@vope/utils 1.9.1 → 1.9.2
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/CHANGELOG.md +6 -0
- package/README.md +3 -0
- package/dist/each.d.ts +22 -0
- package/dist/each.js +33 -0
- package/dist/index.cjs.js +33 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.9.2] - 2026-09-15
|
|
9
|
+
### Added
|
|
10
|
+
- 添加 [forBfsAsyncEach](src/each.ts) 方法,[forBfsEach](src/each.ts) 异步版本
|
|
11
|
+
- 添加 [forDfsAsyncEach](src/each.ts) 方法,[forDfsEach](src/each.ts) 异步版本
|
|
12
|
+
- 添加 [forDfsStackAsyncEach](src/each.ts) 方法,[forDfsStackEach](src/each.ts) 异步版本
|
|
13
|
+
|
|
8
14
|
## [1.9.1] - 2026-05-11
|
|
9
15
|
### Fixed
|
|
10
16
|
- 修复升级依赖 typescript 引起的 .d.ts 文件生成路径错误问题
|
package/README.md
CHANGED
package/dist/each.d.ts
CHANGED
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
* @param callback 节点回调,返回false则停止搜索
|
|
6
6
|
*/
|
|
7
7
|
export declare const forBfsEach: <T>(list: T[] | Set<T>, up: (data: T) => T[] | Set<T> | void, callback: (data: T) => boolean) => void;
|
|
8
|
+
/**
|
|
9
|
+
* 广度优先异步搜索
|
|
10
|
+
* @param list 节点源
|
|
11
|
+
* @param up 节点下钻,返回当前节点的子节点
|
|
12
|
+
* @param callback 节点回调,返回false/Promise<false>则停止搜索
|
|
13
|
+
*/
|
|
14
|
+
export declare const forBfsAsyncEach: <T>(list: T[] | Set<T>, up: (data: T) => T[] | Set<T> | void, callback: (data: T) => boolean | Promise<boolean>) => Promise<void>;
|
|
8
15
|
/**
|
|
9
16
|
* 深度优先搜索
|
|
10
17
|
* @param list 节点源
|
|
@@ -12,6 +19,13 @@ export declare const forBfsEach: <T>(list: T[] | Set<T>, up: (data: T) => T[] |
|
|
|
12
19
|
* @param callback 节点回调,返回false则停止搜索
|
|
13
20
|
*/
|
|
14
21
|
export declare const forDfsEach: <T>(list: T[] | Set<T>, up: (data: T) => T[] | Set<T> | void, callback: (data: T) => boolean) => void;
|
|
22
|
+
/**
|
|
23
|
+
* 深度优先异步搜索
|
|
24
|
+
* @param list 节点源
|
|
25
|
+
* @param up 节点下钻,返回当前节点的子节点
|
|
26
|
+
* @param callback 节点回调,返回false/Promise<false>则停止搜索
|
|
27
|
+
*/
|
|
28
|
+
export declare const forDfsAsyncEach: <T>(list: T[] | Set<T>, up: (data: T) => T[] | Set<T> | void, callback: (data: T) => boolean | Promise<boolean>) => Promise<void>;
|
|
15
29
|
/**
|
|
16
30
|
* 深度优先搜索(栈模式),回调规则为从里到外
|
|
17
31
|
* @param list 节点源
|
|
@@ -20,3 +34,11 @@ export declare const forDfsEach: <T>(list: T[] | Set<T>, up: (data: T) => T[] |
|
|
|
20
34
|
* @description 应用场景:统计子节点的数据量
|
|
21
35
|
*/
|
|
22
36
|
export declare const forDfsStackEach: <T>(list: T[] | Set<T>, up: (data: T) => T[] | Set<T> | void, callback: (data: T) => boolean) => void;
|
|
37
|
+
/**
|
|
38
|
+
* 深度优先异步搜索(栈模式),回调规则为从里到外
|
|
39
|
+
* @param list 节点源
|
|
40
|
+
* @param up 节点下钻,返回当前节点的子节点
|
|
41
|
+
* @param callback 节点回调,返回false/Promise<false>则停止搜索
|
|
42
|
+
* @description 应用场景:统计子节点的数据量
|
|
43
|
+
*/
|
|
44
|
+
export declare const forDfsStackAsyncEach: <T>(list: T[] | Set<T>, up: (data: T) => T[] | Set<T> | void, callback: (data: T) => boolean | Promise<boolean>) => Promise<void>;
|
package/dist/each.js
CHANGED
|
@@ -8,6 +8,16 @@ const forBfsEach = (list, up, callback) => {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
+
const forBfsAsyncEach = async (list, up, callback) => {
|
|
12
|
+
const stack = [list];
|
|
13
|
+
for (const list2 of stack) {
|
|
14
|
+
for (const value of list2) {
|
|
15
|
+
if (!await callback(value)) break;
|
|
16
|
+
const result = up(value);
|
|
17
|
+
result === void 0 || stack.push(result);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
11
21
|
const reverseMergeIn = (from, to = []) => {
|
|
12
22
|
let i = to.length + (Array.isArray(from) ? from.length : from.size);
|
|
13
23
|
for (const value of from) {
|
|
@@ -24,6 +34,15 @@ const forDfsEach = (list, up, callback) => {
|
|
|
24
34
|
result === void 0 || reverseMergeIn(result, stack);
|
|
25
35
|
}
|
|
26
36
|
};
|
|
37
|
+
const forDfsAsyncEach = async (list, up, callback) => {
|
|
38
|
+
const stack = reverseMergeIn(list);
|
|
39
|
+
while (stack.length > 0) {
|
|
40
|
+
const value = stack.pop();
|
|
41
|
+
if (!await callback(value)) break;
|
|
42
|
+
const result = up(value);
|
|
43
|
+
result === void 0 || reverseMergeIn(result, stack);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
27
46
|
const mergeIns = (from, asc, desc) => {
|
|
28
47
|
let count = desc.length + (Array.isArray(from) ? from.length : from.size);
|
|
29
48
|
for (const value of from) {
|
|
@@ -43,8 +62,22 @@ const forDfsStackEach = (list, up, callback) => {
|
|
|
43
62
|
if (!callback(locals[--i])) break;
|
|
44
63
|
}
|
|
45
64
|
};
|
|
65
|
+
const forDfsStackAsyncEach = async (list, up, callback) => {
|
|
66
|
+
const [stack, locals] = mergeIns(list, [], []);
|
|
67
|
+
while (stack.length > 0) {
|
|
68
|
+
const value = stack.pop();
|
|
69
|
+
const result = up(value);
|
|
70
|
+
result === void 0 || mergeIns(result, stack, locals);
|
|
71
|
+
}
|
|
72
|
+
for (let i = locals.length; i > 0; ) {
|
|
73
|
+
if (!await callback(locals[--i])) break;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
46
76
|
export {
|
|
77
|
+
forBfsAsyncEach,
|
|
47
78
|
forBfsEach,
|
|
79
|
+
forDfsAsyncEach,
|
|
48
80
|
forDfsEach,
|
|
81
|
+
forDfsStackAsyncEach,
|
|
49
82
|
forDfsStackEach
|
|
50
83
|
};
|
package/dist/index.cjs.js
CHANGED
|
@@ -65,8 +65,11 @@ __export(index_exports, {
|
|
|
65
65
|
desensReplace: () => desensReplace,
|
|
66
66
|
disableEnumerable: () => disable_enumerable_default,
|
|
67
67
|
flatURLParams: () => flatURLParams,
|
|
68
|
+
forBfsAsyncEach: () => forBfsAsyncEach,
|
|
68
69
|
forBfsEach: () => forBfsEach,
|
|
70
|
+
forDfsAsyncEach: () => forDfsAsyncEach,
|
|
69
71
|
forDfsEach: () => forDfsEach,
|
|
72
|
+
forDfsStackAsyncEach: () => forDfsStackAsyncEach,
|
|
70
73
|
forDfsStackEach: () => forDfsStackEach,
|
|
71
74
|
getEncoding: () => getEncoding,
|
|
72
75
|
hash8json: () => hash8json,
|
|
@@ -1190,6 +1193,16 @@ var forBfsEach = (list, up, callback) => {
|
|
|
1190
1193
|
}
|
|
1191
1194
|
}
|
|
1192
1195
|
};
|
|
1196
|
+
var forBfsAsyncEach = async (list, up, callback) => {
|
|
1197
|
+
const stack = [list];
|
|
1198
|
+
for (const list2 of stack) {
|
|
1199
|
+
for (const value of list2) {
|
|
1200
|
+
if (!await callback(value)) break;
|
|
1201
|
+
const result = up(value);
|
|
1202
|
+
result === void 0 || stack.push(result);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1193
1206
|
var reverseMergeIn = (from, to = []) => {
|
|
1194
1207
|
let i = to.length + (Array.isArray(from) ? from.length : from.size);
|
|
1195
1208
|
for (const value of from) {
|
|
@@ -1206,6 +1219,15 @@ var forDfsEach = (list, up, callback) => {
|
|
|
1206
1219
|
result === void 0 || reverseMergeIn(result, stack);
|
|
1207
1220
|
}
|
|
1208
1221
|
};
|
|
1222
|
+
var forDfsAsyncEach = async (list, up, callback) => {
|
|
1223
|
+
const stack = reverseMergeIn(list);
|
|
1224
|
+
while (stack.length > 0) {
|
|
1225
|
+
const value = stack.pop();
|
|
1226
|
+
if (!await callback(value)) break;
|
|
1227
|
+
const result = up(value);
|
|
1228
|
+
result === void 0 || reverseMergeIn(result, stack);
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1209
1231
|
var mergeIns = (from, asc, desc) => {
|
|
1210
1232
|
let count = desc.length + (Array.isArray(from) ? from.length : from.size);
|
|
1211
1233
|
for (const value of from) {
|
|
@@ -1225,6 +1247,17 @@ var forDfsStackEach = (list, up, callback) => {
|
|
|
1225
1247
|
if (!callback(locals[--i])) break;
|
|
1226
1248
|
}
|
|
1227
1249
|
};
|
|
1250
|
+
var forDfsStackAsyncEach = async (list, up, callback) => {
|
|
1251
|
+
const [stack, locals] = mergeIns(list, [], []);
|
|
1252
|
+
while (stack.length > 0) {
|
|
1253
|
+
const value = stack.pop();
|
|
1254
|
+
const result = up(value);
|
|
1255
|
+
result === void 0 || mergeIns(result, stack, locals);
|
|
1256
|
+
}
|
|
1257
|
+
for (let i = locals.length; i > 0; ) {
|
|
1258
|
+
if (!await callback(locals[--i])) break;
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1228
1261
|
|
|
1229
1262
|
// src/encoding.ts
|
|
1230
1263
|
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, forDfsStackEach } from './each';
|
|
14
|
+
export { forBfsEach, forBfsAsyncEach, forDfsEach, forDfsAsyncEach, forDfsStackEach, forDfsStackAsyncEach } 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, forDfsStackEach } from "./each";
|
|
14
|
+
import { forBfsEach, forBfsAsyncEach, forDfsEach, forDfsAsyncEach, forDfsStackEach, forDfsStackAsyncEach } from "./each";
|
|
15
15
|
import { getEncoding } from "./encoding";
|
|
16
16
|
import { FlatTree } from "./flat-tree";
|
|
17
17
|
import { default as default6 } from "./index-sort";
|
|
@@ -87,8 +87,11 @@ export {
|
|
|
87
87
|
desensReplace,
|
|
88
88
|
default5 as disableEnumerable,
|
|
89
89
|
flatURLParams,
|
|
90
|
+
forBfsAsyncEach,
|
|
90
91
|
forBfsEach,
|
|
92
|
+
forDfsAsyncEach,
|
|
91
93
|
forDfsEach,
|
|
94
|
+
forDfsStackAsyncEach,
|
|
92
95
|
forDfsStackEach,
|
|
93
96
|
getEncoding,
|
|
94
97
|
hash8json,
|