@visactor/vutils-extension 1.12.0-alpha.8 → 1.12.0
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/cjs/spec/clone-deep.js +3 -15
- package/cjs/spec/clone-deep.js.map +1 -1
- package/cjs/spec/merge-spec.js +2 -41
- package/cjs/spec/merge-spec.js.map +1 -1
- package/es/spec/clone-deep.js +4 -14
- package/es/spec/clone-deep.js.map +1 -1
- package/es/spec/merge-spec.js +3 -39
- package/es/spec/merge-spec.js.map +1 -1
- package/package.json +5 -5
package/cjs/spec/clone-deep.js
CHANGED
|
@@ -4,23 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.cloneDeepSpec = void 0;
|
|
6
6
|
|
|
7
|
-
const vutils_1 = require("@visactor/vutils"), vdataset_1 = require("@visactor/vdataset")
|
|
7
|
+
const vutils_1 = require("@visactor/vutils"), vdataset_1 = require("@visactor/vdataset"), ignoreWhen = value => (0,
|
|
8
|
+
vdataset_1.isDataView)(value) || (0, vutils_1.isHTMLElement)(value);
|
|
8
9
|
|
|
9
10
|
function cloneDeepSpec(spec, excludeKeys = [ "data" ]) {
|
|
10
|
-
|
|
11
|
-
let result;
|
|
12
|
-
if (!(0, vutils_1.isValid)(value) || "object" != typeof value) return value;
|
|
13
|
-
if ((0, vdataset_1.isDataView)(value) || (0, vutils_1.isHTMLElement)(value)) return value;
|
|
14
|
-
const isArr = (0, vutils_1.isArray)(value), length = value.length;
|
|
15
|
-
result = isArr ? new Array(length) : "object" == typeof value ? {} : (0, vutils_1.isBoolean)(value) || (0,
|
|
16
|
-
vutils_1.isNumber)(value) || (0, vutils_1.isString)(value) ? value : (0, vutils_1.isDate)(value) ? new Date(+value) : void 0;
|
|
17
|
-
const props = isArr ? void 0 : Object.keys(Object(value));
|
|
18
|
-
let index = -1;
|
|
19
|
-
if (result) for (;++index < (props || value).length; ) {
|
|
20
|
-
const key = props ? props[index] : index, subValue = value[key];
|
|
21
|
-
(null == excludeKeys ? void 0 : excludeKeys.includes(key.toString())) ? result[key] = subValue : result[key] = cloneDeepSpec(subValue, excludeKeys);
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
11
|
+
return (0, vutils_1.cloneDeep)(spec, ignoreWhen, excludeKeys);
|
|
24
12
|
}
|
|
25
13
|
|
|
26
14
|
exports.cloneDeepSpec = cloneDeepSpec;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/spec/clone-deep.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/spec/clone-deep.ts"],"names":[],"mappings":";;;AAAA,6CAA4D;AAC5D,iDAAgD;AAEhD,MAAM,UAAU,GAAG,CAAC,KAAU,EAAE,EAAE;IAChC,OAAO,IAAA,qBAAU,EAAC,KAAK,CAAC,IAAI,IAAA,sBAAa,EAAC,KAAK,CAAC,CAAC;AACnD,CAAC,CAAC;AAMF,SAAgB,aAAa,CAAC,IAAS,EAAE,cAAwB,CAAC,MAAM,CAAC;IACvE,OAAO,IAAA,kBAAS,EAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;AAClD,CAAC;AAFD,sCAEC","file":"clone-deep.js","sourcesContent":["import { isHTMLElement, cloneDeep } from '@visactor/vutils';\nimport { isDataView } from '@visactor/vdataset';\n\nconst ignoreWhen = (value: any) => {\n return isDataView(value) || isHTMLElement(value);\n};\n\n/**\n * 深拷贝 spec,为避免循环引用,DataView 维持原有引用\n * @param spec 原spec\n */\nexport function cloneDeepSpec(spec: any, excludeKeys: string[] = ['data']) {\n return cloneDeep(spec, ignoreWhen, excludeKeys);\n}\n"]}
|
package/cjs/spec/merge-spec.js
CHANGED
|
@@ -6,51 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
|
|
7
7
|
const vutils_1 = require("@visactor/vutils");
|
|
8
8
|
|
|
9
|
-
function baseMerge(target, source, shallowArray = !1) {
|
|
10
|
-
if (source) {
|
|
11
|
-
if (target === source) return;
|
|
12
|
-
if ((0, vutils_1.isValid)(source) && "object" == typeof source) {
|
|
13
|
-
const iterable = Object(source), props = [];
|
|
14
|
-
for (const key in iterable) props.push(key);
|
|
15
|
-
let {length: length} = props, propIndex = -1;
|
|
16
|
-
for (;length--; ) {
|
|
17
|
-
const key = props[++propIndex];
|
|
18
|
-
(0, vutils_1.isValid)(iterable[key]) && "object" == typeof iterable[key] && !(0,
|
|
19
|
-
vutils_1.isArray)(target[key]) ? baseMergeDeep(target, source, key, shallowArray) : assignMergeValue(target, key, iterable[key]);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function baseMergeDeep(target, source, key, shallowArray = !1) {
|
|
26
|
-
const objValue = target[key], srcValue = source[key];
|
|
27
|
-
let newValue = source[key], isCommon = !0;
|
|
28
|
-
if ((0, vutils_1.isArray)(srcValue)) {
|
|
29
|
-
if (shallowArray) newValue = []; else if ((0, vutils_1.isArray)(objValue)) newValue = objValue; else if ((0,
|
|
30
|
-
vutils_1.isArrayLike)(objValue)) {
|
|
31
|
-
newValue = new Array(objValue.length);
|
|
32
|
-
let index = -1;
|
|
33
|
-
const length = objValue.length;
|
|
34
|
-
for (;++index < length; ) newValue[index] = objValue[index];
|
|
35
|
-
}
|
|
36
|
-
} else (0, vutils_1.isPlainObject)(srcValue) ? (newValue = null != objValue ? objValue : {},
|
|
37
|
-
"function" != typeof objValue && "object" == typeof objValue || (newValue = {})) : isCommon = !1;
|
|
38
|
-
isCommon && baseMerge(newValue, srcValue, shallowArray), assignMergeValue(target, key, newValue);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function assignMergeValue(target, key, value) {
|
|
42
|
-
(void 0 !== value && !eq(target[key], value) || void 0 === value && !(key in target)) && (target[key] = value);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function eq(value, other) {
|
|
46
|
-
return value === other || Number.isNaN(value) && Number.isNaN(other);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
9
|
function mergeSpec(target, ...sources) {
|
|
50
10
|
let sourceIndex = -1;
|
|
51
11
|
const length = sources.length;
|
|
52
12
|
for (;++sourceIndex < length; ) {
|
|
53
|
-
|
|
13
|
+
const source = sources[sourceIndex];
|
|
14
|
+
(0, vutils_1.baseMerge)(target, source, !0, !0);
|
|
54
15
|
}
|
|
55
16
|
return target;
|
|
56
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/spec/merge-spec.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/spec/merge-spec.ts"],"names":[],"mappings":";;;AAAA,6CAAgE;AAIhE,SAAgB,SAAS,CAAC,MAAW,EAAE,GAAG,OAAc;IACtD,IAAI,WAAW,GAAG,CAAC,CAAC,CAAC;IACrB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,OAAO,EAAE,WAAW,GAAG,MAAM,EAAE;QAC7B,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;QACpC,IAAA,kBAAS,EAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;KACvC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AARD,8BAQC;AAED,SAAgB,mBAAmB,CACjC,MAAW,EACX,MAAgD,EAChD,IAAS,EACT,UAAmB;IAEnB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QAC9B,IAAI,IAAA,iBAAQ,EAAC,MAAM,CAAC,EAAE;YACpB,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,EAAE;gBACrB,IAAI,IAAA,gBAAO,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;oBACtB,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,EAAE;wBACpC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;qBAC5F;iBACF;qBAAM;oBACL,MAAM,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;iBAChE;aACF;SACF;aAAM;YAEL,IAAI,IAAA,gBAAO,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;gBACtB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAA2B,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC;gBACrF,IAAI,KAAK,IAAI,CAAC,EAAE;oBACd,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;iBAC9E;aACF;iBAAM,IAAI,MAAM,CAAC,EAAE,KAAK,MAAM,EAAE;gBAC/B,MAAM,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;aAChE;SACF;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AA7BD,kDA6BC","file":"merge-spec.js","sourcesContent":["import { baseMerge, isArray, isObject } from '@visactor/vutils';\n/* 与原生的 lodash merge 差异在于对数组是否应用最后一个 source 的结果\n * 以及对一些特殊情况的处理,比如对数组类型 padding 和对象类型的 padding 的 merge\n */\nexport function mergeSpec(target: any, ...sources: any[]): any {\n let sourceIndex = -1;\n const length = sources.length;\n while (++sourceIndex < length) {\n const source = sources[sourceIndex];\n baseMerge(target, source, true, true);\n }\n return target;\n}\n\nexport function mergeSpecWithFilter(\n target: any,\n filter: string | { type: string; index: number },\n spec: any,\n forceMerge: boolean\n) {\n Object.keys(target).forEach(k => {\n if (isObject(filter)) {\n if (filter.type === k) {\n if (isArray(target[k])) {\n if (target[k].length >= filter.index) {\n target[k][filter.index] = forceMerge ? mergeSpec({}, target[k][filter.index], spec) : spec;\n }\n } else {\n target[k] = forceMerge ? mergeSpec({}, target[k], spec) : spec;\n }\n }\n } else {\n // filter === user id\n if (isArray(target[k])) {\n const index = target[k].findIndex((_s: { id: string | number }) => _s.id === filter);\n if (index >= 0) {\n target[k][index] = forceMerge ? mergeSpec({}, target[k][index], spec) : spec;\n }\n } else if (target.id === filter) {\n target[k] = forceMerge ? mergeSpec({}, target[k], spec) : spec;\n }\n }\n });\n}\n"]}
|
package/es/spec/clone-deep.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isHTMLElement, cloneDeep } from "@visactor/vutils";
|
|
2
2
|
|
|
3
3
|
import { isDataView } from "@visactor/vdataset";
|
|
4
4
|
|
|
5
|
+
const ignoreWhen = value => isDataView(value) || isHTMLElement(value);
|
|
6
|
+
|
|
5
7
|
export function cloneDeepSpec(spec, excludeKeys = [ "data" ]) {
|
|
6
|
-
|
|
7
|
-
let result;
|
|
8
|
-
if (!isValid(value) || "object" != typeof value) return value;
|
|
9
|
-
if (isDataView(value) || isHTMLElement(value)) return value;
|
|
10
|
-
const isArr = isArray(value), length = value.length;
|
|
11
|
-
result = isArr ? new Array(length) : "object" == typeof value ? {} : isBoolean(value) || isNumber(value) || isString(value) ? value : isDate(value) ? new Date(+value) : void 0;
|
|
12
|
-
const props = isArr ? void 0 : Object.keys(Object(value));
|
|
13
|
-
let index = -1;
|
|
14
|
-
if (result) for (;++index < (props || value).length; ) {
|
|
15
|
-
const key = props ? props[index] : index, subValue = value[key];
|
|
16
|
-
(null == excludeKeys ? void 0 : excludeKeys.includes(key.toString())) ? result[key] = subValue : result[key] = cloneDeepSpec(subValue, excludeKeys);
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
8
|
+
return cloneDeep(spec, ignoreWhen, excludeKeys);
|
|
19
9
|
}
|
|
20
10
|
//# sourceMappingURL=clone-deep.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/spec/clone-deep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"sources":["../src/spec/clone-deep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,MAAM,UAAU,GAAG,CAAC,KAAU,EAAE,EAAE;IAChC,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC,CAAC;AAMF,MAAM,UAAU,aAAa,CAAC,IAAS,EAAE,cAAwB,CAAC,MAAM,CAAC;IACvE,OAAO,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;AAClD,CAAC","file":"clone-deep.js","sourcesContent":["import { isHTMLElement, cloneDeep } from '@visactor/vutils';\nimport { isDataView } from '@visactor/vdataset';\n\nconst ignoreWhen = (value: any) => {\n return isDataView(value) || isHTMLElement(value);\n};\n\n/**\n * 深拷贝 spec,为避免循环引用,DataView 维持原有引用\n * @param spec 原spec\n */\nexport function cloneDeepSpec(spec: any, excludeKeys: string[] = ['data']) {\n return cloneDeep(spec, ignoreWhen, excludeKeys);\n}\n"]}
|
package/es/spec/merge-spec.js
CHANGED
|
@@ -1,47 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
function baseMerge(target, source, shallowArray = !1) {
|
|
4
|
-
if (source) {
|
|
5
|
-
if (target === source) return;
|
|
6
|
-
if (isValid(source) && "object" == typeof source) {
|
|
7
|
-
const iterable = Object(source), props = [];
|
|
8
|
-
for (const key in iterable) props.push(key);
|
|
9
|
-
let {length: length} = props, propIndex = -1;
|
|
10
|
-
for (;length--; ) {
|
|
11
|
-
const key = props[++propIndex];
|
|
12
|
-
isValid(iterable[key]) && "object" == typeof iterable[key] && !isArray(target[key]) ? baseMergeDeep(target, source, key, shallowArray) : assignMergeValue(target, key, iterable[key]);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function baseMergeDeep(target, source, key, shallowArray = !1) {
|
|
19
|
-
const objValue = target[key], srcValue = source[key];
|
|
20
|
-
let newValue = source[key], isCommon = !0;
|
|
21
|
-
if (isArray(srcValue)) {
|
|
22
|
-
if (shallowArray) newValue = []; else if (isArray(objValue)) newValue = objValue; else if (isArrayLike(objValue)) {
|
|
23
|
-
newValue = new Array(objValue.length);
|
|
24
|
-
let index = -1;
|
|
25
|
-
const length = objValue.length;
|
|
26
|
-
for (;++index < length; ) newValue[index] = objValue[index];
|
|
27
|
-
}
|
|
28
|
-
} else isPlainObject(srcValue) ? (newValue = null != objValue ? objValue : {}, "function" != typeof objValue && "object" == typeof objValue || (newValue = {})) : isCommon = !1;
|
|
29
|
-
isCommon && baseMerge(newValue, srcValue, shallowArray), assignMergeValue(target, key, newValue);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function assignMergeValue(target, key, value) {
|
|
33
|
-
(void 0 !== value && !eq(target[key], value) || void 0 === value && !(key in target)) && (target[key] = value);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function eq(value, other) {
|
|
37
|
-
return value === other || Number.isNaN(value) && Number.isNaN(other);
|
|
38
|
-
}
|
|
1
|
+
import { baseMerge, isArray, isObject } from "@visactor/vutils";
|
|
39
2
|
|
|
40
3
|
export function mergeSpec(target, ...sources) {
|
|
41
4
|
let sourceIndex = -1;
|
|
42
5
|
const length = sources.length;
|
|
43
6
|
for (;++sourceIndex < length; ) {
|
|
44
|
-
|
|
7
|
+
const source = sources[sourceIndex];
|
|
8
|
+
baseMerge(target, source, !0, !0);
|
|
45
9
|
}
|
|
46
10
|
return target;
|
|
47
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/spec/merge-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"sources":["../src/spec/merge-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAIhE,MAAM,UAAU,SAAS,CAAC,MAAW,EAAE,GAAG,OAAc;IACtD,IAAI,WAAW,GAAG,CAAC,CAAC,CAAC;IACrB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,OAAO,EAAE,WAAW,GAAG,MAAM,EAAE;QAC7B,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;QACpC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;KACvC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,MAAW,EACX,MAAgD,EAChD,IAAS,EACT,UAAmB;IAEnB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QAC9B,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE;YACpB,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,EAAE;gBACrB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;oBACtB,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,EAAE;wBACpC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;qBAC5F;iBACF;qBAAM;oBACL,MAAM,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;iBAChE;aACF;SACF;aAAM;YAEL,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;gBACtB,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAA2B,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC;gBACrF,IAAI,KAAK,IAAI,CAAC,EAAE;oBACd,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;iBAC9E;aACF;iBAAM,IAAI,MAAM,CAAC,EAAE,KAAK,MAAM,EAAE;gBAC/B,MAAM,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;aAChE;SACF;IACH,CAAC,CAAC,CAAC;AACL,CAAC","file":"merge-spec.js","sourcesContent":["import { baseMerge, isArray, isObject } from '@visactor/vutils';\n/* 与原生的 lodash merge 差异在于对数组是否应用最后一个 source 的结果\n * 以及对一些特殊情况的处理,比如对数组类型 padding 和对象类型的 padding 的 merge\n */\nexport function mergeSpec(target: any, ...sources: any[]): any {\n let sourceIndex = -1;\n const length = sources.length;\n while (++sourceIndex < length) {\n const source = sources[sourceIndex];\n baseMerge(target, source, true, true);\n }\n return target;\n}\n\nexport function mergeSpecWithFilter(\n target: any,\n filter: string | { type: string; index: number },\n spec: any,\n forceMerge: boolean\n) {\n Object.keys(target).forEach(k => {\n if (isObject(filter)) {\n if (filter.type === k) {\n if (isArray(target[k])) {\n if (target[k].length >= filter.index) {\n target[k][filter.index] = forceMerge ? mergeSpec({}, target[k][filter.index], spec) : spec;\n }\n } else {\n target[k] = forceMerge ? mergeSpec({}, target[k], spec) : spec;\n }\n }\n } else {\n // filter === user id\n if (isArray(target[k])) {\n const index = target[k].findIndex((_s: { id: string | number }) => _s.id === filter);\n if (index >= 0) {\n target[k][index] = forceMerge ? mergeSpec({}, target[k][index], spec) : spec;\n }\n } else if (target.id === filter) {\n target[k] = forceMerge ? mergeSpec({}, target[k], spec) : spec;\n }\n }\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visactor/vutils-extension",
|
|
3
|
-
"version": "1.12.0
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "The extension module for VUtil from VisActor",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "cjs/index.js",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@visactor/vutils": "~0.18.
|
|
16
|
-
"@visactor/vdataset": "~0.18.
|
|
15
|
+
"@visactor/vutils": "~0.18.14",
|
|
16
|
+
"@visactor/vdataset": "~0.18.14"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@rushstack/eslint-patch": "~1.1.4",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"ts-node": "10.9.0",
|
|
36
36
|
"tslib": "2.3.1",
|
|
37
37
|
"tslint": "5.12.1",
|
|
38
|
-
"@internal/
|
|
38
|
+
"@internal/bundler": "0.0.1",
|
|
39
39
|
"@internal/eslint-config": "0.0.1",
|
|
40
|
-
"@internal/
|
|
40
|
+
"@internal/ts-config": "0.0.1"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|