@vope/utils 1.7.5 → 1.8.0

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.
Files changed (52) hide show
  1. package/dist/each.js +28 -6
  2. package/dist/index.cjs.js +39 -9
  3. package/dist/index.js +2 -1
  4. package/dist/input-regex.js +12 -4
  5. package/dist/{each.d.ts → src/each.d.ts} +8 -0
  6. package/dist/{index.d.ts → src/index.d.ts} +1 -1
  7. package/dist/src/input-regex.d.ts +14 -0
  8. package/package.json +81 -81
  9. package/sub_storage/package.json +0 -1
  10. package/dist/input-regex.d.ts +0 -12
  11. /package/dist/{async-lock.d.ts → src/async-lock.d.ts} +0 -0
  12. /package/dist/{calc.d.ts → src/calc.d.ts} +0 -0
  13. /package/dist/{clamp.d.ts → src/clamp.d.ts} +0 -0
  14. /package/dist/{classnames.d.ts → src/classnames.d.ts} +0 -0
  15. /package/dist/{compare → src/compare}/version.d.ts +0 -0
  16. /package/dist/{compare → src/compare}/weak-equal.d.ts +0 -0
  17. /package/dist/{convert → src/convert}/json.d.ts +0 -0
  18. /package/dist/{convert → src/convert}/object.d.ts +0 -0
  19. /package/dist/{convert → src/convert}/strings.d.ts +0 -0
  20. /package/dist/{cron.d.ts → src/cron.d.ts} +0 -0
  21. /package/dist/{desens.d.ts → src/desens.d.ts} +0 -0
  22. /package/dist/{dic.d.ts → src/dic.d.ts} +0 -0
  23. /package/dist/{disable-enumerable.d.ts → src/disable-enumerable.d.ts} +0 -0
  24. /package/dist/{encoding.d.ts → src/encoding.d.ts} +0 -0
  25. /package/dist/{flat-tree.d.ts → src/flat-tree.d.ts} +0 -0
  26. /package/dist/{index-sort.d.ts → src/index-sort.d.ts} +0 -0
  27. /package/dist/{is → src/is}/class.d.ts +0 -0
  28. /package/dist/{is → src/is}/empty.d.ts +0 -0
  29. /package/dist/{is → src/is}/key.d.ts +0 -0
  30. /package/dist/{is → src/is}/null.d.ts +0 -0
  31. /package/dist/{load → src/load}/image.d.ts +0 -0
  32. /package/dist/{memory → src/memory}/basic.d.ts +0 -0
  33. /package/dist/{memory → src/memory}/list.d.ts +0 -0
  34. /package/dist/{memory → src/memory}/power.d.ts +0 -0
  35. /package/dist/{memory → src/memory}/simple.d.ts +0 -0
  36. /package/dist/{neo4j-anchors.d.ts → src/neo4j-anchors.d.ts} +0 -0
  37. /package/dist/{neo4j.d.ts → src/neo4j.d.ts} +0 -0
  38. /package/dist/{once.d.ts → src/once.d.ts} +0 -0
  39. /package/dist/{parse → src/parse}/num.d.ts +0 -0
  40. /package/dist/{power → src/power}/decon.d.ts +0 -0
  41. /package/dist/{rotate → src/rotate}/angle.d.ts +0 -0
  42. /package/dist/{rotate → src/rotate}/rad.d.ts +0 -0
  43. /package/dist/{serialize → src/serialize}/url-params.d.ts +0 -0
  44. /package/dist/{storage → src/storage}/offline.d.ts +0 -0
  45. /package/dist/{style → src/style}/css.d.ts +0 -0
  46. /package/dist/{subscriber.d.ts → src/subscriber.d.ts} +0 -0
  47. /package/dist/{table → src/table}/flex.d.ts +0 -0
  48. /package/dist/{union.d.ts → src/union.d.ts} +0 -0
  49. /package/dist/{url → src/url}/join.d.ts +0 -0
  50. /package/dist/{url → src/url}/params.d.ts +0 -0
  51. /package/dist/{wait.d.ts → src/wait.d.ts} +0 -0
  52. /package/sub_storage/{offline.d.ts → src/storage/offline.d.ts} +0 -0
