@vope/utils 1.7.5 → 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 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/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;
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vope/utils",
3
- "version": "1.7.5",
3
+ "version": "1.7.6",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public",