@vope/utils 1.7.4 → 1.7.6
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/each.d.ts +8 -0
- package/dist/each.js +21 -1
- package/dist/flat-tree.d.ts +2 -1
- package/dist/flat-tree.js +2 -1
- package/dist/index.cjs.js +22 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
package/dist/each.d.ts
CHANGED
|
@@ -12,3 +12,11 @@ export declare const forBfsEach: <T>(list: T[] | Set<T>, up: (data: T) => T[] |
|
|
|
12
12
|
* @param callback 节点回调,返回false则停止搜索
|
|
13
13
|
*/
|
|
14
14
|
export declare const forDfsEach: <T>(list: T[] | Set<T>, up: (data: T) => T[] | Set<T> | void, callback: (data: T) => boolean) => void;
|
|
15
|
+
/**
|
|
16
|
+
* 深度优先搜索(栈模式),回调规则为从里到外
|
|
17
|
+
* @param list 节点源
|
|
18
|
+
* @param up 节点下钻,返回当前节点的子节点
|
|
19
|
+
* @param callback 节点回调,返回false则停止搜索
|
|
20
|
+
* @description 应用场景:统计子节点的数据量
|
|
21
|
+
*/
|
|
22
|
+
export declare const forDfsStackEach: <T>(list: T[] | Set<T>, up: (data: T) => T[] | Set<T> | void, callback: (data: T) => boolean) => void;
|
package/dist/each.js
CHANGED
|
@@ -22,7 +22,27 @@ const forDfsEach = (list, up, callback) => {
|
|
|
22
22
|
result === void 0 || reverseMergeIn(result, stack);
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
+
const mergeIns = (from, asc, desc) => {
|
|
26
|
+
let count = desc.length + (Array.isArray(from) ? from.length : from.size);
|
|
27
|
+
for (const value of from) {
|
|
28
|
+
asc.push(value);
|
|
29
|
+
desc[--count] = value;
|
|
30
|
+
}
|
|
31
|
+
return [asc, desc];
|
|
32
|
+
};
|
|
33
|
+
const forDfsStackEach = (list, up, callback) => {
|
|
34
|
+
const [stack, locals] = mergeIns(list, [], []);
|
|
35
|
+
while (stack.length > 0) {
|
|
36
|
+
const value = stack.pop();
|
|
37
|
+
const result = up(value);
|
|
38
|
+
result === void 0 || mergeIns(result, stack, locals);
|
|
39
|
+
}
|
|
40
|
+
for (let i = locals.length; i > 0; ) {
|
|
41
|
+
if (!callback(locals[--i])) break;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
25
44
|
export {
|
|
26
45
|
forBfsEach,
|
|
27
|
-
forDfsEach
|
|
46
|
+
forDfsEach,
|
|
47
|
+
forDfsStackEach
|
|
28
48
|
};
|
package/dist/flat-tree.d.ts
CHANGED
|
@@ -79,8 +79,9 @@ export declare class FlatTree<K extends string, T extends {
|
|
|
79
79
|
getSup(value: Value): T | undefined;
|
|
80
80
|
/**
|
|
81
81
|
* 获取子级节点
|
|
82
|
+
* @description 当value === null时则获取所有顶级节点
|
|
82
83
|
*/
|
|
83
|
-
getSub(value: Value, callback?: (data: T) => void): T[] | undefined;
|
|
84
|
+
getSub(value: Value | null, callback?: (data: T) => void): T[] | undefined;
|
|
84
85
|
/**
|
|
85
86
|
* 是否含有节点
|
|
86
87
|
*/
|
package/dist/flat-tree.js
CHANGED
|
@@ -134,10 +134,11 @@ class FlatTree {
|
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
136
|
* 获取子级节点
|
|
137
|
+
* @description 当value === null时则获取所有顶级节点
|
|
137
138
|
*/
|
|
138
139
|
getSub(value, callback) {
|
|
139
140
|
const { memory } = this;
|
|
140
|
-
const tmp = this.downs.get(value);
|
|
141
|
+
const tmp = value === null ? this.list : this.downs.get(value);
|
|
141
142
|
if (!tmp) return;
|
|
142
143
|
const list = [];
|
|
143
144
|
for (const id of tmp) {
|
package/dist/index.cjs.js
CHANGED
|
@@ -67,6 +67,7 @@ __export(index_exports, {
|
|
|
67
67
|
flatURLParams: () => flatURLParams,
|
|
68
68
|
forBfsEach: () => forBfsEach,
|
|
69
69
|
forDfsEach: () => forDfsEach,
|
|
70
|
+
forDfsStackEach: () => forDfsStackEach,
|
|
70
71
|
getEncoding: () => getEncoding,
|
|
71
72
|
hash8json: () => hash8json,
|
|
72
73
|
hash8object: () => hash8object,
|
|
@@ -1195,6 +1196,25 @@ var forDfsEach = (list, up, callback) => {
|
|
|
1195
1196
|
result === void 0 || reverseMergeIn(result, stack);
|
|
1196
1197
|
}
|
|
1197
1198
|
};
|
|
1199
|
+
var mergeIns = (from, asc, desc) => {
|
|
1200
|
+
let count = desc.length + (Array.isArray(from) ? from.length : from.size);
|
|
1201
|
+
for (const value of from) {
|
|
1202
|
+
asc.push(value);
|
|
1203
|
+
desc[--count] = value;
|
|
1204
|
+
}
|
|
1205
|
+
return [asc, desc];
|
|
1206
|
+
};
|
|
1207
|
+
var forDfsStackEach = (list, up, callback) => {
|
|
1208
|
+
const [stack, locals] = mergeIns(list, [], []);
|
|
1209
|
+
while (stack.length > 0) {
|
|
1210
|
+
const value = stack.pop();
|
|
1211
|
+
const result = up(value);
|
|
1212
|
+
result === void 0 || mergeIns(result, stack, locals);
|
|
1213
|
+
}
|
|
1214
|
+
for (let i = locals.length; i > 0; ) {
|
|
1215
|
+
if (!callback(locals[--i])) break;
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1198
1218
|
|
|
1199
1219
|
// src/encoding.ts
|
|
1200
1220
|
var utf8_first_prefix = /^1{2,}/g;
|
|
@@ -1389,10 +1409,11 @@ var FlatTree = class {
|
|
|
1389
1409
|
}
|
|
1390
1410
|
/**
|
|
1391
1411
|
* 获取子级节点
|
|
1412
|
+
* @description 当value === null时则获取所有顶级节点
|
|
1392
1413
|
*/
|
|
1393
1414
|
getSub(value, callback) {
|
|
1394
1415
|
const { memory } = this;
|
|
1395
|
-
const tmp = this.downs.get(value);
|
|
1416
|
+
const tmp = value === null ? this.list : this.downs.get(value);
|
|
1396
1417
|
if (!tmp) return;
|
|
1397
1418
|
const list = [];
|
|
1398
1419
|
for (const id of tmp) {
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { weekDic, default_max_second, default_min_second, default_max_minute, de
|
|
|
11
11
|
export { type DesensDecrypt, type DesensEncrypt, desensEncrypt, desensDecrypt, desensReplace } from './desens';
|
|
12
12
|
export { type Dic, default as DicRollup } from './dic';
|
|
13
13
|
export { default as disableEnumerable } from './disable-enumerable';
|
|
14
|
-
export { forBfsEach, forDfsEach } from './each';
|
|
14
|
+
export { forBfsEach, forDfsEach, forDfsStackEach } from './each';
|
|
15
15
|
export { getEncoding } from './encoding';
|
|
16
16
|
export { FlatTree } from './flat-tree';
|
|
17
17
|
export { default as indexSort } from './index-sort';
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { weekDic, default_max_second, default_min_second, default_max_minute, de
|
|
|
11
11
|
import { desensEncrypt, desensDecrypt, desensReplace } from "./desens";
|
|
12
12
|
import { default as default4 } from "./dic";
|
|
13
13
|
import { default as default5 } from "./disable-enumerable";
|
|
14
|
-
import { forBfsEach, forDfsEach } from "./each";
|
|
14
|
+
import { forBfsEach, forDfsEach, forDfsStackEach } from "./each";
|
|
15
15
|
import { getEncoding } from "./encoding";
|
|
16
16
|
import { FlatTree } from "./flat-tree";
|
|
17
17
|
import { default as default6 } from "./index-sort";
|
|
@@ -89,6 +89,7 @@ export {
|
|
|
89
89
|
flatURLParams,
|
|
90
90
|
forBfsEach,
|
|
91
91
|
forDfsEach,
|
|
92
|
+
forDfsStackEach,
|
|
92
93
|
getEncoding,
|
|
93
94
|
hash8json,
|
|
94
95
|
hash8object,
|