package/dist/each.js CHANGED
@@ -1,9 +1,11 @@
1
1
  const forBfsEach = (list, up, callback) => {
2
- const stack = Array.isArray(list) ? list.slice() : Array.from(list);
3
- for (const value of stack) {
4
- if (!callback(value)) break;
5
- const result = up(value);
6
- result === void 0 || stack.push(...result);
2
+ const stack = [list];
3
+ for (const list2 of stack) {
4
+ for (const value of list2) {
5
+ if (!callback(value)) break;
6
+ const result = up(value);
7
+ result === void 0 || stack.push(result);
8
+ }
7
9
  }
8
10
  };
9
11
  const reverseMergeIn = (from, to = []) => {
@@ -22,7 +24,27 @@ const forDfsEach = (list, up, callback) => {
22
24
  result === void 0 || reverseMergeIn(result, stack);
23
25
  }
24
26
  };
27
+ const mergeIns = (from, asc, desc) => {
28
+ let count = desc.length + (Array.isArray(from) ? from.length : from.size);
29
+ for (const value of from) {
30
+ asc.push(value);
31
+ desc[--count] = value;
32
+ }
33
+ return [asc, desc];
34
+ };
35
+ const forDfsStackEach = (list, up, callback) => {
36
+ const [stack, locals] = mergeIns(list, [], []);
37
+ while (stack.length > 0) {
38
+ const value = stack.pop();
39
+ const result = up(value);
40
+ result === void 0 || mergeIns(result, stack, locals);
41
+ }
42
+ for (let i = locals.length; i > 0; ) {
43
+ if (!callback(locals[--i])) break;
44
+ }
45
+ };
25
46
  export {
26
47
  forBfsEach,
27
- forDfsEach
48
+ forDfsEach,
49
+ forDfsStackEach
28
50
  };
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,
@@ -1172,11 +1173,13 @@ var disable_enumerable_default = (data, key) => {
1172
1173
 
1173
1174
  // src/each.ts
1174
1175
  var forBfsEach = (list, up, callback) => {
1175
- const stack = Array.isArray(list) ? list.slice() : Array.from(list);
1176
- for (const value of stack) {
1177
- if (!callback(value)) break;
1178
- const result = up(value);
1179
- result === void 0 || stack.push(...result);
1176
+ const stack = [list];
1177
+ for (const list2 of stack) {
1178
+ for (const value of list2) {
1179
+ if (!callback(value)) break;
1180
+ const result = up(value);
1181
+ result === void 0 || stack.push(result);
1182
+ }
1180
1183
  }
1181
1184
  };
1182
1185
  var reverseMergeIn = (from, to = []) => {
@@ -1195,6 +1198,25 @@ var forDfsEach = (list, up, callback) => {
1195
1198
  result === void 0 || reverseMergeIn(result, stack);
1196
1199
  }
1197
1200
  };
1201
+ var mergeIns = (from, asc, desc) => {
1202
+ let count = desc.length + (Array.isArray(from) ? from.length : from.size);
1203
+ for (const value of from) {
1204
+ asc.push(value);
1205
+ desc[--count] = value;
1206
+ }
1207
+ return [asc, desc];
1208
+ };
1209
+ var forDfsStackEach = (list, up, callback) => {
1210
+ const [stack, locals] = mergeIns(list, [], []);
1211
+ while (stack.length > 0) {
1212
+ const value = stack.pop();
1213
+ const result = up(value);
1214
+ result === void 0 || mergeIns(result, stack, locals);
1215
+ }
1216
+ for (let i = locals.length; i > 0; ) {
1217
+ if (!callback(locals[--i])) break;
1218
+ }
1219
+ };
1198
1220
 
1199
1221
  // src/encoding.ts
1200
1222
  var utf8_first_prefix = /^1{2,}/g;
@@ -1493,10 +1515,18 @@ var index_sort_default = (list, key) => {
1493
1515
  };
1494
1516
 
1495
1517
  // src/input-regex.ts
1496
- var RE_REGEX = /[$()*+.[?\\^{|]/g;
1497
- var RE_STRING = /[$()*+.[?\\^{|-]/g;
1498
- function inputRegex(text, flags) {
1499
- return flags === false ? text.replace(RE_STRING, ($0) => "\\" + $0) : new RegExp(text.replace(RE_REGEX, ($0) => "\\" + $0), flags);
1518
+ var spaces = {
1519
+ "\f": "f",
1520
+ "\n": "n",
1521
+ "\r": "r",
1522
+ " ": "t",
1523
+ "\v": "v"
1524
+ };
1525
+ var RE_REGEX = /(^[\d\a-zA-Z]|[-,=<>#&!%:;@~'`" ])|([$\\.*+^?()[\]{}|/])|([\f\n\r\t\v])/g;
1526
+ function inputRegex(text, flags, polyfill) {
1527
+ const { escape } = RegExp;
1528
+ const tmp = !polyfill && escape ? escape(text) : text.replace(RE_REGEX, ($0, $1, $2) => "\\" + ($1 ? "x" + $0.charCodeAt(0).toString(16) : $2 ? $0 : spaces[$0]));
1529
+ return flags === false ? tmp : new RegExp(tmp, flags);
1500
1530
  }
1501
1531
 
1502
1532
  // src/is/class.ts
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,
@@ -1,7 +1,15 @@
1
- const RE_REGEX = /[$()*+.[?\\^{|]/g;
2
- const RE_STRING = /[$()*+.[?\\^{|-]/g;
3
- function inputRegex(text, flags) {
4
- return flags === false ? text.replace(RE_STRING, ($0) => "\\" + $0) : new RegExp(text.replace(RE_REGEX, ($0) => "\\" + $0), flags);
1
+ const spaces = {
2
+ "\f": "f",
3
+ "\n": "n",
4
+ "\r": "r",
5
+ " ": "t",
6
+ "\v": "v"
7
+ };
8
+ const RE_REGEX = /(^[\d\a-zA-Z]|[-,=<>#&!%:;@~'`" ])|([$\\.*+^?()[\]{}|/])|([\f\n\r\t\v])/g;
9
+ function inputRegex(text, flags, polyfill) {
10
+ const { escape } = RegExp;
11
+ const tmp = !polyfill && escape ? escape(text) : text.replace(RE_REGEX, ($0, $1, $2) => "\\" + ($1 ? "x" + $0.charCodeAt(0).toString(16) : $2 ? $0 : spaces[$0]));
12
+ return flags === false ? tmp : new RegExp(tmp, flags);
5
13
  }
6
14
  export {
7
15
  inputRegex
@@ -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;
@@ -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';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 处理输入文本中的特殊字符,用于转换正则表达式
3
+ * @param text
4
+ * @param flags 表示输出正则表达式
5
+ * @param polyfill 是否强制使用polyfill,默认为自动兼容,该参数主要在测试代码环境中使用
6
+ */
7
+ export declare function inputRegex(text: string, flags?: string, polyfill?: boolean): RegExp;
8
+ /**
9
+ * 处理输入文本中的特殊字符,用于转换正则表达式
10
+ * @param text
11
+ * @param flags 表示输出字符串,该字符串将作为正则表达式的一部分
12
+ * @param polyfill 是否强制使用polyfill,默认为自动兼容,该参数主要在测试代码环境中使用
13
+ */
14
+ export declare function inputRegex(text: string, flags: false, polyfill?: boolean): string;
package/package.json CHANGED
@@ -1,81 +1,81 @@
1
- {
2
- "name": "@vope/utils",
3
- "version": "1.7.5",
4
- "description": "",
5
- "publishConfig": {
6
- "access": "public",
7
- "registry": "https://registry.npmjs.org/"
8
- },
9
- "types": "./dist/index.d.ts",
10
- "typings": "./dist/index.d.ts",
11
- "module": "./dist/index.js",
12
- "main": "./dist/index.js",
13
- "scripts": {
14
- "start": "esbuild ./start.ts --outfile=start.cjs --format=cjs & node ./start.cjs",
15
- "poststart": "esbuild ./pre.ts --outfile=pre.cjs --format=cjs & node ./pre.cjs",
16
- "build": "npm run start & node ./build.cjs",
17
- "premocha": "node ./build.cjs --type=test",
18
- "mocha": "mocha __tests/**/*.js",
19
- "test": "npm run mocha",
20
- "prepublishOnly": "npm run build & npm run test",
21
- "debug": "npm run start & npm run premocha",
22
- "clean": "rimraf start.cjs pre.cjs build.cjs src/index.ts dist/ __tests/ __examples/ sub_storage/"
23
- },
24
- "exports": {
25
- ".": {
26
- "types": "./dist/index.d.ts",
27
- "import": "./dist/index.js",
28
- "require": "./dist/index.cjs.js"
29
- },
30
- "./storage": {
31
- "types": "./sub_storage/offline.d.ts",
32
- "import": "./sub_storage/offline.js",
33
- "require": "./sub_storage/offline.cjs.js"
34
- }
35
- },
36
- "author": "vope",
37
- "license": "ISC",
38
- "files": [
39
- "dist",
40
- "sub_storage"
41
- ],
42
- "devDependencies": {
43
- "@babel/parser": "^7.26.9",
44
- "@babel/traverse": "^7.26.9",
45
- "@babel/types": "^7.26.9",
46
- "@rollup/plugin-alias": "^5.1.1",
47
- "@rollup/plugin-commonjs": "^28.0.2",
48
- "@rollup/plugin-json": "^6.1.0",
49
- "@rollup/plugin-node-resolve": "^16.0.0",
50
- "@rollup/plugin-typescript": "^12.1.2",
51
- "@types/babel__traverse": "^7.20.6",
52
- "@types/mocha": "^10.0.6",
53
- "@types/node": "^22.13.5",
54
- "@types/sm-crypto": "^0.3.4",
55
- "esbuild": "^0.25.0",
56
- "glob": "^11.0.1",
57
- "iconv-lite": "^0.6.3",
58
- "mocha": "^10.2.0",
59
- "puppeteer": "^24.3.0",
60
- "rimraf": "^5.0.5",
61
- "rollup": "^4.34.8",
62
- "tslib": "^2.8.1",
63
- "typescript": "^5.9.2",
64
- "uuid": "^11.1.0"
65
- },
66
- "dependencies": {
67
- "@type-challenges/utils": "^0.1.1",
68
- "@types/lodash-es": "^4.17.12",
69
- "@vope/types": "^1.2.0",
70
- "csstype": "^3.2.3",
71
- "localforage": "^1.10.0",
72
- "lodash-es": "^4.17.21",
73
- "sm-crypto": "^0.3.13"
74
- },
75
- "pnpm": {
76
- "onlyBuiltDependencies": [
77
- "esbuild",
78
- "puppeteer"
79
- ]
80
- }
81
- }
1
+ {
2
+ "name": "@vope/utils",
3
+ "version": "1.8.0",
4
+ "description": "",
5
+ "publishConfig": {
6
+ "access": "public",
7
+ "registry": "https://registry.npmjs.org/"
8
+ },
9
+ "types": "./dist/index.d.ts",
10
+ "typings": "./dist/index.d.ts",
11
+ "module": "./dist/index.js",
12
+ "main": "./dist/index.js",
13
+ "scripts": {
14
+ "start": "esbuild ./start.ts --outfile=start.cjs --format=cjs & node ./start.cjs",
15
+ "poststart": "esbuild ./pre.ts --outfile=pre.cjs --format=cjs & node ./pre.cjs",
16
+ "build": "npm run start & node ./build.cjs",
17
+ "premocha": "node ./build.cjs --type=test",
18
+ "mocha": "mocha __tests/**/*.js",
19
+ "test": "npm run mocha",
20
+ "prepublishOnly": "npm run build & npm run test",
21
+ "debug": "npm run start & npm run premocha",
22
+ "clean": "rimraf start.cjs pre.cjs build.cjs src/index.ts dist/ __tests/ __examples/ sub_storage/"
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js",
28
+ "require": "./dist/index.cjs.js"
29
+ },
30
+ "./storage": {
31
+ "types": "./sub_storage/offline.d.ts",
32
+ "import": "./sub_storage/offline.js",
33
+ "require": "./sub_storage/offline.cjs.js"
34
+ }
35
+ },
36
+ "author": "vope",
37
+ "license": "ISC",
38
+ "files": [
39
+ "dist",
40
+ "sub_storage"
41
+ ],
42
+ "devDependencies": {
43
+ "@babel/parser": "^7.26.9",
44
+ "@babel/traverse": "^7.26.9",
45
+ "@babel/types": "^7.26.9",
46
+ "@rollup/plugin-alias": "^5.1.1",
47
+ "@rollup/plugin-commonjs": "^28.0.2",
48
+ "@rollup/plugin-json": "^6.1.0",
49
+ "@rollup/plugin-node-resolve": "^16.0.0",
50
+ "@rollup/plugin-typescript": "^12.1.2",
51
+ "@types/babel__traverse": "^7.20.6",
52
+ "@types/mocha": "^10.0.6",
53
+ "@types/node": "^22.13.5",
54
+ "@types/sm-crypto": "^0.3.4",
55
+ "esbuild": "^0.25.0",
56
+ "glob": "^11.0.1",
57
+ "iconv-lite": "^0.6.3",
58
+ "mocha": "^10.2.0",
59
+ "puppeteer": "^24.3.0",
60
+ "rimraf": "^5.0.5",
61
+ "rollup": "^4.34.8",
62
+ "tslib": "^2.8.1",
63
+ "typescript": "^6.0.3",
64
+ "uuid": "^11.1.0"
65
+ },
66
+ "dependencies": {
67
+ "@type-challenges/utils": "^0.1.1",
68
+ "@types/lodash-es": "^4.17.12",
69
+ "@vope/types": "^1.2.0",
70
+ "csstype": "^3.2.3",
71
+ "localforage": "^1.10.0",
72
+ "lodash-es": "^4.17.21",
73
+ "sm-crypto": "^0.3.13"
74
+ },
75
+ "pnpm": {
76
+ "onlyBuiltDependencies": [
77
+ "esbuild",
78
+ "puppeteer"
79
+ ]
80
+ }
81
+ }
@@ -1,5 +1,4 @@
1
1
  {
2
- "types": "offline.d.ts",
3
2
  "import": "offline.js",
4
3
  "require": "offline.cjs.js"
5
4
  }
@@ -1,12 +0,0 @@
1
- /**
2
- * 处理输入文本中的特殊字符,用于转换正则表达式
3
- * @param text
4
- * @param flags 表示输出正则表达式
5
- */
6
- export declare function inputRegex(text: string, flags?: string): RegExp;
7
- /**
8
- * 处理输入文本中的特殊字符,用于转换正则表达式
9
- * @param text
10
- * @param flags 表示输出字符串,该字符串将作为正则表达式的一部分
11
- */
12
- export declare function inputRegex(text: string, flags: false): string;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes