@wener/utils 1.1.39 → 1.1.40
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/lib/asyncs/createAsyncIterator.js.map +1 -1
- package/lib/asyncs/createLazyPromise.js.map +1 -1
- package/lib/asyncs/firstOfAsyncIterator.js.map +1 -1
- package/lib/asyncs/nextOfAsyncIterator.js.map +1 -1
- package/lib/cn/division/DivisionCode.js +35 -43
- package/lib/cn/division/DivisionCode.js.map +1 -1
- package/lib/cn/division/binarySearch.js +27 -0
- package/lib/cn/division/binarySearch.js.map +1 -0
- package/lib/cn/id/ResidentIdNumber.js +25 -14
- package/lib/cn/id/ResidentIdNumber.js.map +1 -1
- package/lib/cn/index.js +1 -0
- package/lib/cn/index.js.map +1 -1
- package/lib/cn/pinyin/cartesianProduct.js +22 -0
- package/lib/cn/pinyin/cartesianProduct.js.map +1 -0
- package/lib/cn/pinyin/data.json +413 -0
- package/lib/cn/pinyin/toPinyinPure.js +39 -0
- package/lib/cn/pinyin/toPinyinPure.js.map +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/langs/mixin.js +22 -0
- package/lib/langs/mixin.js.map +1 -0
- package/lib/logging/createChildLogger.js.map +1 -1
- package/lib/objects/get.js.map +1 -1
- package/lib/objects/set.js.map +1 -1
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-model.js +1 -1
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-model.js.map +1 -1
- package/lib/scripts/getGenerateContext.js +86 -0
- package/lib/scripts/getGenerateContext.js.map +1 -0
- package/lib/types.d.js.map +1 -1
- package/package.json +2 -1
- package/src/asyncs/createAsyncIterator.ts +1 -1
- package/src/asyncs/createLazyPromise.ts +1 -1
- package/src/asyncs/firstOfAsyncIterator.ts +1 -1
- package/src/asyncs/nextOfAsyncIterator.ts +1 -1
- package/src/cn/division/DivisionCode.ts +37 -44
- package/src/cn/division/binarySearch.test.ts +64 -0
- package/src/cn/division/binarySearch.ts +25 -0
- package/src/cn/id/ResidentIdNumber.ts +38 -12
- package/src/cn/id/id.test.ts +1 -1
- package/src/cn/index.ts +2 -0
- package/src/cn/pinyin/cartesianProduct.test.ts +64 -0
- package/src/cn/pinyin/cartesianProduct.ts +24 -0
- package/src/cn/pinyin/data.json +413 -0
- package/src/cn/pinyin/toPinyin.test.ts +10 -0
- package/src/cn/pinyin/toPinyinPure.ts +52 -0
- package/src/cn/scripts/gen.test.ts +130 -0
- package/src/cn/uscc/uscc.test.ts +2 -2
- package/src/index.ts +3 -0
- package/src/io/ArrayBuffers.base64.test.ts +1 -1
- package/src/io/ArrayBuffers.test.ts +1 -1
- package/src/io/Buffer.test.ts +1 -1
- package/src/langs/README.md +4 -0
- package/src/langs/mixin.ts +82 -0
- package/src/logging/createChildLogger.ts +1 -1
- package/src/logging/logger.test.ts +1 -1
- package/src/modules/parseModuleId.test.ts +1 -1
- package/src/objects/get.ts +1 -2
- package/src/objects/parseObjectPath.test.ts +1 -1
- package/src/objects/set.test.ts +1 -1
- package/src/objects/set.ts +1 -2
- package/src/schema/typebox/gen/codegen/typescript/typescript-to-model.ts +1 -1
- package/src/scripts/getGenerateContext.ts +97 -0
- package/src/server/polyfill/polyfillBrowser.test.ts +1 -1
- package/src/types.d.ts +2 -2
- package/lib/langs/hashCode.ignored.js +0 -112
- package/lib/langs/hashCode.ignored.js.map +0 -1
- package/src/langs/hashCode.ignored.ts +0 -125
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
function sortObjectKeys(obj?: Record<string, any>) {
|
|
2
|
-
if (obj === null || obj === undefined) {
|
|
3
|
-
return obj;
|
|
4
|
-
}
|
|
5
|
-
if (typeof obj !== 'object') {
|
|
6
|
-
// it is a primitive: number/string (in an array)
|
|
7
|
-
return obj;
|
|
8
|
-
}
|
|
9
|
-
return Object.keys(obj)
|
|
10
|
-
.sort()
|
|
11
|
-
.reduce(
|
|
12
|
-
(acc, key) => {
|
|
13
|
-
if (Array.isArray(obj[key])) {
|
|
14
|
-
acc[key] = obj[key].map(sortObjectKeys);
|
|
15
|
-
} else if (typeof obj[key] === 'object') {
|
|
16
|
-
acc[key] = sortObjectKeys(obj[key]);
|
|
17
|
-
} else {
|
|
18
|
-
acc[key] = obj[key];
|
|
19
|
-
}
|
|
20
|
-
return acc;
|
|
21
|
-
},
|
|
22
|
-
{} as Record<string, any>,
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function toDeterministicJson(o: any) {
|
|
27
|
-
// https://github.com/kikobeats/json-stringify-deterministic
|
|
28
|
-
// https://stackoverflow.com/a/54902696/1870054
|
|
29
|
-
// https://github.com/sinclairzx81/typebox#hash
|
|
30
|
-
// https://github.com/sinclairzx81/typebox/blob/master/src/value/hash.ts
|
|
31
|
-
// LCS longest common subsequence
|
|
32
|
-
// https://github.com/sinclairzx81/typebox/issues/272
|
|
33
|
-
let sorted: any = sortObjectKeys(o);
|
|
34
|
-
let out = JSON.stringify(sorted, function (_, v) {
|
|
35
|
-
return v === undefined ? 'undef' : v;
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// Remove all whitespace
|
|
39
|
-
return out.replace(/\s+/g, '');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface Visitor<C> {
|
|
43
|
-
array: (o: any[], ctx: C) => any;
|
|
44
|
-
object: (o: Record<string, any>, ctx: C) => any;
|
|
45
|
-
boolean: (o: boolean, ctx: C) => any;
|
|
46
|
-
number: (o: number, ctx: C) => any;
|
|
47
|
-
string: (o: string, ctx: C) => any;
|
|
48
|
-
symbol: (o: symbol, ctx: C) => any;
|
|
49
|
-
bigint: (o: bigint, ctx: C) => any;
|
|
50
|
-
date: (o: Date, ctx: C) => any;
|
|
51
|
-
buffer: (o: ArrayBuffer, ctx: C) => any;
|
|
52
|
-
null: (o: null, ctx: C) => any;
|
|
53
|
-
undefined: (o: undefined, ctx: C) => any;
|
|
54
|
-
unknown: (o: unknown, ctx: C) => any;
|
|
55
|
-
visit: (o: any, ctx: C) => any;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function visit<C>(o: any, _v: Partial<Visitor<C>>, ctx: C) {
|
|
59
|
-
const v = {
|
|
60
|
-
array: (o: any[], ctx: C): any => o.map((x) => v.visit(x, ctx)),
|
|
61
|
-
object: (o: Record<string, any>, ctx: C) => {
|
|
62
|
-
return Object.fromEntries(Object.entries(o).map(([k, v]) => [k, v.visit(v, ctx)]));
|
|
63
|
-
},
|
|
64
|
-
buffer: (o: ArrayBuffer) => {
|
|
65
|
-
return o;
|
|
66
|
-
},
|
|
67
|
-
boolean: (o: boolean) => o,
|
|
68
|
-
number: (o: number) => o,
|
|
69
|
-
string: (o: string) => o,
|
|
70
|
-
symbol: (o: symbol) => o,
|
|
71
|
-
bigint: (o: bigint) => o,
|
|
72
|
-
date: (o: Date) => o,
|
|
73
|
-
null: (o: null) => o,
|
|
74
|
-
undefined: (o: undefined) => o,
|
|
75
|
-
unknown: (o: unknown, ctx: C): any => {
|
|
76
|
-
if (o instanceof Map) {
|
|
77
|
-
return new Map([...o.entries()].map(([k, v]) => [k, v.visit(v, ctx)]));
|
|
78
|
-
}
|
|
79
|
-
if (o instanceof Set) {
|
|
80
|
-
return new Set([...o.values()].map((v) => v.visit(v, ctx)));
|
|
81
|
-
}
|
|
82
|
-
return o;
|
|
83
|
-
},
|
|
84
|
-
visit: (o: any, ctx: C): any => {
|
|
85
|
-
if (o === null) {
|
|
86
|
-
return v.null(o, ctx);
|
|
87
|
-
}
|
|
88
|
-
switch (typeof o) {
|
|
89
|
-
case 'object':
|
|
90
|
-
if (o instanceof ArrayBuffer) {
|
|
91
|
-
return v.buffer(o, ctx);
|
|
92
|
-
}
|
|
93
|
-
if (Array.isArray(o)) {
|
|
94
|
-
return v.array(o, ctx);
|
|
95
|
-
}
|
|
96
|
-
if (o instanceof Date) {
|
|
97
|
-
return v.date(o, ctx);
|
|
98
|
-
}
|
|
99
|
-
// plain object
|
|
100
|
-
if (o.constructor === Object) {
|
|
101
|
-
return v.object(o, ctx);
|
|
102
|
-
}
|
|
103
|
-
//
|
|
104
|
-
return v.unknown(o, ctx);
|
|
105
|
-
case 'boolean':
|
|
106
|
-
return v.boolean(o, ctx);
|
|
107
|
-
case 'number':
|
|
108
|
-
return v.number(o, ctx);
|
|
109
|
-
case 'string':
|
|
110
|
-
return v.string(o, ctx);
|
|
111
|
-
case 'symbol':
|
|
112
|
-
return v.symbol(o, ctx);
|
|
113
|
-
case 'bigint':
|
|
114
|
-
return v.bigint(o, ctx);
|
|
115
|
-
case 'undefined':
|
|
116
|
-
return v.undefined(o, ctx);
|
|
117
|
-
default:
|
|
118
|
-
return v.unknown(o, ctx);
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
..._v,
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
return v.visit(o, ctx);
|
|
125
|
-
}
|