forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin-utils.ts
More file actions
28 lines (26 loc) · 881 Bytes
/
plugin-utils.ts
File metadata and controls
28 lines (26 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import type { ILowCodePluginPreferenceDeclaration } from './plugin-types';
import { isPlainObject } from 'lodash';
export function isValidPreferenceKey(
key: string,
preferenceDeclaration: ILowCodePluginPreferenceDeclaration,
): boolean {
if (!preferenceDeclaration || !Array.isArray(preferenceDeclaration.properties)) {
return false;
}
return preferenceDeclaration.properties.some((prop) => {
return prop.key === key;
});
}
export function filterValidOptions(opts: any, preferenceDeclaration: ILowCodePluginPreferenceDeclaration) {
if (!opts || !isPlainObject(opts)) return opts;
const filteredOpts = {} as any;
Object.keys(opts).forEach(key => {
if (isValidPreferenceKey(key, preferenceDeclaration)) {
const v = opts[key];
if (v !== undefined && v !== null) {
filteredOpts[key] = v;
}
}
});
return filteredOpts;
}