forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplugin-utils.ts
More file actions
35 lines (32 loc) · 1.04 KB
/
plugin-utils.ts
File metadata and controls
35 lines (32 loc) · 1.04 KB
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
29
30
31
32
33
34
35
import { isPlainObject } from 'lodash';
import {
IPublicTypePluginRegisterOptions,
IPublicTypePluginDeclaration,
} from '@felce/lowcode-types';
export function isValidPreferenceKey(
key: string,
preferenceDeclaration: IPublicTypePluginDeclaration,
): boolean {
if (!preferenceDeclaration || !Array.isArray(preferenceDeclaration.properties)) {
return false;
}
return preferenceDeclaration.properties.some((prop) => {
return prop.key === key;
});
}
export function isLowCodeRegisterOptions(opts: any): opts is IPublicTypePluginRegisterOptions {
return opts && ('autoInit' in opts || 'override' in opts);
}
export function filterValidOptions(opts: any, preferenceDeclaration: IPublicTypePluginDeclaration) {
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;
}