@vope/utils 1.9.1 → 1.9.3
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 +14 -0
- package/README.md +7 -0
- package/dist/each.d.ts +22 -0
- package/dist/each.js +35 -2
- package/dist/index.cjs.js +35 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -1
- package/package.json +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,20 @@ 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.3] - 2026-11-11
|
|
9
|
+
### Fixed
|
|
10
|
+
- 修复 [forBfsEach](src/each.ts)、[forBfsAsyncEach](src/each.ts)、[forDfsEach](src/each.ts) 和 [forDfsAsyncEach](src/each.ts) 在嵌套遍历中回调返回 `false` 后未彻底停止的问题
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- 完善 [forBfsEach](src/each.ts)、[forBfsAsyncEach](src/each.ts) 和 [forDfsAsyncEach](src/each.ts) 单元测试
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## [1.9.2] - 2026-09-15
|
|
17
|
+
### Added
|
|
18
|
+
- 添加 [forBfsAsyncEach](src/each.ts) 方法,[forBfsEach](src/each.ts) 异步版本
|
|
19
|
+
- 添加 [forDfsAsyncEach](src/each.ts) 方法,[forDfsEach](src/each.ts) 异步版本
|
|
20
|
+
- 添加 [forDfsStackAsyncEach](src/each.ts) 方法,[forDfsStackEach](src/each.ts) 异步版本
|
|
21
|
+
|
|
8
22
|
## [1.9.1] - 2026-05-11
|
|
9
23
|
### Fixed
|
|
10
24
|
- 修复升级依赖 typescript 引起的 .d.ts 文件生成路径错误问题
|
package/README.md
CHANGED
|
@@ -12,6 +12,9 @@ pnpm add @vope/utils
|
|
|
12
12
|
yarn add @vope/utils
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
## Logs
|
|
16
|
+
[CHANGELOG](./CHANGELOG.md)
|
|
17
|
+
|
|
15
18
|
## API 文档
|
|
16
19
|
|
|
17
20
|
### 异步控制
|
|
@@ -29,7 +32,11 @@ yarn add @vope/utils
|
|
|
29
32
|
|--------|------|
|
|
30
33
|
| FlatTree | 扁平树 |
|
|
31
34
|
| forBfsEach | 广度优先搜索 |
|
|
35
|
+
| forBfsAsyncEach | 广度优先异步搜索 |
|
|
32
36
|
| forDfsEach | 深度优先搜索 |
|
|
37
|
+
| forDfsAsyncEach | 深度优先异步搜索 |
|
|
38
|
+
| forDfsStackEach | 深度优先栈模式搜索(从里到外回调) |
|
|
39
|
+
| forDfsStackAsyncEach | 深度优先栈模式异步搜索(从里到外回调) |
|
|
33
40
|
|
|
34
41
|
### 数据转换
|
|
35
42
|
|
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
|
@@ -2,7 +2,17 @@ const forBfsEach = (list, up, callback) => {
|
|
|
2
2
|
const stack = [list];
|
|
3
3
|
for (const list2 of stack) {
|
|
4
4
|
for (const value of list2) {
|
|
5
|
-
if (!callback(value))
|
|
5
|
+
if (!callback(value)) return;
|
|
6
|
+
const result = up(value);
|
|
7
|
+
result === void 0 || stack.push(result);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
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)) return;
|
|
6
16
|
const result = up(value);
|
|
7
17
|
result === void 0 || stack.push(result);
|
|
8
18
|
}
|
|
@@ -19,7 +29,16 @@ const forDfsEach = (list, up, callback) => {
|
|
|
19
29
|
const stack = reverseMergeIn(list);
|
|
20
30
|
while (stack.length > 0) {
|
|
21
31
|
const value = stack.pop();
|
|
22
|
-
if (!callback(value))
|
|
32
|
+
if (!callback(value)) return;
|
|
33
|
+
const result = up(value);
|
|
34
|
+
result === void 0 || reverseMergeIn(result, stack);
|
|
35
|
+
}
|
|
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)) return;
|
|
23
42
|
const result = up(value);
|
|
24
43
|
result === void 0 || reverseMergeIn(result, stack);
|
|
25
44
|
}
|
|
@@ -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,
|
|
@@ -1184,7 +1187,17 @@ var forBfsEach = (list, up, callback) => {
|
|
|
1184
1187
|
const stack = [list];
|
|
1185
1188
|
for (const list2 of stack) {
|
|
1186
1189
|
for (const value of list2) {
|
|
1187
|
-
if (!callback(value))
|
|
1190
|
+
if (!callback(value)) return;
|
|
1191
|
+
const result = up(value);
|
|
1192
|
+
result === void 0 || stack.push(result);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
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)) return;
|
|
1188
1201
|
const result = up(value);
|
|
1189
1202
|
result === void 0 || stack.push(result);
|
|
1190
1203
|
}
|
|
@@ -1201,7 +1214,16 @@ var forDfsEach = (list, up, callback) => {
|
|
|
1201
1214
|
const stack = reverseMergeIn(list);
|
|
1202
1215
|
while (stack.length > 0) {
|
|
1203
1216
|
const value = stack.pop();
|
|
1204
|
-
if (!callback(value))
|
|
1217
|
+
if (!callback(value)) return;
|
|
1218
|
+
const result = up(value);
|
|
1219
|
+
result === void 0 || reverseMergeIn(result, stack);
|
|
1220
|
+
}
|
|
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)) return;
|
|
1205
1227
|
const result = up(value);
|
|
1206
1228
|
result === void 0 || reverseMergeIn(result, stack);
|
|
1207
1229
|
}
|
|
@@ -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,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vope/utils",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -78,5 +78,10 @@
|
|
|
78
78
|
"esbuild",
|
|
79
79
|
"puppeteer"
|
|
80
80
|
]
|
|
81
|
+
},
|
|
82
|
+
"repository": {
|
|
83
|
+
"type": "git",
|
|
84
|
+
"url": "git+https://github.com/702017364/utils.git",
|
|
85
|
+
"directory": "packages/utils"
|
|
81
86
|
}
|
|
82
87
|
}
|