cascade-extend 2.1.10 → 2.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +37 -42
- package/package.json +3 -4
package/dist/index.js
CHANGED
|
@@ -1,46 +1,41 @@
|
|
|
1
1
|
import { extend } from '@cabloy/extend';
|
|
2
|
+
|
|
2
3
|
const __SepDefault = '.';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const parts = key.substring(prefix.length + 1).split(sep);
|
|
25
|
-
return parts.every(part => !!scope[part]);
|
|
26
|
-
});
|
|
27
|
-
// ok
|
|
28
|
-
return keys.length === 0 ? undefined : keys;
|
|
4
|
+
function cascadeExtendKeys(scope, source, prefix, sep = __SepDefault) {
|
|
5
|
+
if (!source) return undefined;
|
|
6
|
+
if (prefix === undefined) prefix = '';
|
|
7
|
+
// filter
|
|
8
|
+
let keys = Object.keys(source).filter(key => {
|
|
9
|
+
return key === prefix || key.indexOf(prefix + sep) === 0;
|
|
10
|
+
});
|
|
11
|
+
if (keys.length === 0) return undefined;
|
|
12
|
+
if (keys.length === 1 && keys[0] === prefix) return keys;
|
|
13
|
+
// sort
|
|
14
|
+
keys.sort((a, b) => {
|
|
15
|
+
return a.split(sep).length - b.split(sep).length;
|
|
16
|
+
});
|
|
17
|
+
// filter
|
|
18
|
+
keys = keys.filter(key => {
|
|
19
|
+
if (key === prefix) return true;
|
|
20
|
+
const parts = key.substring(prefix.length + 1).split(sep);
|
|
21
|
+
return parts.every(part => !!scope[part]);
|
|
22
|
+
});
|
|
23
|
+
// ok
|
|
24
|
+
return keys.length === 0 ? undefined : keys;
|
|
29
25
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
extend(true, result, source[key]);
|
|
44
|
-
}
|
|
45
|
-
return result;
|
|
26
|
+
function cascadeExtend(scope, source, prefix, sep = __SepDefault) {
|
|
27
|
+
if (!source) return undefined;
|
|
28
|
+
// keys
|
|
29
|
+
const keys = cascadeExtendKeys(scope, source, prefix, sep);
|
|
30
|
+
if (!keys) return undefined;
|
|
31
|
+
// special
|
|
32
|
+
if (keys.length === 1) return source[keys[0]];
|
|
33
|
+
// extend
|
|
34
|
+
const result = {};
|
|
35
|
+
for (const key of keys) {
|
|
36
|
+
extend(true, result, source[key]);
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
46
39
|
}
|
|
40
|
+
|
|
41
|
+
export { cascadeExtend, cascadeExtendKeys };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cascade-extend",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.11",
|
|
5
5
|
"description": "cascade-extend",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -34,12 +34,11 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@cabloy/extend": "^3.1.
|
|
37
|
+
"@cabloy/extend": "^3.1.11"
|
|
38
38
|
},
|
|
39
39
|
"gitHead": "0eab9dc4a5622caffe89e7b1b3f02c08ccbc4c4b",
|
|
40
40
|
"scripts": {
|
|
41
|
-
"lint": "eslint .",
|
|
42
41
|
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
|
|
43
|
-
"tsc:publish": "npm run clean && tsc -p tsconfig.build.json"
|
|
42
|
+
"tsc:publish": "npm run clean && vona :bin:buildGeneral && tsc -p tsconfig.build.json"
|
|
44
43
|
}
|
|
45
44
|
}
|