sculp-js 1.7.0 → 1.7.1
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/README.md +2 -1
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/object.js +65 -18
- package/lib/cjs/tree.js +6 -4
- package/lib/es/index.js +1 -1
- package/lib/es/object.js +65 -18
- package/lib/es/tree.js +6 -4
- package/lib/index.d.ts +5 -5
- package/lib/umd/index.js +67 -20
- package/package.json +1 -1
- package/lib/tsdoc-metadata.json +0 -11
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
- Tree
|
|
51
51
|
|
|
52
52
|
- forEachDeep 高性能的深度优先遍历函数, 支持continue、break,可定制id、children
|
|
53
|
-
-
|
|
53
|
+
- mapDeep 高性能的深度优先遍历的Map函数, 支持continue、break,可定制id、children
|
|
54
54
|
- searchTreeById 在树中找到 id 为某个值的节点,并返回上游的所有父级节点
|
|
55
55
|
- formatTree 高性能的数组转树函数
|
|
56
56
|
- flatTree 树转数组
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
- objectEach
|
|
65
65
|
- objectEachAsync
|
|
66
66
|
- objectGet
|
|
67
|
+
- cloneDeep
|
|
67
68
|
|
|
68
69
|
- Number
|
|
69
70
|
|
package/lib/cjs/index.js
CHANGED
|
@@ -141,9 +141,9 @@ exports.tooltipEvent = tooltip.tooltipEvent;
|
|
|
141
141
|
exports.buildTree = tree.buildTree;
|
|
142
142
|
exports.flatTree = tree.flatTree;
|
|
143
143
|
exports.forEachDeep = tree.forEachDeep;
|
|
144
|
-
exports.forEachMap = tree.forEachMap;
|
|
145
144
|
exports.formatTree = tree.formatTree;
|
|
146
145
|
exports.fuzzySearchTree = tree.fuzzySearchTree;
|
|
146
|
+
exports.mapDeep = tree.mapDeep;
|
|
147
147
|
exports.searchTreeById = tree.searchTreeById;
|
|
148
148
|
exports.add = math.add;
|
|
149
149
|
exports.divide = math.divide;
|
package/lib/cjs/object.js
CHANGED
|
@@ -198,26 +198,73 @@ function objectGet(obj, path, strict = false) {
|
|
|
198
198
|
}
|
|
199
199
|
/**
|
|
200
200
|
* 深拷贝堪称完全体 即:任何类型的数据都会被深拷贝
|
|
201
|
-
* @param {
|
|
201
|
+
* @param {T} source
|
|
202
202
|
* @param {WeakMap} map
|
|
203
|
-
* @returns {
|
|
203
|
+
* @returns {T}
|
|
204
204
|
*/
|
|
205
|
-
function cloneDeep(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
205
|
+
function cloneDeep(source, map = new WeakMap()) {
|
|
206
|
+
// 处理原始类型(非对象/数组)和 null/undefined
|
|
207
|
+
if (source === null || typeof source !== 'object') {
|
|
208
|
+
return source;
|
|
209
|
+
}
|
|
210
|
+
// 处理循环引用
|
|
211
|
+
if (map.has(source)) {
|
|
212
|
+
return map.get(source);
|
|
213
|
+
}
|
|
214
|
+
// 处理 Date 类型
|
|
215
|
+
if (source instanceof Date) {
|
|
216
|
+
const copy = new Date(source.getTime());
|
|
217
|
+
map.set(source, copy);
|
|
218
|
+
return copy;
|
|
219
|
+
}
|
|
220
|
+
// 处理 RegExp 类型
|
|
221
|
+
if (source instanceof RegExp) {
|
|
222
|
+
const copy = new RegExp(source.source, source.flags);
|
|
223
|
+
map.set(source, copy);
|
|
224
|
+
return copy;
|
|
225
|
+
}
|
|
226
|
+
// 处理数组类型
|
|
227
|
+
if (Array.isArray(source)) {
|
|
228
|
+
const copy = [];
|
|
229
|
+
map.set(source, copy);
|
|
230
|
+
for (const item of source) {
|
|
231
|
+
copy.push(cloneDeep(item, map));
|
|
232
|
+
}
|
|
233
|
+
return copy;
|
|
234
|
+
}
|
|
235
|
+
// 处理 Map 类型
|
|
236
|
+
if (source instanceof Map) {
|
|
237
|
+
const copy = new Map();
|
|
238
|
+
map.set(source, copy);
|
|
239
|
+
source.forEach((value, key) => {
|
|
240
|
+
copy.set(cloneDeep(key, map), cloneDeep(value, map));
|
|
241
|
+
});
|
|
242
|
+
return copy;
|
|
243
|
+
}
|
|
244
|
+
// 处理 Set 类型
|
|
245
|
+
if (source instanceof Set) {
|
|
246
|
+
const copy = new Set();
|
|
247
|
+
map.set(source, copy);
|
|
248
|
+
source.forEach(value => {
|
|
249
|
+
copy.add(cloneDeep(value, map));
|
|
250
|
+
});
|
|
251
|
+
return copy;
|
|
252
|
+
}
|
|
253
|
+
// 处理 ArrayBuffer 类型
|
|
254
|
+
if (source instanceof ArrayBuffer) {
|
|
255
|
+
const copy = new ArrayBuffer(source.byteLength);
|
|
256
|
+
new Uint8Array(copy).set(new Uint8Array(source));
|
|
257
|
+
map.set(source, copy);
|
|
258
|
+
return copy;
|
|
259
|
+
}
|
|
260
|
+
// 处理普通对象(包括原型链继承)
|
|
261
|
+
const copy = Object.create(Object.getPrototypeOf(source));
|
|
262
|
+
map.set(source, copy);
|
|
263
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
264
|
+
const value = source[key];
|
|
265
|
+
copy[key] = cloneDeep(value, map);
|
|
266
|
+
}
|
|
267
|
+
return copy;
|
|
221
268
|
}
|
|
222
269
|
|
|
223
270
|
exports.cloneDeep = cloneDeep;
|
package/lib/cjs/tree.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
var object = require('./object.js');
|
|
10
|
+
|
|
9
11
|
const defaultFieldOptions = { keyField: 'key', childField: 'children', pidField: 'pid' };
|
|
10
12
|
const defaultSearchTreeOptions = {
|
|
11
13
|
childField: 'children',
|
|
@@ -74,7 +76,7 @@ function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
|
|
|
74
76
|
* @param {boolean} isReverse 是否反向遍历
|
|
75
77
|
* @returns {any[]} 新的一棵树
|
|
76
78
|
*/
|
|
77
|
-
function
|
|
79
|
+
function mapDeep(tree, iterator, children = 'children', isReverse = false) {
|
|
78
80
|
let isBreak = false;
|
|
79
81
|
const newTree = [];
|
|
80
82
|
const walk = (arr, parent, newTree, level = 0) => {
|
|
@@ -91,7 +93,7 @@ function forEachMap(tree, iterator, children = 'children', isReverse = false) {
|
|
|
91
93
|
else if (re === true) {
|
|
92
94
|
continue;
|
|
93
95
|
}
|
|
94
|
-
newTree.push(re);
|
|
96
|
+
newTree.push(object.objectOmit(re, [children]));
|
|
95
97
|
// @ts-ignore
|
|
96
98
|
if (arr[i] && Array.isArray(arr[i][children])) {
|
|
97
99
|
newTree[newTree.length - 1][children] = [];
|
|
@@ -117,7 +119,7 @@ function forEachMap(tree, iterator, children = 'children', isReverse = false) {
|
|
|
117
119
|
else if (re === true) {
|
|
118
120
|
continue;
|
|
119
121
|
}
|
|
120
|
-
newTree.push(re);
|
|
122
|
+
newTree.push(object.objectOmit(re, [children]));
|
|
121
123
|
// @ts-ignore
|
|
122
124
|
if (arr[i] && Array.isArray(arr[i][children])) {
|
|
123
125
|
newTree[newTree.length - 1][children] = [];
|
|
@@ -352,7 +354,7 @@ function fuzzySearchTree(nodes, query, options = defaultSearchTreeOptions) {
|
|
|
352
354
|
exports.buildTree = buildTree;
|
|
353
355
|
exports.flatTree = flatTree;
|
|
354
356
|
exports.forEachDeep = forEachDeep;
|
|
355
|
-
exports.forEachMap = forEachMap;
|
|
356
357
|
exports.formatTree = formatTree;
|
|
357
358
|
exports.fuzzySearchTree = fuzzySearchTree;
|
|
359
|
+
exports.mapDeep = mapDeep;
|
|
358
360
|
exports.searchTreeById = searchTreeById;
|
package/lib/es/index.js
CHANGED
|
@@ -24,7 +24,7 @@ export { STRING_POOL, randomNumber, randomString, randomUuid } from './random.js
|
|
|
24
24
|
export { HEX_POOL, formatNumber, numberAbbr, numberToHex } from './number.js';
|
|
25
25
|
export { UNIQUE_NUMBER_SAFE_LENGTH, uniqueNumber, uniqueString } from './unique.js';
|
|
26
26
|
export { tooltipEvent } from './tooltip.js';
|
|
27
|
-
export { buildTree, flatTree, forEachDeep,
|
|
27
|
+
export { buildTree, flatTree, forEachDeep, formatTree, fuzzySearchTree, mapDeep, searchTreeById } from './tree.js';
|
|
28
28
|
export { add, divide, multiply, strip, subtract } from './math.js';
|
|
29
29
|
export { weAtob, weBtoa } from './we-decode.js';
|
|
30
30
|
export { decodeFromBase64, encodeToBase64 } from './base64.js';
|
package/lib/es/object.js
CHANGED
|
@@ -196,26 +196,73 @@ function objectGet(obj, path, strict = false) {
|
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
198
198
|
* 深拷贝堪称完全体 即:任何类型的数据都会被深拷贝
|
|
199
|
-
* @param {
|
|
199
|
+
* @param {T} source
|
|
200
200
|
* @param {WeakMap} map
|
|
201
|
-
* @returns {
|
|
201
|
+
* @returns {T}
|
|
202
202
|
*/
|
|
203
|
-
function cloneDeep(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
203
|
+
function cloneDeep(source, map = new WeakMap()) {
|
|
204
|
+
// 处理原始类型(非对象/数组)和 null/undefined
|
|
205
|
+
if (source === null || typeof source !== 'object') {
|
|
206
|
+
return source;
|
|
207
|
+
}
|
|
208
|
+
// 处理循环引用
|
|
209
|
+
if (map.has(source)) {
|
|
210
|
+
return map.get(source);
|
|
211
|
+
}
|
|
212
|
+
// 处理 Date 类型
|
|
213
|
+
if (source instanceof Date) {
|
|
214
|
+
const copy = new Date(source.getTime());
|
|
215
|
+
map.set(source, copy);
|
|
216
|
+
return copy;
|
|
217
|
+
}
|
|
218
|
+
// 处理 RegExp 类型
|
|
219
|
+
if (source instanceof RegExp) {
|
|
220
|
+
const copy = new RegExp(source.source, source.flags);
|
|
221
|
+
map.set(source, copy);
|
|
222
|
+
return copy;
|
|
223
|
+
}
|
|
224
|
+
// 处理数组类型
|
|
225
|
+
if (Array.isArray(source)) {
|
|
226
|
+
const copy = [];
|
|
227
|
+
map.set(source, copy);
|
|
228
|
+
for (const item of source) {
|
|
229
|
+
copy.push(cloneDeep(item, map));
|
|
230
|
+
}
|
|
231
|
+
return copy;
|
|
232
|
+
}
|
|
233
|
+
// 处理 Map 类型
|
|
234
|
+
if (source instanceof Map) {
|
|
235
|
+
const copy = new Map();
|
|
236
|
+
map.set(source, copy);
|
|
237
|
+
source.forEach((value, key) => {
|
|
238
|
+
copy.set(cloneDeep(key, map), cloneDeep(value, map));
|
|
239
|
+
});
|
|
240
|
+
return copy;
|
|
241
|
+
}
|
|
242
|
+
// 处理 Set 类型
|
|
243
|
+
if (source instanceof Set) {
|
|
244
|
+
const copy = new Set();
|
|
245
|
+
map.set(source, copy);
|
|
246
|
+
source.forEach(value => {
|
|
247
|
+
copy.add(cloneDeep(value, map));
|
|
248
|
+
});
|
|
249
|
+
return copy;
|
|
250
|
+
}
|
|
251
|
+
// 处理 ArrayBuffer 类型
|
|
252
|
+
if (source instanceof ArrayBuffer) {
|
|
253
|
+
const copy = new ArrayBuffer(source.byteLength);
|
|
254
|
+
new Uint8Array(copy).set(new Uint8Array(source));
|
|
255
|
+
map.set(source, copy);
|
|
256
|
+
return copy;
|
|
257
|
+
}
|
|
258
|
+
// 处理普通对象(包括原型链继承)
|
|
259
|
+
const copy = Object.create(Object.getPrototypeOf(source));
|
|
260
|
+
map.set(source, copy);
|
|
261
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
262
|
+
const value = source[key];
|
|
263
|
+
copy[key] = cloneDeep(value, map);
|
|
264
|
+
}
|
|
265
|
+
return copy;
|
|
219
266
|
}
|
|
220
267
|
|
|
221
268
|
export { cloneDeep, isPlainObject, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectMap, objectAssign as objectMerge, objectOmit, objectPick };
|
package/lib/es/tree.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { objectOmit } from './object.js';
|
|
8
|
+
|
|
7
9
|
const defaultFieldOptions = { keyField: 'key', childField: 'children', pidField: 'pid' };
|
|
8
10
|
const defaultSearchTreeOptions = {
|
|
9
11
|
childField: 'children',
|
|
@@ -72,7 +74,7 @@ function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
|
|
|
72
74
|
* @param {boolean} isReverse 是否反向遍历
|
|
73
75
|
* @returns {any[]} 新的一棵树
|
|
74
76
|
*/
|
|
75
|
-
function
|
|
77
|
+
function mapDeep(tree, iterator, children = 'children', isReverse = false) {
|
|
76
78
|
let isBreak = false;
|
|
77
79
|
const newTree = [];
|
|
78
80
|
const walk = (arr, parent, newTree, level = 0) => {
|
|
@@ -89,7 +91,7 @@ function forEachMap(tree, iterator, children = 'children', isReverse = false) {
|
|
|
89
91
|
else if (re === true) {
|
|
90
92
|
continue;
|
|
91
93
|
}
|
|
92
|
-
newTree.push(re);
|
|
94
|
+
newTree.push(objectOmit(re, [children]));
|
|
93
95
|
// @ts-ignore
|
|
94
96
|
if (arr[i] && Array.isArray(arr[i][children])) {
|
|
95
97
|
newTree[newTree.length - 1][children] = [];
|
|
@@ -115,7 +117,7 @@ function forEachMap(tree, iterator, children = 'children', isReverse = false) {
|
|
|
115
117
|
else if (re === true) {
|
|
116
118
|
continue;
|
|
117
119
|
}
|
|
118
|
-
newTree.push(re);
|
|
120
|
+
newTree.push(objectOmit(re, [children]));
|
|
119
121
|
// @ts-ignore
|
|
120
122
|
if (arr[i] && Array.isArray(arr[i][children])) {
|
|
121
123
|
newTree[newTree.length - 1][children] = [];
|
|
@@ -347,4 +349,4 @@ function fuzzySearchTree(nodes, query, options = defaultSearchTreeOptions) {
|
|
|
347
349
|
return result;
|
|
348
350
|
}
|
|
349
351
|
|
|
350
|
-
export { buildTree, flatTree, forEachDeep,
|
|
352
|
+
export { buildTree, flatTree, forEachDeep, formatTree, fuzzySearchTree, mapDeep, searchTreeById };
|
package/lib/index.d.ts
CHANGED
|
@@ -410,11 +410,11 @@ declare function objectGet(obj: AnyObject, path: string, strict?: boolean): {
|
|
|
410
410
|
};
|
|
411
411
|
/**
|
|
412
412
|
* 深拷贝堪称完全体 即:任何类型的数据都会被深拷贝
|
|
413
|
-
* @param {
|
|
413
|
+
* @param {T} source
|
|
414
414
|
* @param {WeakMap} map
|
|
415
|
-
* @returns {
|
|
415
|
+
* @returns {T}
|
|
416
416
|
*/
|
|
417
|
-
declare function cloneDeep(
|
|
417
|
+
declare function cloneDeep<T>(source: T, map?: WeakMap<any, any>): T;
|
|
418
418
|
|
|
419
419
|
/**
|
|
420
420
|
* 标准化路径
|
|
@@ -781,7 +781,7 @@ declare function forEachDeep<V>(tree: ArrayLike<V>, iterator: (val: V, i: number
|
|
|
781
781
|
* @param {boolean} isReverse 是否反向遍历
|
|
782
782
|
* @returns {any[]} 新的一棵树
|
|
783
783
|
*/
|
|
784
|
-
declare function
|
|
784
|
+
declare function mapDeep<V>(tree: ArrayLike<V>, iterator: (val: V, i: number, currentArr: ArrayLike<V>, tree: ArrayLike<V>, parent: V | null, level: number) => boolean | any, children?: string, isReverse?: boolean): any[];
|
|
785
785
|
type IdLike = number | string;
|
|
786
786
|
interface ITreeConf {
|
|
787
787
|
id: string | number;
|
|
@@ -1057,4 +1057,4 @@ declare function replaceVarFromString(sourceStr: string, targetObj: Record<strin
|
|
|
1057
1057
|
*/
|
|
1058
1058
|
declare function executeInScope(code: string, scope?: Record<string, any>): any;
|
|
1059
1059
|
|
|
1060
|
-
export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type DateObj, type DateValue, type DebounceFunc, EMAIL_REGEX, type FileType, HEX_POOL, HTTP_URL_REGEX, type ICanvasWM, type ICompressOptions, type IFieldOptions, IPV4_REGEX, IPV6_REGEX, type ISearchTreeOpts, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, PHONE_REGEX, type Params, type PartialDeep, type RandomString, type ReadyCallback, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, URL_REGEX, type UniqueString, type Url, type WithChildren, add, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, buildTree, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, crossOriginDownload, dateParse, dateToEnd, dateToStart, debounce, decodeFromBase64, divide, downloadBlob, downloadData, downloadHref, downloadURL, encodeToBase64, escapeRegExp, executeInScope, flatTree, forEachDeep,
|
|
1060
|
+
export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type DateObj, type DateValue, type DebounceFunc, EMAIL_REGEX, type FileType, HEX_POOL, HTTP_URL_REGEX, type ICanvasWM, type ICompressOptions, type IFieldOptions, IPV4_REGEX, IPV6_REGEX, type ISearchTreeOpts, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, PHONE_REGEX, type Params, type PartialDeep, type RandomString, type ReadyCallback, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, URL_REGEX, type UniqueString, type Url, type WithChildren, add, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, buildTree, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, crossOriginDownload, dateParse, dateToEnd, dateToStart, debounce, decodeFromBase64, divide, downloadBlob, downloadData, downloadHref, downloadURL, encodeToBase64, escapeRegExp, executeInScope, flatTree, forEachDeep, formatDate, formatNumber, formatTree, fuzzySearchTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, isArray, isBigInt, isBoolean, isDate, isDigit, isDomReady, isEmail, isEmpty, isError, isFloat, isFunction, isIdNo, isInteger, isIpV4, isIpV6, isJsonString, isNaN, isNull, isNullOrUnDef, isNumber, isNumerical, isObject, isPhone, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isUrl, isValidDate, mapDeep, multiply, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, onDomReady, once, parseQueryParams, parseVarFromString, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, replaceVarFromString, searchTreeById, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, strip, subtract, supportCanvas, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, uniqueSymbol, urlDelParams, urlParse, urlSetParams, urlStringify, wait, weAtob, weBtoa };
|
package/lib/umd/index.js
CHANGED
|
@@ -424,26 +424,73 @@
|
|
|
424
424
|
}
|
|
425
425
|
/**
|
|
426
426
|
* 深拷贝堪称完全体 即:任何类型的数据都会被深拷贝
|
|
427
|
-
* @param {
|
|
427
|
+
* @param {T} source
|
|
428
428
|
* @param {WeakMap} map
|
|
429
|
-
* @returns {
|
|
429
|
+
* @returns {T}
|
|
430
430
|
*/
|
|
431
|
-
function cloneDeep(
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
431
|
+
function cloneDeep(source, map = new WeakMap()) {
|
|
432
|
+
// 处理原始类型(非对象/数组)和 null/undefined
|
|
433
|
+
if (source === null || typeof source !== 'object') {
|
|
434
|
+
return source;
|
|
435
|
+
}
|
|
436
|
+
// 处理循环引用
|
|
437
|
+
if (map.has(source)) {
|
|
438
|
+
return map.get(source);
|
|
439
|
+
}
|
|
440
|
+
// 处理 Date 类型
|
|
441
|
+
if (source instanceof Date) {
|
|
442
|
+
const copy = new Date(source.getTime());
|
|
443
|
+
map.set(source, copy);
|
|
444
|
+
return copy;
|
|
445
|
+
}
|
|
446
|
+
// 处理 RegExp 类型
|
|
447
|
+
if (source instanceof RegExp) {
|
|
448
|
+
const copy = new RegExp(source.source, source.flags);
|
|
449
|
+
map.set(source, copy);
|
|
450
|
+
return copy;
|
|
451
|
+
}
|
|
452
|
+
// 处理数组类型
|
|
453
|
+
if (Array.isArray(source)) {
|
|
454
|
+
const copy = [];
|
|
455
|
+
map.set(source, copy);
|
|
456
|
+
for (const item of source) {
|
|
457
|
+
copy.push(cloneDeep(item, map));
|
|
458
|
+
}
|
|
459
|
+
return copy;
|
|
460
|
+
}
|
|
461
|
+
// 处理 Map 类型
|
|
462
|
+
if (source instanceof Map) {
|
|
463
|
+
const copy = new Map();
|
|
464
|
+
map.set(source, copy);
|
|
465
|
+
source.forEach((value, key) => {
|
|
466
|
+
copy.set(cloneDeep(key, map), cloneDeep(value, map));
|
|
467
|
+
});
|
|
468
|
+
return copy;
|
|
469
|
+
}
|
|
470
|
+
// 处理 Set 类型
|
|
471
|
+
if (source instanceof Set) {
|
|
472
|
+
const copy = new Set();
|
|
473
|
+
map.set(source, copy);
|
|
474
|
+
source.forEach(value => {
|
|
475
|
+
copy.add(cloneDeep(value, map));
|
|
476
|
+
});
|
|
477
|
+
return copy;
|
|
478
|
+
}
|
|
479
|
+
// 处理 ArrayBuffer 类型
|
|
480
|
+
if (source instanceof ArrayBuffer) {
|
|
481
|
+
const copy = new ArrayBuffer(source.byteLength);
|
|
482
|
+
new Uint8Array(copy).set(new Uint8Array(source));
|
|
483
|
+
map.set(source, copy);
|
|
484
|
+
return copy;
|
|
438
485
|
}
|
|
439
|
-
|
|
440
|
-
const
|
|
441
|
-
map.set(
|
|
442
|
-
for (const key of Reflect.ownKeys(
|
|
443
|
-
const value =
|
|
444
|
-
|
|
486
|
+
// 处理普通对象(包括原型链继承)
|
|
487
|
+
const copy = Object.create(Object.getPrototypeOf(source));
|
|
488
|
+
map.set(source, copy);
|
|
489
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
490
|
+
const value = source[key];
|
|
491
|
+
copy[key] = cloneDeep(value, map);
|
|
445
492
|
}
|
|
446
|
-
return
|
|
493
|
+
return copy;
|
|
447
494
|
}
|
|
448
495
|
|
|
449
496
|
/**
|
|
@@ -2196,7 +2243,7 @@
|
|
|
2196
2243
|
* @param {boolean} isReverse 是否反向遍历
|
|
2197
2244
|
* @returns {any[]} 新的一棵树
|
|
2198
2245
|
*/
|
|
2199
|
-
function
|
|
2246
|
+
function mapDeep(tree, iterator, children = 'children', isReverse = false) {
|
|
2200
2247
|
let isBreak = false;
|
|
2201
2248
|
const newTree = [];
|
|
2202
2249
|
const walk = (arr, parent, newTree, level = 0) => {
|
|
@@ -2213,7 +2260,7 @@
|
|
|
2213
2260
|
else if (re === true) {
|
|
2214
2261
|
continue;
|
|
2215
2262
|
}
|
|
2216
|
-
newTree.push(re);
|
|
2263
|
+
newTree.push(objectOmit(re, [children]));
|
|
2217
2264
|
// @ts-ignore
|
|
2218
2265
|
if (arr[i] && Array.isArray(arr[i][children])) {
|
|
2219
2266
|
newTree[newTree.length - 1][children] = [];
|
|
@@ -2239,7 +2286,7 @@
|
|
|
2239
2286
|
else if (re === true) {
|
|
2240
2287
|
continue;
|
|
2241
2288
|
}
|
|
2242
|
-
newTree.push(re);
|
|
2289
|
+
newTree.push(objectOmit(re, [children]));
|
|
2243
2290
|
// @ts-ignore
|
|
2244
2291
|
if (arr[i] && Array.isArray(arr[i][children])) {
|
|
2245
2292
|
newTree[newTree.length - 1][children] = [];
|
|
@@ -2866,7 +2913,6 @@
|
|
|
2866
2913
|
exports.executeInScope = executeInScope;
|
|
2867
2914
|
exports.flatTree = flatTree;
|
|
2868
2915
|
exports.forEachDeep = forEachDeep;
|
|
2869
|
-
exports.forEachMap = forEachMap;
|
|
2870
2916
|
exports.formatDate = formatDate;
|
|
2871
2917
|
exports.formatNumber = formatNumber;
|
|
2872
2918
|
exports.formatTree = formatTree;
|
|
@@ -2908,6 +2954,7 @@
|
|
|
2908
2954
|
exports.isUndefined = isUndefined;
|
|
2909
2955
|
exports.isUrl = isUrl;
|
|
2910
2956
|
exports.isValidDate = isValidDate;
|
|
2957
|
+
exports.mapDeep = mapDeep;
|
|
2911
2958
|
exports.multiply = multiply;
|
|
2912
2959
|
exports.numberAbbr = numberAbbr;
|
|
2913
2960
|
exports.numberToHex = numberToHex;
|
package/package.json
CHANGED
package/lib/tsdoc-metadata.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
-
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
-
{
|
|
4
|
-
"tsdocVersion": "0.12",
|
|
5
|
-
"toolPackages": [
|
|
6
|
-
{
|
|
7
|
-
"packageName": "@microsoft/api-extractor",
|
|
8
|
-
"packageVersion": "7.38.3"
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
}
|