@pawover/kit 0.4.2 → 0.6.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.
- package/package.json +166 -29
- package/packages/eslint-rules/dist/core.antfu.cjs +78 -0
- package/packages/eslint-rules/dist/core.antfu.d.cts +1 -0
- package/packages/eslint-rules/dist/core.antfu.d.ts +74 -0
- package/packages/eslint-rules/dist/core.antfu.js +79 -0
- package/packages/eslint-rules/dist/core.imports.cjs +59 -0
- package/packages/eslint-rules/dist/core.imports.d.cts +1 -0
- package/packages/eslint-rules/dist/core.imports.d.ts +61 -0
- package/packages/eslint-rules/dist/core.imports.js +59 -0
- package/packages/eslint-rules/dist/core.importsSort.cjs +7 -0
- package/packages/eslint-rules/dist/core.importsSort.d.cts +1 -0
- package/packages/eslint-rules/dist/core.importsSort.d.ts +7 -0
- package/packages/eslint-rules/dist/core.importsSort.js +7 -0
- package/packages/eslint-rules/dist/core.javascript.cjs +1208 -0
- package/packages/eslint-rules/dist/core.javascript.d.cts +1 -0
- package/packages/eslint-rules/dist/core.javascript.d.ts +1216 -0
- package/packages/eslint-rules/dist/core.javascript.js +1208 -0
- package/packages/eslint-rules/dist/core.react.cjs +551 -0
- package/packages/eslint-rules/dist/core.react.d.cts +1 -0
- package/packages/eslint-rules/dist/core.react.d.ts +551 -0
- package/packages/eslint-rules/dist/core.react.js +551 -0
- package/packages/eslint-rules/dist/core.reactHooks.cjs +107 -0
- package/packages/eslint-rules/dist/core.reactHooks.d.cts +1 -0
- package/packages/eslint-rules/dist/core.reactHooks.d.ts +107 -0
- package/packages/eslint-rules/dist/core.reactHooks.js +107 -0
- package/packages/eslint-rules/dist/core.stylistic.cjs +608 -0
- package/packages/eslint-rules/dist/core.stylistic.d.cts +1 -0
- package/packages/eslint-rules/dist/core.stylistic.d.ts +595 -0
- package/packages/eslint-rules/dist/core.stylistic.js +608 -0
- package/packages/eslint-rules/dist/core.typescript.cjs +905 -0
- package/packages/eslint-rules/dist/core.typescript.d.cts +1 -0
- package/packages/eslint-rules/dist/core.typescript.d.ts +917 -0
- package/packages/eslint-rules/dist/core.typescript.js +906 -0
- package/packages/eslint-rules/dist/core.vue.cjs +312 -0
- package/packages/eslint-rules/dist/core.vue.d.cts +1 -0
- package/packages/eslint-rules/dist/core.vue.d.ts +293 -0
- package/packages/eslint-rules/dist/core.vue.js +313 -0
- package/packages/eslint-rules/dist/index.cjs +126 -0
- package/packages/eslint-rules/dist/index.d.cts +1 -0
- package/packages/eslint-rules/dist/index.d.ts +113 -0
- package/packages/eslint-rules/dist/index.js +126 -0
- package/packages/eslint-rules/dist/preset-Bk6lxNP0.cjs +107 -0
- package/packages/eslint-rules/dist/preset-CQJST7pW.js +102 -0
- package/packages/hooks/dist/alova.cjs +53 -0
- package/packages/hooks/dist/alova.d.cts +1 -0
- package/packages/hooks/dist/index.cjs +0 -0
- package/packages/hooks/dist/index.d.cts +1 -0
- package/packages/hooks/dist/react.cjs +169 -0
- package/packages/hooks/dist/react.d.cts +1 -0
- package/packages/hooks/dist/react.d.ts +2 -60
- package/packages/hooks/dist/react.js +2 -2441
- package/packages/types/dist/index.cjs +0 -0
- package/packages/types/dist/index.d.cts +1 -0
- package/packages/types/dist/index.d.ts +271 -0
- package/packages/types/dist/index.js +0 -0
- package/packages/types/dist/react.cjs +0 -0
- package/packages/types/dist/react.d.cts +1 -0
- package/packages/types/dist/react.d.ts +64 -0
- package/packages/types/dist/react.js +0 -0
- package/packages/utils/dist/index.cjs +2300 -0
- package/packages/utils/dist/index.d.cts +1 -0
- package/packages/utils/dist/index.d.ts +156 -2721
- package/packages/utils/dist/index.js +122 -35
- package/packages/utils/dist/math-BznvO4qI.cjs +1029 -0
- package/packages/utils/dist/{math-B5PyWuKn.js → math-DRbCtLQH.js} +31 -27
- package/packages/utils/dist/math.cjs +3 -0
- package/packages/utils/dist/math.d.cts +1 -0
- package/packages/utils/dist/math.d.ts +3 -0
- package/packages/utils/dist/math.js +1 -1
- package/packages/utils/dist/vite.cjs +44 -0
- package/packages/utils/dist/vite.d.cts +1 -0
- package/packages/utils/dist/vite.js +12 -8
- package/packages/zod/dist/index.cjs +91 -0
- package/packages/zod/dist/index.d.cts +1 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { n as StringUtil, r as TypeUtil, t as MathUtil } from "./math-
|
|
1
|
+
import { n as StringUtil, r as TypeUtil, t as MathUtil } from "./math-DRbCtLQH.js";
|
|
2
2
|
//#region src/array/arrayUtil.ts
|
|
3
3
|
/**
|
|
4
4
|
* 数组工具类
|
|
5
5
|
*/
|
|
6
6
|
var ArrayUtil = class {
|
|
7
|
-
static cast(candidate,
|
|
8
|
-
if (
|
|
7
|
+
static cast(candidate, checkNullish = true) {
|
|
8
|
+
if (checkNullish && TypeUtil.isNullish(candidate)) return [];
|
|
9
9
|
return TypeUtil.isArray(candidate) ? [...candidate] : [candidate];
|
|
10
10
|
}
|
|
11
11
|
static first(initialList, fallback) {
|
|
@@ -68,8 +68,13 @@ var ArrayUtil = class {
|
|
|
68
68
|
* @returns 差集数组
|
|
69
69
|
* @example
|
|
70
70
|
* ```ts
|
|
71
|
+
* // 重载 1: 按元素本身比较(自动去重)
|
|
71
72
|
* ArrayUtil.difference([1, 2, 3], [2, 3, 4]); // [1]
|
|
73
|
+
* ArrayUtil.difference([1, 1, 2], [2]); // [1],重复项会被去重
|
|
74
|
+
*
|
|
75
|
+
* // 重载 2: 按 match 结果比较(不去重,保留 initialList 原始重复项与顺序)
|
|
72
76
|
* ArrayUtil.difference([{ id: 1 }, { id: 2 }], [{ id: 2 }], (x) => x.id); // [{ id: 1 }]
|
|
77
|
+
* ArrayUtil.difference([{ id: 1 }, { id: 1 }], [{ id: 2 }], (x) => x.id); // [{ id: 1 }, { id: 1 }]
|
|
73
78
|
* ```
|
|
74
79
|
*/
|
|
75
80
|
static difference(initialList, diffList, match) {
|
|
@@ -138,6 +143,7 @@ var ArrayUtil = class {
|
|
|
138
143
|
* - 在给定的数组中,替换并移动符合匹配函数结果的项目
|
|
139
144
|
* - 只替换和移动第一个匹配项
|
|
140
145
|
* - 未匹配时,根据 `position` 在指定位置插入 `newItem`
|
|
146
|
+
* - ⚠️ `position` 为负数或非正整数(如 `-1`、`2.5`)时不生效,静默回退为 `push`(追加到末尾)
|
|
141
147
|
*
|
|
142
148
|
* @param initialList 初始数组
|
|
143
149
|
* @param newItem 替换项
|
|
@@ -150,6 +156,9 @@ var ArrayUtil = class {
|
|
|
150
156
|
* ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, 2); // [1, 3, 5, 4]
|
|
151
157
|
* ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, "start"); // [5, 1, 3, 4]
|
|
152
158
|
* ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2); // [1, 3, 4, 5]
|
|
159
|
+
*
|
|
160
|
+
* // position 为负数 → 静默回退为 push
|
|
161
|
+
* ArrayUtil.replaceMove([1, 2, 3, 4], 5, (n) => n === 2, -1); // [1, 3, 4, 5]
|
|
153
162
|
* ```
|
|
154
163
|
*/
|
|
155
164
|
static replaceMove(initialList, newItem, match, position) {
|
|
@@ -206,31 +215,48 @@ var ArrayUtil = class {
|
|
|
206
215
|
/**
|
|
207
216
|
* 数组解压
|
|
208
217
|
* - `ArrayUtil.zip` 的反向操作
|
|
218
|
+
* - 默认按最长数组补齐 `undefined`
|
|
209
219
|
*
|
|
210
220
|
* @param arrayList 压缩后的数组
|
|
221
|
+
* @param options 配置项(`truncate` 为 `true` 时按最短数组截断)
|
|
211
222
|
* @returns 解压后的二维数组
|
|
212
223
|
* @example
|
|
213
224
|
* ```ts
|
|
214
225
|
* ArrayUtil.unzip([[1, "a"], [2, "b"]]); // [[1, 2], ["a", "b"]]
|
|
226
|
+
*
|
|
227
|
+
* // 补齐语义
|
|
228
|
+
* ArrayUtil.unzip([[1, 2], [3]]); // [[1, 3], [2, undefined]]
|
|
229
|
+
*
|
|
230
|
+
* // 截断语义
|
|
231
|
+
* ArrayUtil.unzip([[1, 2], [3]], { truncate: true }); // [[1, 3]]
|
|
215
232
|
* ```
|
|
216
233
|
*/
|
|
217
|
-
static unzip(arrayList) {
|
|
234
|
+
static unzip(arrayList, options) {
|
|
218
235
|
if (!TypeUtil.isArray(arrayList) || !arrayList.length) return [];
|
|
219
|
-
const
|
|
236
|
+
const length = options?.truncate ? arrayList.reduce((min, arr) => Math.min(min, arr.length), Infinity) : arrayList.reduce((max, arr) => Math.max(max, arr.length), 0);
|
|
237
|
+
const out = new Array(length);
|
|
220
238
|
let index = 0;
|
|
221
239
|
const get = (array) => array[index];
|
|
222
240
|
for (; index < out.length; index++) out[index] = Array.from(arrayList, get);
|
|
223
241
|
return out;
|
|
224
242
|
}
|
|
225
|
-
static zip(...
|
|
226
|
-
|
|
243
|
+
static zip(...arraysAndOptions) {
|
|
244
|
+
const last = arraysAndOptions[arraysAndOptions.length - 1];
|
|
245
|
+
const options = last && !TypeUtil.isArray(last) ? last : void 0;
|
|
246
|
+
const arrays = options ? arraysAndOptions.slice(0, -1) : arraysAndOptions;
|
|
247
|
+
return this.unzip(arrays, options);
|
|
227
248
|
}
|
|
228
249
|
static zipToObject(keys, values) {
|
|
229
250
|
const result = {};
|
|
230
251
|
if (!TypeUtil.isArray(keys) || !keys.length) return result;
|
|
231
252
|
const getValue = TypeUtil.isFunction(values) ? values : TypeUtil.isArray(values) ? (_k, i) => values[i] : (_k, _i) => values;
|
|
232
253
|
return keys.reduce((acc, key, idx) => {
|
|
233
|
-
acc
|
|
254
|
+
Object.defineProperty(acc, key, {
|
|
255
|
+
value: getValue(key, idx),
|
|
256
|
+
enumerable: true,
|
|
257
|
+
writable: true,
|
|
258
|
+
configurable: true
|
|
259
|
+
});
|
|
234
260
|
return acc;
|
|
235
261
|
}, result);
|
|
236
262
|
}
|
|
@@ -361,17 +387,19 @@ var CurrencyUtil = class {
|
|
|
361
387
|
XPF: "fr-PF"
|
|
362
388
|
};
|
|
363
389
|
static currencyFormatter(value, options) {
|
|
364
|
-
if (TypeUtil.
|
|
390
|
+
if (TypeUtil.isNullish(value)) return null;
|
|
365
391
|
const { currencySign, currencySignPosition, locales, currencyFormatOptions } = options;
|
|
366
|
-
|
|
392
|
+
const numberValue = Number(value);
|
|
393
|
+
if (Number.isNaN(numberValue)) return null;
|
|
394
|
+
let formatedValue = numberValue.toLocaleString(locales, currencyFormatOptions).replace(currencySign, "").trim();
|
|
367
395
|
if (currencySignPosition === "start") formatedValue = `${currencySign} ${formatedValue}`;
|
|
368
396
|
if (currencySignPosition === "end") formatedValue = `${formatedValue} ${currencySign}`;
|
|
369
397
|
return formatedValue;
|
|
370
398
|
}
|
|
371
399
|
static toRealValue(mathJsInstance, value, precision, stringMode) {
|
|
372
|
-
if (TypeUtil.
|
|
400
|
+
if (TypeUtil.isNullish(value)) return null;
|
|
373
401
|
const precisionValue = MathUtil.toDecimal(mathJsInstance, value, precision);
|
|
374
|
-
return stringMode ? precisionValue :
|
|
402
|
+
return stringMode === false ? Number(precisionValue) : precisionValue;
|
|
375
403
|
}
|
|
376
404
|
};
|
|
377
405
|
//#endregion
|
|
@@ -528,9 +556,13 @@ var DateTimeUtil = class {
|
|
|
528
556
|
* ```
|
|
529
557
|
*/
|
|
530
558
|
static getTimeZone() {
|
|
531
|
-
const
|
|
559
|
+
const offsetMinutes = 0 - (/* @__PURE__ */ new Date()).getTimezoneOffset();
|
|
560
|
+
const sign = offsetMinutes >= 0 ? "+" : "-";
|
|
561
|
+
const absMinutes = Math.abs(offsetMinutes);
|
|
562
|
+
const hours = Math.floor(absMinutes / this.MINUTE_PER_HOUR);
|
|
563
|
+
const minutes = absMinutes % this.MINUTE_PER_HOUR;
|
|
532
564
|
return {
|
|
533
|
-
UTC:
|
|
565
|
+
UTC: `UTC${sign}${hours}${minutes ? `:${String(minutes).padStart(2, "0")}` : ""}`,
|
|
534
566
|
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
535
567
|
};
|
|
536
568
|
}
|
|
@@ -539,6 +571,8 @@ var DateTimeUtil = class {
|
|
|
539
571
|
//#region src/env/envUtil.ts
|
|
540
572
|
/**
|
|
541
573
|
* 环境检查工具类
|
|
574
|
+
* - ⚠️ `isBrowser` / `isWebWorker` / `isReactNative` 基于静态字段判定,在**模块加载时**求值一次。
|
|
575
|
+
* SSR 场景下若在 Node 端 import(此时 `window` 未定义),结果会永久为 `false`,不会随运行时环境变化重算。
|
|
542
576
|
*/
|
|
543
577
|
var EnvUtil = class {
|
|
544
578
|
static _isBrowser = typeof window !== "undefined" && TypeUtil.isFunction(window?.document?.createElement);
|
|
@@ -711,6 +745,7 @@ var EnvUtil = class {
|
|
|
711
745
|
* @param maxWidth - 平板最大宽度(默认 1200px)
|
|
712
746
|
* @param dpi - 标准 DPI 基准(默认 160)
|
|
713
747
|
* @returns 是否为平板设备
|
|
748
|
+
* - 宽度命中 `[minWidth, maxWidth]` 区间,或 CSS/DPI 折算尺寸落在 `[7, 13)` 英寸(排除 DPR=1 的 1920×1080 桌面)
|
|
714
749
|
* @example
|
|
715
750
|
* ```ts
|
|
716
751
|
* // 假设 window.innerWidth = 1000
|
|
@@ -728,7 +763,7 @@ var EnvUtil = class {
|
|
|
728
763
|
const widthInch = widthPx / DPI;
|
|
729
764
|
const heightInch = heightPx / DPI;
|
|
730
765
|
const screenInches = Math.sqrt(widthInch ** 2 + heightInch ** 2);
|
|
731
|
-
return isWithinWidthRange || screenInches >= 7;
|
|
766
|
+
return isWithinWidthRange || screenInches >= 7 && screenInches < 13;
|
|
732
767
|
} catch {
|
|
733
768
|
return isWithinWidthRange;
|
|
734
769
|
}
|
|
@@ -766,7 +801,10 @@ var FunctionUtil = class {
|
|
|
766
801
|
Object.getOwnPropertyNames(err).forEach((key) => {
|
|
767
802
|
if (!(key in parsedError)) parsedError[key] = err[key];
|
|
768
803
|
});
|
|
769
|
-
} else
|
|
804
|
+
} else {
|
|
805
|
+
Object.assign(parsedError, err);
|
|
806
|
+
if (!parsedError.message) parsedError.message = String(err);
|
|
807
|
+
}
|
|
770
808
|
Object.assign(parsedError, errorExt);
|
|
771
809
|
return [parsedError, void 0];
|
|
772
810
|
}
|
|
@@ -1294,7 +1332,12 @@ var ObjectUtil = class {
|
|
|
1294
1332
|
if (!TypeUtil.isPlainObject(plainObject)) return defaultResult;
|
|
1295
1333
|
return this.entries(plainObject).reduce((acc, [key, value]) => {
|
|
1296
1334
|
const [newKey, newValue] = toEntry(key, value);
|
|
1297
|
-
acc
|
|
1335
|
+
Object.defineProperty(acc, newKey, {
|
|
1336
|
+
value: newValue,
|
|
1337
|
+
enumerable: true,
|
|
1338
|
+
writable: true,
|
|
1339
|
+
configurable: true
|
|
1340
|
+
});
|
|
1298
1341
|
return acc;
|
|
1299
1342
|
}, defaultResult);
|
|
1300
1343
|
}
|
|
@@ -1303,7 +1346,12 @@ var ObjectUtil = class {
|
|
|
1303
1346
|
if (!TypeUtil.isPlainObject(obj)) return result;
|
|
1304
1347
|
if (!TypeUtil.isArray(keys)) return obj;
|
|
1305
1348
|
return keys.reduce((acc, key) => {
|
|
1306
|
-
if (key in obj) acc
|
|
1349
|
+
if (key in obj) Object.defineProperty(acc, key, {
|
|
1350
|
+
value: obj[key],
|
|
1351
|
+
enumerable: true,
|
|
1352
|
+
writable: true,
|
|
1353
|
+
configurable: true
|
|
1354
|
+
});
|
|
1307
1355
|
return acc;
|
|
1308
1356
|
}, result);
|
|
1309
1357
|
}
|
|
@@ -1313,7 +1361,12 @@ var ObjectUtil = class {
|
|
|
1313
1361
|
if (!TypeUtil.isArray(keys)) return obj;
|
|
1314
1362
|
const keysToOmit = new Set(keys);
|
|
1315
1363
|
return Object.keys(obj).reduce((acc, key) => {
|
|
1316
|
-
if (!keysToOmit.has(key)) acc
|
|
1364
|
+
if (!keysToOmit.has(key)) Object.defineProperty(acc, key, {
|
|
1365
|
+
value: obj[key],
|
|
1366
|
+
enumerable: true,
|
|
1367
|
+
writable: true,
|
|
1368
|
+
configurable: true
|
|
1369
|
+
});
|
|
1317
1370
|
return acc;
|
|
1318
1371
|
}, result);
|
|
1319
1372
|
}
|
|
@@ -1427,7 +1480,7 @@ function postImpl$3(row, callback, options) {
|
|
|
1427
1480
|
parents: [...options.parents, row],
|
|
1428
1481
|
depth: options.depth + 1
|
|
1429
1482
|
};
|
|
1430
|
-
newChildren = children.map((c) =>
|
|
1483
|
+
newChildren = children.map((c) => postImpl$3(c, callback, nextLevelOptions)).filter((c) => !!c);
|
|
1431
1484
|
}
|
|
1432
1485
|
if (!callback(row, options)) return;
|
|
1433
1486
|
return {
|
|
@@ -1692,47 +1745,68 @@ const treeMapStrategies = {
|
|
|
1692
1745
|
//#region src/tree/treeUtil.ts
|
|
1693
1746
|
/**
|
|
1694
1747
|
* 树结构工具类
|
|
1748
|
+
*
|
|
1749
|
+
* 引用策略约定:
|
|
1750
|
+
* - 转换类方法(`rowsToTree` / `treeToRows` / `filter` / `map`):不突变输入;输出的每个节点均为**新对象引用**(来源节点的浅拷贝,仅自有可枚举属性;非枚举属性、原型链、getter 及深层嵌套对象不保证)。
|
|
1751
|
+
* - 查询类方法(`find` / `forEach`):按查询语义直接使用**原对象引用**。
|
|
1695
1752
|
*/
|
|
1696
1753
|
var TreeUtil = class {
|
|
1697
1754
|
/**
|
|
1698
1755
|
* 行结构 转 树结构
|
|
1699
1756
|
* - 将平铺的数组转换为树形结构
|
|
1757
|
+
* - 返回的树结构与输入行无共享节点(新对象引用),输入行不会被突变
|
|
1758
|
+
* - 重复 id 的行只取首次出现;仅叶子/缺失父节点的 id 会作为根节点,且每个根节点只输出一次
|
|
1700
1759
|
*
|
|
1701
1760
|
* @param rows 行数据数组
|
|
1702
1761
|
* @param options 配置项
|
|
1703
|
-
* @returns
|
|
1762
|
+
* @returns 树结构数组(所有节点均包含 children 数组)
|
|
1704
1763
|
* @example
|
|
1705
1764
|
* ```ts
|
|
1706
1765
|
* const rows = [
|
|
1707
1766
|
* { id: 1, parentId: null },
|
|
1708
1767
|
* { id: 2, parentId: 1 },
|
|
1709
1768
|
* ];
|
|
1710
|
-
* TreeUtil.rowsToTree(rows); // [{ id: 1, parentId: null, children: [{ id: 2, parentId: 1 }] }]
|
|
1769
|
+
* TreeUtil.rowsToTree(rows); // [{ id: 1, parentId: null, children: [{ id: 2, parentId: 1, children: [] }] }]
|
|
1711
1770
|
* ```
|
|
1712
1771
|
*/
|
|
1713
1772
|
static rowsToTree(rows, options) {
|
|
1714
1773
|
const { parentIdKey = "parentId", rowKey = "id", childrenKey = "children" } = options || {};
|
|
1715
1774
|
const result = [];
|
|
1716
1775
|
const map = /* @__PURE__ */ new Map();
|
|
1776
|
+
const processedIds = /* @__PURE__ */ new Set();
|
|
1717
1777
|
for (const row of rows) {
|
|
1718
1778
|
const id = row[rowKey];
|
|
1719
|
-
if (!map.get(id)) map.set(id, row);
|
|
1779
|
+
if (!map.get(id)) map.set(id, { ...row });
|
|
1720
1780
|
}
|
|
1721
1781
|
for (const row of rows) {
|
|
1782
|
+
const id = row[rowKey];
|
|
1783
|
+
if (processedIds.has(id)) continue;
|
|
1784
|
+
processedIds.add(id);
|
|
1722
1785
|
const parentId = row[parentIdKey];
|
|
1723
|
-
const
|
|
1724
|
-
if (!
|
|
1725
|
-
|
|
1786
|
+
const node = map.get(id);
|
|
1787
|
+
if (!node) continue;
|
|
1788
|
+
if (TypeUtil.isNullish(parentId) || parentId === id || !map.has(parentId)) {
|
|
1789
|
+
result.push(node);
|
|
1726
1790
|
continue;
|
|
1727
1791
|
}
|
|
1792
|
+
const parent = map.get(parentId);
|
|
1728
1793
|
const siblings = parent[childrenKey];
|
|
1729
|
-
if (TypeUtil.
|
|
1730
|
-
else if (Array.isArray(siblings)) siblings.push(
|
|
1794
|
+
if (TypeUtil.isNullish(siblings)) parent[childrenKey] = [node];
|
|
1795
|
+
else if (Array.isArray(siblings)) siblings.push(node);
|
|
1731
1796
|
else {
|
|
1732
1797
|
const message = `The key "${childrenKey.toString()}" in parent item is not an array.`;
|
|
1733
1798
|
throw new Error(message);
|
|
1734
1799
|
}
|
|
1735
1800
|
}
|
|
1801
|
+
for (const root of result) this.forEach(root, (node) => {
|
|
1802
|
+
const record = node;
|
|
1803
|
+
const children = record[childrenKey];
|
|
1804
|
+
if (TypeUtil.isNullish(children)) record[childrenKey] = [];
|
|
1805
|
+
else if (!Array.isArray(children)) {
|
|
1806
|
+
const message = `The key "${childrenKey.toString()}" in parent item is not an array.`;
|
|
1807
|
+
throw new Error(message);
|
|
1808
|
+
}
|
|
1809
|
+
}, { childrenKey });
|
|
1736
1810
|
return result;
|
|
1737
1811
|
}
|
|
1738
1812
|
/**
|
|
@@ -1923,25 +1997,37 @@ var ValidateUtil = class {
|
|
|
1923
1997
|
}
|
|
1924
1998
|
static _uscc = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
|
|
1925
1999
|
/**
|
|
1926
|
-
*
|
|
2000
|
+
* 验证是否为统一社会信用代码(USCC / USCI / USCCS)
|
|
2001
|
+
* - 固定 18 位:1 位登记管理部门码 + 1 位机构类别码 + 6 位行政区划码 + 9 位主体标识码 + 1 位校验码
|
|
2002
|
+
* - 字符集:数字 0-9 + 大写英文字母(排除 I、O、Z、S、V,防视觉混淆)
|
|
2003
|
+
* - 第 1-2 位允许字母(如登记管理部门码 `A`,代表"其他"),第 3-8 位行政区划码为纯数字
|
|
2004
|
+
*
|
|
2005
|
+
* @param input 待校验字符串
|
|
2006
|
+
* @returns 是否为合法格式的统一社会信用代码
|
|
1927
2007
|
* @example
|
|
1928
2008
|
* ```ts
|
|
1929
2009
|
* ValidateUtil.isUSCC("91350100M000100Y43"); // true
|
|
2010
|
+
* ValidateUtil.isUSCC("A1350100M000100Y43"); // true (A 开头"其他"部门码)
|
|
1930
2011
|
* ```
|
|
1931
2012
|
*/
|
|
1932
2013
|
static isUSCC(input) {
|
|
1933
2014
|
return this._uscc.test(input.toString());
|
|
1934
2015
|
}
|
|
1935
|
-
static _usccs = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
|
|
1936
2016
|
/**
|
|
1937
|
-
*
|
|
2017
|
+
* 验证是否为统一社会信用代码(同 `isUSCC`)
|
|
2018
|
+
* - USCC / USCI / USCCS 均指统一社会信用代码,固定 18 位
|
|
2019
|
+
* - 15 位旧税务登记号在 2015 年"三证合一"前使用,现已作废,视为无效
|
|
2020
|
+
*
|
|
2021
|
+
* @param input 待校验字符串
|
|
2022
|
+
* @returns 是否为合法代码
|
|
1938
2023
|
* @example
|
|
1939
2024
|
* ```ts
|
|
1940
|
-
* ValidateUtil.isUSCCS("91350100M000100Y43"); // true
|
|
2025
|
+
* ValidateUtil.isUSCCS("91350100M000100Y43"); // true (18位)
|
|
2026
|
+
* ValidateUtil.isUSCCS("91350100M000100"); // false (15位旧号,已作废)
|
|
1941
2027
|
* ```
|
|
1942
2028
|
*/
|
|
1943
2029
|
static isUSCCS(input) {
|
|
1944
|
-
return this.
|
|
2030
|
+
return this.isUSCC(input);
|
|
1945
2031
|
}
|
|
1946
2032
|
static _dirPathWindows = /^[a-z]:\\(?:\w+\\?)*$/i;
|
|
1947
2033
|
/**
|
|
@@ -2023,6 +2109,7 @@ var ValidateUtil = class {
|
|
|
2023
2109
|
static _chineseId = /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))([\dX])$/i;
|
|
2024
2110
|
/**
|
|
2025
2111
|
* 验证是否为中国身份证号
|
|
2112
|
+
* - ⚠️ 仅校验 18 位格式(含生日合法性),**不验证第 18 位校验位**,伪造码可通过校验
|
|
2026
2113
|
* @example
|
|
2027
2114
|
* ```ts
|
|
2028
2115
|
* ValidateUtil.isChineseID("11010519491231002X"); // true
|
|
@@ -2031,7 +2118,7 @@ var ValidateUtil = class {
|
|
|
2031
2118
|
static isChineseID(input) {
|
|
2032
2119
|
return this._chineseId.test(input.toString());
|
|
2033
2120
|
}
|
|
2034
|
-
static _chineseProvince =
|
|
2121
|
+
static _chineseProvince = /^(?:安徽|澳门|北京|重庆|福建|甘肃|广东|广西|贵州|海南|河北|河南|黑龙江|湖北|湖南|吉林|江苏|江西|辽宁|内蒙古|宁夏|青海|山东|山西|陕西|上海|四川|台湾|天津|西藏|香港|新疆|云南|浙江)$/;
|
|
2035
2122
|
/**
|
|
2036
2123
|
* 验证是否为中国省份
|
|
2037
2124
|
* @example
|
|
@@ -2042,7 +2129,7 @@ var ValidateUtil = class {
|
|
|
2042
2129
|
static isChineseProvince(input) {
|
|
2043
2130
|
return this._chineseProvince.test(input.toString());
|
|
2044
2131
|
}
|
|
2045
|
-
static _chineseNation =
|
|
2132
|
+
static _chineseNation = /^(?:汉族|蒙古族|回族|藏族|维吾尔族|苗族|彝族|壮族|布依族|朝鲜族|满族|侗族|瑶族|白族|土家族|哈尼族|哈萨克族|傣族|黎族|傈僳族|佤族|畲族|高山族|拉祜族|水族|东乡族|纳西族|景颇族|柯尔克孜族|土族|达斡尔族|仫佬族|羌族|布朗族|撒拉族|毛南族|仡佬族|锡伯族|阿昌族|普米族|塔吉克族|怒族|乌孜别克族|俄罗斯族|鄂温克族|德昂族|保安族|裕固族|京族|塔塔尔族|独龙族|鄂伦春族|赫哲族|门巴族|珞巴族|基诺族|其它未识别民族|外国人入中国籍)$/;
|
|
2046
2133
|
/**
|
|
2047
2134
|
* 验证是否为中华民族
|
|
2048
2135
|
* @example
|