@wener/common 2.0.1 → 2.0.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/lib/cn/ChineseResidentIdNo.js +41 -0
- package/lib/cn/ChineseResidentIdNo.mod.js +1 -0
- package/lib/cn/{ResidentIdentityCardNumber.test.js → ChineseResidentIdNo.test.js} +7 -6
- package/lib/cn/DivisionCode.js +211 -300
- package/lib/cn/DivisionCode.mod.js +1 -0
- package/lib/cn/DivisionCode.test.js +9 -15
- package/lib/cn/{Mod11Checksum.js → Mod11.js} +1 -0
- package/lib/cn/{Mod31Checksum.js → Mod31.js} +1 -0
- package/lib/cn/UnifiedSocialCreditCode.js +130 -115
- package/lib/cn/UnifiedSocialCreditCode.mod.js +1 -0
- package/lib/cn/UnifiedSocialCreditCode.test.js +1 -1
- package/lib/cn/index.js +1 -3
- package/lib/cn/mod.js +6 -0
- package/lib/consola/formatLogObject.js +18 -6
- package/lib/dayjs/dayjs.js +38 -0
- package/lib/dayjs/formatDuration.js +58 -0
- package/lib/dayjs/formatDuration.test.js +90 -0
- package/lib/dayjs/index.js +3 -0
- package/lib/dayjs/parseDuration.js +32 -0
- package/lib/decimal/index.js +1 -0
- package/lib/decimal/parseDecimal.js +13 -0
- package/lib/{resource → foundation}/schema/SexType.js +5 -1
- package/lib/foundation/schema/index.js +1 -0
- package/lib/foundation/schema/parseSexType.js +18 -0
- package/lib/foundation/schema/types.js +5 -0
- package/lib/password/Password.js +10 -7
- package/lib/resource/ListQuery.js +119 -0
- package/lib/resource/index.js +1 -0
- package/lib/resource/schema/AnyResourceSchema.js +1 -1
- package/lib/resource/schema/index.js +5 -0
- package/lib/{resource/schema → schema}/SchemaRegistry.js +12 -5
- package/lib/schema/SchemaRegistry.mod.js +2 -0
- package/lib/schema/createSchemaData.js +1 -1
- package/lib/schema/getSchemaOptions.js +2 -2
- package/lib/schema/index.js +1 -0
- package/lib/utils/getEstimateProcessTime.js +20 -0
- package/lib/utils/index.js +1 -0
- package/package.json +23 -14
- package/src/cn/ChineseResidentIdNo.mod.ts +7 -0
- package/src/cn/ChineseResidentIdNo.test.ts +18 -0
- package/src/cn/ChineseResidentIdNo.ts +66 -0
- package/src/cn/DivisionCode.mod.ts +7 -0
- package/src/cn/DivisionCode.test.ts +3 -13
- package/src/cn/DivisionCode.ts +132 -195
- package/src/cn/{Mod11Checksum.ts → Mod11.ts} +3 -1
- package/src/cn/{Mod31Checksum.ts → Mod31.ts} +2 -0
- package/src/cn/UnifiedSocialCreditCode.mod.ts +7 -0
- package/src/cn/UnifiedSocialCreditCode.test.ts +2 -2
- package/src/cn/UnifiedSocialCreditCode.ts +105 -125
- package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +14 -0
- package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +18 -12
- package/src/cn/index.ts +1 -3
- package/src/cn/mod.ts +3 -0
- package/src/consola/formatLogObject.ts +12 -4
- package/src/dayjs/dayjs.ts +40 -0
- package/src/dayjs/formatDuration.test.ts +14 -0
- package/src/dayjs/formatDuration.ts +86 -0
- package/src/dayjs/index.ts +3 -0
- package/src/dayjs/parseDuration.ts +40 -0
- package/src/decimal/index.ts +1 -0
- package/src/decimal/parseDecimal.ts +16 -0
- package/src/foundation/schema/SexType.ts +21 -0
- package/src/foundation/schema/index.ts +1 -0
- package/src/foundation/schema/parseSexType.ts +19 -0
- package/src/foundation/schema/types.ts +8 -0
- package/src/password/Password.ts +2 -2
- package/src/resource/ListQuery.ts +53 -0
- package/src/resource/index.ts +1 -0
- package/src/resource/schema/AnyResourceSchema.ts +1 -1
- package/src/resource/schema/index.ts +5 -0
- package/src/schema/SchemaRegistry.mod.ts +1 -0
- package/src/{resource/schema → schema}/SchemaRegistry.ts +12 -8
- package/src/schema/createSchemaData.ts +1 -1
- package/src/schema/getSchemaOptions.ts +2 -2
- package/src/schema/index.ts +1 -0
- package/src/utils/getEstimateProcessTime.ts +36 -0
- package/src/utils/index.ts +1 -0
- package/lib/cn/ResidentIdentityCardNumber.js +0 -50
- package/lib/cn/formatDate.js +0 -13
- package/lib/cn/parseSex.js +0 -20
- package/lib/search/AdvanceSearch.js +0 -9
- package/lib/search/AdvanceSearch.test.js +0 -435
- package/lib/search/formatAdvanceSearch.js +0 -78
- package/lib/search/index.js +0 -1
- package/lib/search/optimizeAdvanceSearch.js +0 -143
- package/lib/search/parseAdvanceSearch.js +0 -20
- package/lib/search/parser.d.js +0 -1
- package/lib/search/parser.js +0 -3088
- package/lib/search/types.d.js +0 -1
- package/src/cn/ResidentIdentityCardNumber.test.ts +0 -17
- package/src/cn/ResidentIdentityCardNumber.ts +0 -96
- package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +0 -15
- package/src/cn/formatDate.ts +0 -12
- package/src/cn/parseSex.ts +0 -13
- package/src/resource/schema/SexType.ts +0 -13
- package/src/search/AdvanceSearch.test.ts +0 -149
- package/src/search/AdvanceSearch.ts +0 -14
- package/src/search/Makefile +0 -2
- package/src/search/__snapshots__/AdvanceSearch.test.ts.snap +0 -675
- package/src/search/formatAdvanceSearch.ts +0 -52
- package/src/search/index.ts +0 -1
- package/src/search/optimizeAdvanceSearch.ts +0 -77
- package/src/search/parseAdvanceSearch.ts +0 -23
- package/src/search/parser.d.ts +0 -8
- package/src/search/parser.js +0 -2794
- package/src/search/parser.peggy +0 -237
- package/src/search/types.d.ts +0 -45
|
@@ -1,124 +1,139 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
import { Mod31 } from "./Mod31.js";
|
|
3
|
+
var CodeNames = {
|
|
4
|
+
1: {
|
|
5
|
+
name: "\u673A\u6784\u7F16\u5236",
|
|
6
|
+
children: {
|
|
7
|
+
1: {
|
|
8
|
+
name: "\u673A\u5173"
|
|
9
|
+
},
|
|
10
|
+
2: {
|
|
11
|
+
name: "\u4E8B\u4E1A\u5355\u4F4D"
|
|
12
|
+
},
|
|
13
|
+
3: {
|
|
14
|
+
name: "\u4E2D\u592E\u7F16\u529E\u76F4\u63A5\u7BA1\u7406\u673A\u6784\u7F16\u5236\u7684\u7FA4\u4F17\u56E2\u4F53"
|
|
15
|
+
},
|
|
16
|
+
9: {
|
|
17
|
+
name: "\u5176\u4ED6"
|
|
19
18
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
5: {
|
|
22
|
+
name: "\u6C11\u653F",
|
|
23
|
+
children: {
|
|
24
|
+
1: {
|
|
25
|
+
name: "\u793E\u4F1A\u56E2\u4F53"
|
|
26
|
+
},
|
|
27
|
+
2: {
|
|
28
|
+
name: "\u6C11\u529E\u975E\u4F01\u4E1A\u5355\u4F4D"
|
|
29
|
+
},
|
|
30
|
+
3: {
|
|
31
|
+
name: "\u57FA\u91D1\u4F1A"
|
|
32
|
+
},
|
|
33
|
+
9: {
|
|
34
|
+
name: "\u5176\u4ED6"
|
|
36
35
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
9: {
|
|
39
|
+
name: "\u5DE5\u5546",
|
|
40
|
+
children: {
|
|
41
|
+
1: {
|
|
42
|
+
name: "\u4F01\u4E1A"
|
|
43
|
+
},
|
|
44
|
+
2: {
|
|
45
|
+
name: "\u4E2A\u4F53\u5DE5\u5546\u6237"
|
|
46
|
+
},
|
|
47
|
+
3: {
|
|
48
|
+
name: "\u519C\u6C11\u4E13\u4E1A\u5408\u4F5C\u793E"
|
|
49
|
+
},
|
|
50
|
+
9: {
|
|
51
|
+
name: "\u5176\u4ED6"
|
|
53
52
|
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
Y: {
|
|
56
|
+
name: "\u5176\u4ED6",
|
|
57
|
+
children: {
|
|
58
|
+
1: {
|
|
59
|
+
name: "\u5176\u4ED6"
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
|
-
};
|
|
64
|
-
UnifiedSocialCreditCode.pattern = /^([159][1239]|Y1)[0-9]{6}[0-9A-HJ-NP-RTUWXY]{10}$/; // 无 I O Z S V
|
|
65
|
-
UnifiedSocialCreditCode.Checksum = new Mod31Checksum();
|
|
66
|
-
function parse(s) {
|
|
67
|
-
var _l1_children;
|
|
68
|
-
var bureau = s[0];
|
|
69
|
-
var subjectType = s[1];
|
|
70
|
-
var division = s.slice(2, 8); // 第3~8位,共6位,正确
|
|
71
|
-
var subject = s.slice(8, 17); // 第9~17位,共9位
|
|
72
|
-
var checksum = s.slice(17, 18); // 第18位,校验码
|
|
73
|
-
var labels = [];
|
|
74
|
-
var l1 = CodeLabels[bureau];
|
|
75
|
-
l1 && labels.push(l1 === null || l1 === void 0 ? void 0 : l1.label);
|
|
76
|
-
var l2 = l1 === null || l1 === void 0 ? void 0 : (_l1_children = l1.children) === null || _l1_children === void 0 ? void 0 : _l1_children[subjectType];
|
|
77
|
-
l2 && labels.push(l2 === null || l2 === void 0 ? void 0 : l2.label);
|
|
78
|
-
return {
|
|
79
|
-
bureau: bureau,
|
|
80
|
-
subjectType: subjectType,
|
|
81
|
-
division: division,
|
|
82
|
-
subject: subject,
|
|
83
|
-
checksum: checksum,
|
|
84
|
-
codes: [
|
|
85
|
-
bureau,
|
|
86
|
-
subjectType,
|
|
87
|
-
division,
|
|
88
|
-
subject
|
|
89
|
-
],
|
|
90
|
-
labels: labels
|
|
91
|
-
};
|
|
92
62
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
63
|
+
};
|
|
64
|
+
export var ParsedUnifiedSocialCreditCodeSchema = z.object({
|
|
65
|
+
raw: z.string().length(18).describe("\u7EDF\u4E00\u793E\u4F1A\u4FE1\u7528\u4EE3\u7801"),
|
|
66
|
+
registrationAuthorityCode: z.string().length(1).describe("\u767B\u8BB0\u7BA1\u7406\u90E8\u95E8\u4EE3\u7801"),
|
|
67
|
+
entityCategoryCode: z.string().length(1).describe("\u673A\u6784\u7C7B\u522B\u4EE3\u7801"),
|
|
68
|
+
adminDivisionCode: z.string().length(6).describe("\u767B\u8BB0\u7BA1\u7406\u673A\u5173\u884C\u653F\u533A\u5212\u7801 "),
|
|
69
|
+
organizationCode: z.string().length(9).describe("\u4E3B\u4F53\u6807\u8BC6\u7801/\u7EC4\u7EC7\u673A\u6784\u4EE3\u7801"),
|
|
70
|
+
checkDigit: z.string().length(1).describe("\u6821\u9A8C\u7801"),
|
|
71
|
+
codes: z.string().array().describe("\u4EE3\u7801\u6570\u7EC4"),
|
|
72
|
+
names: z.string().array().describe("\u4EE3\u7801\u540D\u79F0"),
|
|
73
|
+
valid: z.boolean().optional().describe("\u662F\u5426\u6709\u6548")
|
|
74
|
+
}).describe("\u7EDF\u4E00\u793E\u4F1A\u4FE1\u7528\u4EE3\u7801");
|
|
75
|
+
export var UnifiedSocialCreditCodeRegex = /^([159][1239]|Y1)[0-9]{6}[0-9A-HJ-NP-RTUWXY]{10}$/;
|
|
76
|
+
export function parseUnifiedSocialCreditCode(s) {
|
|
77
|
+
if (!s || s.length !== 18)
|
|
78
|
+
return undefined;
|
|
79
|
+
var registrationAuthorityCode = s[0];
|
|
80
|
+
var entityCategoryCode = s[1];
|
|
81
|
+
var adminDivisionCode = s.slice(2, 8);
|
|
82
|
+
var organizationCode = s.slice(8, 17);
|
|
83
|
+
var checkDigit = s[17];
|
|
84
|
+
var codes = [
|
|
85
|
+
registrationAuthorityCode,
|
|
86
|
+
entityCategoryCode,
|
|
87
|
+
adminDivisionCode,
|
|
88
|
+
organizationCode,
|
|
89
|
+
checkDigit
|
|
90
|
+
];
|
|
91
|
+
var names = [];
|
|
92
|
+
var bureau = CodeNames[registrationAuthorityCode];
|
|
93
|
+
if (bureau) {
|
|
94
|
+
var _bureau_children;
|
|
95
|
+
names.push(bureau.name);
|
|
96
|
+
var subject = (_bureau_children = bureau.children) === null || _bureau_children === void 0 ? void 0 : _bureau_children[entityCategoryCode];
|
|
97
|
+
if (subject) {
|
|
98
|
+
names.push(subject.name);
|
|
99
|
+
}
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
101
|
+
return {
|
|
102
|
+
raw: s,
|
|
103
|
+
registrationAuthorityCode: registrationAuthorityCode,
|
|
104
|
+
entityCategoryCode: entityCategoryCode,
|
|
105
|
+
adminDivisionCode: adminDivisionCode,
|
|
106
|
+
organizationCode: organizationCode,
|
|
107
|
+
checkDigit: checkDigit,
|
|
108
|
+
codes: codes,
|
|
109
|
+
names: names,
|
|
110
|
+
valid: UnifiedSocialCreditCodeRegex.test(s) && Mod31.validate(s)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export function formatUnifiedSocialCreditCode(param) {
|
|
114
|
+
var registrationAuthorityCode = param.registrationAuthorityCode, entityCategoryCode = param.entityCategoryCode, adminDivisionCode = param.adminDivisionCode, organizationCode = param.organizationCode, checkDigit = param.checkDigit;
|
|
115
|
+
var base = "".concat(registrationAuthorityCode).concat(entityCategoryCode).concat(adminDivisionCode).concat(organizationCode);
|
|
116
|
+
checkDigit || (checkDigit = Mod31.compute(base));
|
|
117
|
+
return "".concat(base).concat(checkDigit);
|
|
118
|
+
}
|
|
119
|
+
export function next(s) {
|
|
120
|
+
var delta = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
|
|
121
|
+
var sp = s.split("").map(function (v) {
|
|
122
|
+
return Mod31.numbers[v];
|
|
123
|
+
});
|
|
124
|
+
for (var i = sp.length - 1; i >= 0; i--) {
|
|
125
|
+
if (delta > 0 && sp[i] < 30 || delta < 0 && sp[i] > 0) {
|
|
126
|
+
sp[i] += delta;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
else if (delta > 0 && sp[i] === 30) {
|
|
130
|
+
sp[i] = 0;
|
|
131
|
+
}
|
|
132
|
+
else if (delta < 0 && sp[i] === 0) {
|
|
133
|
+
sp[i] = 30;
|
|
117
134
|
}
|
|
118
|
-
return sp.map(function (v) {
|
|
119
|
-
return UnifiedSocialCreditCode.Checksum.chars[v];
|
|
120
|
-
}).join("");
|
|
121
135
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
136
|
+
return sp.map(function (v) {
|
|
137
|
+
return Mod31.chars[v];
|
|
138
|
+
}).join("");
|
|
139
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { UnifiedSocialCreditCodeRegex as regex, ParsedUnifiedSocialCreditCodeSchema as ResultSchema, parseUnifiedSocialCreditCode as parse, formatUnifiedSocialCreditCode as format } from "./UnifiedSocialCreditCode.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { UnifiedSocialCreditCode } from "./
|
|
2
|
+
import { UnifiedSocialCreditCode } from "./mod.js";
|
|
3
3
|
describe("UnifiedSocialCreditCode", function () {
|
|
4
4
|
it("should parse", function () {
|
|
5
5
|
for (var _i = 0, _iter = [
|
package/lib/cn/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { DivisionCode } from "./DivisionCode.js";
|
|
3
|
-
export { UnifiedSocialCreditCode } from "./UnifiedSocialCreditCode.js";
|
|
1
|
+
export { ChineseResidentIdNo, UnifiedSocialCreditCode, DivisionCode } from "./mod.js";
|
package/lib/cn/mod.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as _ChineseResidentIdNo from "./ChineseResidentIdNo.mod.js";
|
|
2
|
+
export { _ChineseResidentIdNo as ChineseResidentIdNo };
|
|
3
|
+
import * as _UnifiedSocialCreditCode from "./UnifiedSocialCreditCode.mod.js";
|
|
4
|
+
export { _UnifiedSocialCreditCode as UnifiedSocialCreditCode };
|
|
5
|
+
import * as _DivisionCode from "./DivisionCode.mod.js";
|
|
6
|
+
export { _DivisionCode as DivisionCode };
|
|
@@ -84,10 +84,10 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
84
84
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
85
85
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
86
86
|
}
|
|
87
|
-
import colors from 'chalk';
|
|
87
|
+
import colors, { Chalk } from 'chalk';
|
|
88
88
|
import dayjs from 'dayjs';
|
|
89
89
|
import { isDevelopment } from 'std-env';
|
|
90
|
-
var
|
|
90
|
+
var LevelColors = {
|
|
91
91
|
trace: colors.gray,
|
|
92
92
|
debug: colors.cyan,
|
|
93
93
|
info: colors.blueBright,
|
|
@@ -120,10 +120,22 @@ var levelShort = {
|
|
|
120
120
|
verbose: 'VERB'
|
|
121
121
|
};
|
|
122
122
|
var start = Date.now();
|
|
123
|
+
var Colors = colors;
|
|
124
|
+
var NoColors = new Chalk({
|
|
125
|
+
level: 0
|
|
126
|
+
});
|
|
123
127
|
export function formatLogObject(o, ctx) {
|
|
128
|
+
var _ctx_options_formatOptions, _ctx_options;
|
|
129
|
+
var shouldColor = Boolean((_ctx_options = ctx.options) === null || _ctx_options === void 0 ? void 0 : (_ctx_options_formatOptions = _ctx_options.formatOptions) === null || _ctx_options_formatOptions === void 0 ? void 0 : _ctx_options_formatOptions.colors);
|
|
124
130
|
var date = o.date, type = o.type, tag = o.tag;
|
|
125
131
|
type = type === 'log' ? 'info' : type;
|
|
126
|
-
var
|
|
132
|
+
var _$colors = shouldColor ? Colors : NoColors;
|
|
133
|
+
var color = LevelColors[type] || _$colors.white;
|
|
134
|
+
if (!shouldColor) {
|
|
135
|
+
color = function(v) {
|
|
136
|
+
return v;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
127
139
|
var levelText = levelShort[type] || type.toUpperCase().slice(0, 4); // Get first 4 chars, consistent uppercase
|
|
128
140
|
var line = '';
|
|
129
141
|
var out = [];
|
|
@@ -131,15 +143,15 @@ export function formatLogObject(o, ctx) {
|
|
|
131
143
|
if (isDevelopment) {
|
|
132
144
|
// process.hrtime.bigint()
|
|
133
145
|
var diff = (date.getTime() - start) / 1000;
|
|
134
|
-
out.push(colors.gray(diff.toFixed(3).padStart(7, ' ')));
|
|
146
|
+
out.push(_$colors.gray(diff.toFixed(3).padStart(7, ' ')));
|
|
135
147
|
} else {
|
|
136
|
-
out.push(colors.gray(dayjs(date).format('YYYY-MM-DD HH:mm:ss.SSS')));
|
|
148
|
+
out.push(_$colors.gray(dayjs(date).format('YYYY-MM-DD HH:mm:ss.SSS')));
|
|
137
149
|
}
|
|
138
150
|
// Log Level (colored)
|
|
139
151
|
// Pad to 4 characters
|
|
140
152
|
out.push(color(levelText.padEnd(4, ' ')));
|
|
141
153
|
if (tag) {
|
|
142
|
-
out.push(colors.yellow("[".concat(tag, "]"))); // Added color for tag
|
|
154
|
+
out.push(_$colors.yellow("[".concat(tag, "]"))); // Added color for tag
|
|
143
155
|
}
|
|
144
156
|
{
|
|
145
157
|
var _formatArgs_split = _to_array(formatArgs(o.args, ctx).split('\n')), message = _formatArgs_split[0], additional = _formatArgs_split.slice(1);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
|
3
|
+
import dayOfYear from 'dayjs/plugin/dayOfYear';
|
|
4
|
+
import duration from 'dayjs/plugin/duration';
|
|
5
|
+
import isBetween from 'dayjs/plugin/isBetween';
|
|
6
|
+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
7
|
+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
8
|
+
import isToday from 'dayjs/plugin/isToday';
|
|
9
|
+
import isTomorrow from 'dayjs/plugin/isTomorrow';
|
|
10
|
+
import isYesterday from 'dayjs/plugin/isYesterday';
|
|
11
|
+
import localeData from 'dayjs/plugin/localeData';
|
|
12
|
+
import objectSupport from 'dayjs/plugin/objectSupport';
|
|
13
|
+
import quarterOfYear from 'dayjs/plugin/quarterOfYear';
|
|
14
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
15
|
+
import timezone from 'dayjs/plugin/timezone';
|
|
16
|
+
import toObject from 'dayjs/plugin/toObject';
|
|
17
|
+
import utc from 'dayjs/plugin/utc';
|
|
18
|
+
import 'dayjs/locale/zh-cn';
|
|
19
|
+
import 'dayjs/locale/zh';
|
|
20
|
+
dayjs.extend(advancedFormat);
|
|
21
|
+
dayjs.extend(dayOfYear);
|
|
22
|
+
dayjs.extend(duration);
|
|
23
|
+
dayjs.extend(isBetween);
|
|
24
|
+
dayjs.extend(isSameOrAfter);
|
|
25
|
+
dayjs.extend(isSameOrBefore);
|
|
26
|
+
dayjs.extend(isToday);
|
|
27
|
+
dayjs.extend(isTomorrow);
|
|
28
|
+
dayjs.extend(isYesterday);
|
|
29
|
+
dayjs.extend(localeData);
|
|
30
|
+
dayjs.extend(objectSupport);
|
|
31
|
+
dayjs.extend(quarterOfYear);
|
|
32
|
+
dayjs.extend(relativeTime);
|
|
33
|
+
dayjs.extend(timezone);
|
|
34
|
+
dayjs.extend(toObject);
|
|
35
|
+
dayjs.extend(utc);
|
|
36
|
+
dayjs.locale('zh-cn');
|
|
37
|
+
dayjs.tz.setDefault('Asia/Shanghai');
|
|
38
|
+
export { dayjs };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { parseDuration } from "./parseDuration.js";
|
|
2
|
+
export function formatDuration(value, o) {
|
|
3
|
+
var v = parseDuration(value);
|
|
4
|
+
if (v === undefined || v === null) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
var _ref = o || {}, format = _ref.format, humanize = _ref.humanize, iso = _ref.iso;
|
|
8
|
+
// Use local variables instead of modifying o directly
|
|
9
|
+
switch (format) {
|
|
10
|
+
case "human":
|
|
11
|
+
case "humanize":
|
|
12
|
+
humanize = true;
|
|
13
|
+
format = undefined;
|
|
14
|
+
break;
|
|
15
|
+
case "iso":
|
|
16
|
+
iso = true;
|
|
17
|
+
format = undefined;
|
|
18
|
+
break;
|
|
19
|
+
case "auto":
|
|
20
|
+
format = undefined;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
if (humanize) {
|
|
24
|
+
return v.humanize();
|
|
25
|
+
}
|
|
26
|
+
if (iso) {
|
|
27
|
+
return v.toISOString();
|
|
28
|
+
}
|
|
29
|
+
if (format) {
|
|
30
|
+
return v.format(format);
|
|
31
|
+
}
|
|
32
|
+
// auto format
|
|
33
|
+
// 1h2m3s
|
|
34
|
+
if (v.asDays() > 1) {
|
|
35
|
+
var s = v.toISOString();
|
|
36
|
+
return s.replace("P", "").replace("T", "").toLowerCase();
|
|
37
|
+
}
|
|
38
|
+
{
|
|
39
|
+
var parts = [];
|
|
40
|
+
var h = v.hours();
|
|
41
|
+
var m = v.minutes();
|
|
42
|
+
var s1 = v.seconds();
|
|
43
|
+
var ms = v.milliseconds();
|
|
44
|
+
if (h > 0) {
|
|
45
|
+
parts.push("".concat(h, "h"));
|
|
46
|
+
}
|
|
47
|
+
if (m > 0) {
|
|
48
|
+
parts.push("".concat(m, "m"));
|
|
49
|
+
}
|
|
50
|
+
if (s1 > 0) {
|
|
51
|
+
parts.push("".concat(s1, "s"));
|
|
52
|
+
}
|
|
53
|
+
if (ms > 0 || h === 0 && m === 0 && s1 === 0) {
|
|
54
|
+
parts.push("".concat(ms, "ms"));
|
|
55
|
+
}
|
|
56
|
+
return parts.join("");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length)
|
|
3
|
+
len = arr.length;
|
|
4
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
5
|
+
arr2[i] = arr[i];
|
|
6
|
+
return arr2;
|
|
7
|
+
}
|
|
8
|
+
function _array_with_holes(arr) {
|
|
9
|
+
if (Array.isArray(arr))
|
|
10
|
+
return arr;
|
|
11
|
+
}
|
|
12
|
+
function _iterable_to_array_limit(arr, i) {
|
|
13
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
14
|
+
if (_i == null)
|
|
15
|
+
return;
|
|
16
|
+
var _arr = [];
|
|
17
|
+
var _n = true;
|
|
18
|
+
var _d = false;
|
|
19
|
+
var _s, _e;
|
|
20
|
+
try {
|
|
21
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
22
|
+
_arr.push(_s.value);
|
|
23
|
+
if (i && _arr.length === i)
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
_d = true;
|
|
29
|
+
_e = err;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
try {
|
|
33
|
+
if (!_n && _i["return"] != null)
|
|
34
|
+
_i["return"]();
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
if (_d)
|
|
38
|
+
throw _e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return _arr;
|
|
42
|
+
}
|
|
43
|
+
function _non_iterable_rest() {
|
|
44
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
45
|
+
}
|
|
46
|
+
function _sliced_to_array(arr, i) {
|
|
47
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
48
|
+
}
|
|
49
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
50
|
+
if (!o)
|
|
51
|
+
return;
|
|
52
|
+
if (typeof o === "string")
|
|
53
|
+
return _array_like_to_array(o, minLen);
|
|
54
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
55
|
+
if (n === "Object" && o.constructor)
|
|
56
|
+
n = o.constructor.name;
|
|
57
|
+
if (n === "Map" || n === "Set")
|
|
58
|
+
return Array.from(n);
|
|
59
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
60
|
+
return _array_like_to_array(o, minLen);
|
|
61
|
+
}
|
|
62
|
+
import { expect, test } from "vitest";
|
|
63
|
+
import { formatDuration } from "./formatDuration.js";
|
|
64
|
+
test("formatDuration", function () {
|
|
65
|
+
for (var _i = 0, _iter = [
|
|
66
|
+
[
|
|
67
|
+
0,
|
|
68
|
+
"0ms"
|
|
69
|
+
],
|
|
70
|
+
[
|
|
71
|
+
1000,
|
|
72
|
+
"1s"
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
1000 * 60,
|
|
76
|
+
"1m"
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
1000 * 60 + 1000,
|
|
80
|
+
"1m1s"
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
1000 * 60 + 1000 + 1,
|
|
84
|
+
"1m1s1ms"
|
|
85
|
+
]
|
|
86
|
+
]; _i < _iter.length; _i++) {
|
|
87
|
+
var _iter__i = _sliced_to_array(_iter[_i], 2), a = _iter__i[0], b = _iter__i[1];
|
|
88
|
+
expect(formatDuration(a)).toBe(b);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function _type_of(obj) {
|
|
2
|
+
"@swc/helpers - typeof";
|
|
3
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
4
|
+
}
|
|
5
|
+
import { dayjs } from "./dayjs.js";
|
|
6
|
+
export function parseDuration(value) {
|
|
7
|
+
if (!value && value !== 0) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
var duration;
|
|
11
|
+
if (typeof value === "number") {
|
|
12
|
+
duration = dayjs.duration(value);
|
|
13
|
+
}
|
|
14
|
+
else if (typeof value === "string" && value.startsWith("P")) {
|
|
15
|
+
// PT0S
|
|
16
|
+
duration = dayjs.duration(value);
|
|
17
|
+
}
|
|
18
|
+
else if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "object" && "value" in value) {
|
|
19
|
+
duration = dayjs.duration(value.value, value.unit);
|
|
20
|
+
}
|
|
21
|
+
else if (dayjs.isDuration(value)) {
|
|
22
|
+
duration = value;
|
|
23
|
+
}
|
|
24
|
+
else if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "object") {
|
|
25
|
+
duration = dayjs.duration(value);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.warn("Invalid duration value:", value);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
return duration;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parseDecimal } from "./parseDecimal.js";
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
+
// Sex 指的是生理性别/生物性别,通常由出生时的生物特征决定
|
|
2
3
|
export var SexType = Object.freeze({
|
|
3
4
|
__proto__: null,
|
|
4
5
|
Male: 'Male',
|
|
5
6
|
Female: 'Female'
|
|
6
7
|
});
|
|
7
8
|
export var SexTypeSchema = z.union([
|
|
9
|
+
//
|
|
8
10
|
z.literal(SexType.Male).describe('男'),
|
|
9
11
|
z.literal(SexType.Female).describe('女')
|
|
10
|
-
]).describe('性别')
|
|
12
|
+
]).describe('性别').meta({
|
|
13
|
+
title: 'SexType'
|
|
14
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SexType, SexTypeSchema } from "./SexType.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SexType } from "./SexType.js";
|
|
2
|
+
export function parseSexType(s) {
|
|
3
|
+
if (!s)
|
|
4
|
+
return undefined;
|
|
5
|
+
switch (s.toLowerCase()) {
|
|
6
|
+
case "\u2642":
|
|
7
|
+
case "\u7537":
|
|
8
|
+
case "male":
|
|
9
|
+
case "man":
|
|
10
|
+
return SexType.Male;
|
|
11
|
+
case "\u2640":
|
|
12
|
+
case "\u5973":
|
|
13
|
+
case "female":
|
|
14
|
+
case "woman":
|
|
15
|
+
return SexType.Female;
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
package/lib/password/Password.js
CHANGED
|
@@ -272,9 +272,9 @@ import { PHC } from "./PHC.js";
|
|
|
272
272
|
}
|
|
273
273
|
return f;
|
|
274
274
|
}
|
|
275
|
-
function
|
|
275
|
+
function validate(password, hash) {
|
|
276
276
|
return _async_to_generator(function () {
|
|
277
|
-
var res, f;
|
|
277
|
+
var res, f, _tmp;
|
|
278
278
|
return _ts_generator(this, function (_state) {
|
|
279
279
|
switch (_state.label) {
|
|
280
280
|
case 0:
|
|
@@ -285,18 +285,21 @@ import { PHC } from "./PHC.js";
|
|
|
285
285
|
case 1:
|
|
286
286
|
res = _state.sent();
|
|
287
287
|
f = resolveAlgorithm(res.id);
|
|
288
|
+
_tmp = {};
|
|
289
|
+
return [
|
|
290
|
+
4,
|
|
291
|
+
f.verify(password, hash, res)
|
|
292
|
+
];
|
|
293
|
+
case 2:
|
|
288
294
|
return [
|
|
289
295
|
2,
|
|
290
|
-
|
|
291
|
-
result: f.verify(password, hash, res),
|
|
292
|
-
parsed: res
|
|
293
|
-
}
|
|
296
|
+
(_tmp.result = _state.sent(), _tmp.parsed = res, _tmp)
|
|
294
297
|
];
|
|
295
298
|
}
|
|
296
299
|
});
|
|
297
300
|
})();
|
|
298
301
|
}
|
|
299
|
-
Password.
|
|
302
|
+
Password.validate = validate;
|
|
300
303
|
function verify(password, hash) {
|
|
301
304
|
return _async_to_generator(function () {
|
|
302
305
|
var res, f;
|