@wener/common 1.0.5 → 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/ChineseResidentIdNo.test.js +22 -0
- package/lib/cn/DivisionCode.js +214 -280
- package/lib/cn/DivisionCode.mod.js +1 -0
- package/lib/cn/DivisionCode.test.js +134 -0
- package/lib/cn/Mod11.js +86 -0
- package/lib/cn/Mod31.js +98 -0
- package/lib/cn/UnifiedSocialCreditCode.js +130 -109
- package/lib/cn/UnifiedSocialCreditCode.mod.js +1 -0
- package/lib/cn/UnifiedSocialCreditCode.test.js +16 -0
- package/lib/cn/index.js +1 -4
- package/lib/cn/mod.js +6 -0
- package/lib/cn/types.d.js +0 -2
- package/lib/consola/createStandardConsolaReporter.js +6 -6
- package/lib/consola/formatLogObject.js +147 -34
- package/lib/consola/index.js +0 -1
- package/lib/data/formatSort.js +5 -6
- package/lib/data/formatSort.test.js +34 -0
- package/lib/data/index.js +0 -1
- package/lib/data/maybeNumber.js +11 -5
- package/lib/data/parseSort.js +28 -22
- package/lib/data/parseSort.test.js +188 -0
- package/lib/data/resolvePagination.js +27 -16
- package/lib/data/resolvePagination.test.js +232 -0
- package/lib/data/types.d.js +0 -2
- 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/foundation/schema/SexType.js +14 -0
- 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/index.js +0 -1
- package/lib/jsonschema/JsonSchema.js +78 -52
- package/lib/jsonschema/JsonSchema.test.js +137 -0
- package/lib/jsonschema/index.js +0 -1
- package/lib/jsonschema/types.d.js +5 -3
- package/lib/meta/defineFileType.js +103 -20
- package/lib/meta/defineInit.js +250 -31
- package/lib/meta/defineMetadata.js +140 -24
- package/lib/meta/defineMetadata.test.js +13 -0
- package/lib/meta/index.js +0 -1
- package/lib/password/PHC.js +87 -63
- package/lib/password/PHC.test.js +539 -0
- package/lib/password/Password.js +295 -30
- package/lib/password/Password.test.js +362 -0
- package/lib/password/createArgon2PasswordAlgorithm.js +191 -35
- package/lib/password/createBase64PasswordAlgorithm.js +141 -8
- package/lib/password/createBcryptPasswordAlgorithm.js +168 -13
- package/lib/password/createPBKDF2PasswordAlgorithm.js +228 -46
- package/lib/password/createScryptPasswordAlgorithm.js +211 -55
- package/lib/password/index.js +0 -1
- package/lib/password/server/index.js +0 -1
- package/lib/resource/Identifiable.js +1 -0
- package/lib/resource/ListQuery.js +119 -0
- package/lib/resource/getTitleOfResource.js +10 -0
- package/lib/resource/index.js +2 -0
- package/lib/resource/schema/AnyResourceSchema.js +89 -0
- package/lib/resource/schema/BaseResourceSchema.js +29 -0
- package/lib/resource/schema/ResourceActionType.js +118 -0
- package/lib/resource/schema/ResourceStatus.js +93 -0
- package/lib/resource/schema/ResourceType.js +24 -0
- package/lib/resource/schema/index.js +5 -0
- package/lib/resource/schema/types.js +89 -0
- package/lib/resource/schema/types.test.js +14 -0
- package/lib/schema/SchemaRegistry.js +45 -0
- package/lib/schema/SchemaRegistry.mod.js +2 -0
- package/lib/schema/TypeSchema.d.js +1 -0
- package/lib/schema/createSchemaData.js +173 -0
- package/lib/schema/findJsonSchemaByPath.js +49 -0
- package/lib/schema/getSchemaCache.js +11 -0
- package/lib/schema/getSchemaOptions.js +24 -0
- package/lib/schema/index.js +6 -0
- package/lib/schema/toJsonSchema.js +441 -0
- package/lib/schema/toJsonSchema.test.js +27 -0
- package/lib/schema/validate.js +124 -0
- package/lib/tools/generateSchema.js +197 -39
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
- package/lib/utils/getEstimateProcessTime.js +20 -0
- package/lib/utils/index.js +1 -0
- package/package.json +38 -17
- 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/data/maybeNumber.ts +5 -1
- package/src/data/resolvePagination.test.ts +1 -1
- package/src/data/resolvePagination.ts +18 -7
- package/src/data/types.d.ts +12 -0
- 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/jsonschema/JsonSchema.test.ts +17 -0
- package/src/jsonschema/JsonSchema.ts +2 -2
- package/src/jsonschema/types.d.ts +63 -12
- package/src/password/Password.ts +2 -2
- package/src/resource/Identifiable.ts +3 -0
- package/src/resource/ListQuery.ts +53 -0
- package/src/resource/getTitleOfResource.tsx +6 -0
- package/src/resource/index.ts +4 -0
- package/src/resource/schema/AnyResourceSchema.ts +113 -0
- package/src/resource/schema/BaseResourceSchema.ts +32 -0
- package/src/resource/schema/ResourceActionType.ts +123 -0
- package/src/resource/schema/ResourceStatus.ts +94 -0
- package/src/resource/schema/ResourceType.ts +25 -0
- package/src/resource/schema/index.ts +5 -0
- package/src/resource/schema/types.test.ts +18 -0
- package/src/resource/schema/types.ts +105 -0
- package/src/schema/SchemaRegistry.mod.ts +1 -0
- package/src/schema/SchemaRegistry.ts +46 -0
- package/src/schema/TypeSchema.d.ts +32 -0
- package/src/schema/createSchemaData.ts +81 -0
- package/src/schema/findJsonSchemaByPath.ts +37 -0
- package/src/schema/getSchemaCache.ts +21 -0
- package/src/schema/getSchemaOptions.ts +24 -0
- package/src/schema/index.ts +7 -0
- package/src/schema/toJsonSchema.test.ts +37 -0
- package/src/schema/toJsonSchema.ts +200 -0
- package/src/schema/validate.ts +135 -0
- package/src/tools/generateSchema.ts +28 -28
- package/src/utils/getEstimateProcessTime.ts +36 -0
- package/src/utils/index.ts +1 -0
- package/lib/cn/DivisionCode.js.map +0 -1
- package/lib/cn/Mod11Checksum.js +0 -42
- package/lib/cn/Mod11Checksum.js.map +0 -1
- package/lib/cn/Mod31Checksum.js +0 -48
- package/lib/cn/Mod31Checksum.js.map +0 -1
- package/lib/cn/ResidentIdentityCardNumber.js +0 -50
- package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
- package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
- package/lib/cn/formatDate.js +0 -15
- package/lib/cn/formatDate.js.map +0 -1
- package/lib/cn/index.js.map +0 -1
- package/lib/cn/parseSex.js +0 -22
- package/lib/cn/parseSex.js.map +0 -1
- package/lib/cn/types.d.js.map +0 -1
- package/lib/consola/createStandardConsolaReporter.js.map +0 -1
- package/lib/consola/formatLogObject.js.map +0 -1
- package/lib/consola/index.js.map +0 -1
- package/lib/data/formatSort.js.map +0 -1
- package/lib/data/index.js.map +0 -1
- package/lib/data/maybeNumber.js.map +0 -1
- package/lib/data/parseSort.js.map +0 -1
- package/lib/data/resolvePagination.js.map +0 -1
- package/lib/data/types.d.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/jsonschema/JsonSchema.js.map +0 -1
- package/lib/jsonschema/index.js.map +0 -1
- package/lib/jsonschema/types.d.js.map +0 -1
- package/lib/meta/defineFileType.js.map +0 -1
- package/lib/meta/defineInit.js.map +0 -1
- package/lib/meta/defineMetadata.js.map +0 -1
- package/lib/meta/index.js.map +0 -1
- package/lib/password/PHC.js.map +0 -1
- package/lib/password/Password.js.map +0 -1
- package/lib/password/createArgon2PasswordAlgorithm.js.map +0 -1
- package/lib/password/createBase64PasswordAlgorithm.js.map +0 -1
- package/lib/password/createBcryptPasswordAlgorithm.js.map +0 -1
- package/lib/password/createPBKDF2PasswordAlgorithm.js.map +0 -1
- package/lib/password/createScryptPasswordAlgorithm.js.map +0 -1
- package/lib/password/index.js.map +0 -1
- package/lib/password/server/index.js.map +0 -1
- package/lib/search/AdvanceSearch.js +0 -10
- package/lib/search/AdvanceSearch.js.map +0 -1
- package/lib/search/formatAdvanceSearch.js +0 -64
- package/lib/search/formatAdvanceSearch.js.map +0 -1
- package/lib/search/index.js +0 -2
- package/lib/search/index.js.map +0 -1
- package/lib/search/optimizeAdvanceSearch.js +0 -89
- package/lib/search/optimizeAdvanceSearch.js.map +0 -1
- package/lib/search/parseAdvanceSearch.js +0 -20
- package/lib/search/parseAdvanceSearch.js.map +0 -1
- package/lib/search/parser.d.js +0 -3
- package/lib/search/parser.d.js.map +0 -1
- package/lib/search/parser.js +0 -3065
- package/lib/search/parser.js.map +0 -1
- package/lib/search/types.d.js +0 -3
- package/lib/search/types.d.js.map +0 -1
- package/lib/tools/generateSchema.js.map +0 -1
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +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/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
|
@@ -0,0 +1,134 @@
|
|
|
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 { describe, expect, it } from "vitest";
|
|
63
|
+
import { DivisionCode } from "./mod.js";
|
|
64
|
+
describe("DivisionCode", function () {
|
|
65
|
+
it("should parse", function () {
|
|
66
|
+
for (var _i = 0, _iter = [
|
|
67
|
+
[
|
|
68
|
+
"441900003001",
|
|
69
|
+
{
|
|
70
|
+
codes: [
|
|
71
|
+
"44",
|
|
72
|
+
"19",
|
|
73
|
+
"00",
|
|
74
|
+
"003",
|
|
75
|
+
"001"
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
441900003001,
|
|
81
|
+
{
|
|
82
|
+
codes: [
|
|
83
|
+
"44",
|
|
84
|
+
"19",
|
|
85
|
+
"00",
|
|
86
|
+
"003",
|
|
87
|
+
"001"
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
441900,
|
|
93
|
+
{
|
|
94
|
+
codes: [
|
|
95
|
+
"44",
|
|
96
|
+
"19",
|
|
97
|
+
"00"
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
"31",
|
|
103
|
+
{
|
|
104
|
+
codes: [
|
|
105
|
+
"31"
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
"4",
|
|
111
|
+
undefined
|
|
112
|
+
],
|
|
113
|
+
[
|
|
114
|
+
"",
|
|
115
|
+
undefined
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
null,
|
|
119
|
+
undefined
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
undefined,
|
|
123
|
+
undefined
|
|
124
|
+
]
|
|
125
|
+
]; _i < _iter.length; _i++) {
|
|
126
|
+
var _iter__i = _sliced_to_array(_iter[_i], 2), a = _iter__i[0], b = _iter__i[1];
|
|
127
|
+
var out = DivisionCode.parse(a);
|
|
128
|
+
expect(out).toMatchObject(b);
|
|
129
|
+
if (out) {
|
|
130
|
+
expect(DivisionCode.format(out)).toBe(String(a));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
package/lib/cn/Mod11.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISO 7064:1983, MOD 11-2.
|
|
3
|
+
*/ function _class_call_check(instance, Constructor) {
|
|
4
|
+
if (!(instance instanceof Constructor)) {
|
|
5
|
+
throw new TypeError("Cannot call a class as a function");
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function _defineProperties(target, props) {
|
|
9
|
+
for(var i = 0; i < props.length; i++){
|
|
10
|
+
var descriptor = props[i];
|
|
11
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
12
|
+
descriptor.configurable = true;
|
|
13
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
14
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
18
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
19
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
20
|
+
return Constructor;
|
|
21
|
+
}
|
|
22
|
+
function _define_property(obj, key, value) {
|
|
23
|
+
if (key in obj) {
|
|
24
|
+
Object.defineProperty(obj, key, {
|
|
25
|
+
value: value,
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
obj[key] = value;
|
|
32
|
+
}
|
|
33
|
+
return obj;
|
|
34
|
+
}
|
|
35
|
+
export var Mod11Checksum = /*#__PURE__*/ function() {
|
|
36
|
+
"use strict";
|
|
37
|
+
function Mod11Checksum() {
|
|
38
|
+
_class_call_check(this, Mod11Checksum);
|
|
39
|
+
_define_property(this, "weights", [
|
|
40
|
+
7,
|
|
41
|
+
9,
|
|
42
|
+
10,
|
|
43
|
+
5,
|
|
44
|
+
8,
|
|
45
|
+
4,
|
|
46
|
+
2,
|
|
47
|
+
1,
|
|
48
|
+
6,
|
|
49
|
+
3,
|
|
50
|
+
7,
|
|
51
|
+
9,
|
|
52
|
+
10,
|
|
53
|
+
5,
|
|
54
|
+
8,
|
|
55
|
+
4,
|
|
56
|
+
2,
|
|
57
|
+
1
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
_create_class(Mod11Checksum, [
|
|
61
|
+
{
|
|
62
|
+
key: "validate",
|
|
63
|
+
value: function validate(s) {
|
|
64
|
+
return s.at(-1) === this.compute(s.slice(0, s.length - 1));
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
key: "compute",
|
|
69
|
+
value: function compute(s) {
|
|
70
|
+
var weights = this.weights;
|
|
71
|
+
var sum = 0;
|
|
72
|
+
for(var i = 0; i < s.length; i++){
|
|
73
|
+
sum += parseInt(s[i]) * weights[i];
|
|
74
|
+
}
|
|
75
|
+
var num = (12 - sum % 11) % 11;
|
|
76
|
+
if (num < 10) {
|
|
77
|
+
return num.toString();
|
|
78
|
+
} else {
|
|
79
|
+
return 'X';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
]);
|
|
84
|
+
return Mod11Checksum;
|
|
85
|
+
}();
|
|
86
|
+
export var Mod11 = new Mod11Checksum();
|
package/lib/cn/Mod31.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GB/T 17710(采ISO 7064)的模31校验码
|
|
3
|
+
*
|
|
4
|
+
* Mod31-3
|
|
5
|
+
*/ function _class_call_check(instance, Constructor) {
|
|
6
|
+
if (!(instance instanceof Constructor)) {
|
|
7
|
+
throw new TypeError("Cannot call a class as a function");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function _defineProperties(target, props) {
|
|
11
|
+
for(var i = 0; i < props.length; i++){
|
|
12
|
+
var descriptor = props[i];
|
|
13
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
14
|
+
descriptor.configurable = true;
|
|
15
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
16
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
20
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
21
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
22
|
+
return Constructor;
|
|
23
|
+
}
|
|
24
|
+
function _define_property(obj, key, value) {
|
|
25
|
+
if (key in obj) {
|
|
26
|
+
Object.defineProperty(obj, key, {
|
|
27
|
+
value: value,
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
obj[key] = value;
|
|
34
|
+
}
|
|
35
|
+
return obj;
|
|
36
|
+
}
|
|
37
|
+
export var Mod31Checksum = /*#__PURE__*/ function() {
|
|
38
|
+
"use strict";
|
|
39
|
+
function Mod31Checksum() {
|
|
40
|
+
_class_call_check(this, Mod31Checksum);
|
|
41
|
+
_define_property(this, "weights", [
|
|
42
|
+
1,
|
|
43
|
+
3,
|
|
44
|
+
9,
|
|
45
|
+
27,
|
|
46
|
+
19,
|
|
47
|
+
26,
|
|
48
|
+
16,
|
|
49
|
+
17,
|
|
50
|
+
20,
|
|
51
|
+
29,
|
|
52
|
+
25,
|
|
53
|
+
13,
|
|
54
|
+
8,
|
|
55
|
+
24,
|
|
56
|
+
10,
|
|
57
|
+
30,
|
|
58
|
+
28
|
|
59
|
+
]);
|
|
60
|
+
_define_property(this, "chars", '0123456789ABCDEFGHJKLMNPQRTUWXY');
|
|
61
|
+
_define_property(this, "numbers", this.chars.split('').reduce(function(acc, cur, i) {
|
|
62
|
+
acc[cur] = i;
|
|
63
|
+
return acc;
|
|
64
|
+
}, {}));
|
|
65
|
+
}
|
|
66
|
+
_create_class(Mod31Checksum, [
|
|
67
|
+
{
|
|
68
|
+
key: "toChar",
|
|
69
|
+
value: function toChar(n) {
|
|
70
|
+
return this.chars[n];
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
key: "toNumber",
|
|
75
|
+
value: function toNumber(c) {
|
|
76
|
+
return this.numbers[c];
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
key: "validate",
|
|
81
|
+
value: function validate(s) {
|
|
82
|
+
return s.at(-1) === this.compute(s.slice(0, s.length - 1));
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
key: "compute",
|
|
87
|
+
value: function compute(s) {
|
|
88
|
+
var sum = 0;
|
|
89
|
+
for(var i = 0; i < s.length; i++){
|
|
90
|
+
sum += this.numbers[s[i]] * this.weights[i];
|
|
91
|
+
}
|
|
92
|
+
return this.toChar(31 - sum % 31);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
]);
|
|
96
|
+
return Mod31Checksum;
|
|
97
|
+
}();
|
|
98
|
+
export var Mod31 = new Mod31Checksum();
|
|
@@ -1,118 +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
|
-
let bureau = s[0];
|
|
68
|
-
let subjectType = s[1];
|
|
69
|
-
let division = s.slice(2, 8); // 第3~8位,共6位,正确
|
|
70
|
-
let subject = s.slice(8, 17); // 第9~17位,共9位
|
|
71
|
-
let checksum = s.slice(17, 18); // 第18位,校验码
|
|
72
|
-
const labels = [];
|
|
73
|
-
let l1 = CodeLabels[bureau];
|
|
74
|
-
l1 && labels.push(l1?.label);
|
|
75
|
-
let l2 = l1?.children?.[subjectType];
|
|
76
|
-
l2 && labels.push(l2?.label);
|
|
77
|
-
return {
|
|
78
|
-
bureau,
|
|
79
|
-
subjectType,
|
|
80
|
-
division,
|
|
81
|
-
subject,
|
|
82
|
-
checksum,
|
|
83
|
-
codes: [
|
|
84
|
-
bureau,
|
|
85
|
-
subjectType,
|
|
86
|
-
division,
|
|
87
|
-
subject
|
|
88
|
-
],
|
|
89
|
-
labels
|
|
90
|
-
};
|
|
91
62
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
+
}
|
|
97
100
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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;
|
|
112
134
|
}
|
|
113
|
-
return sp.map((v) => UnifiedSocialCreditCode.Checksum.chars[v]).join("");
|
|
114
135
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { UnifiedSocialCreditCode } from "./mod.js";
|
|
3
|
+
describe("UnifiedSocialCreditCode", function () {
|
|
4
|
+
it("should parse", function () {
|
|
5
|
+
for (var _i = 0, _iter = [
|
|
6
|
+
//
|
|
7
|
+
"91330106673959654P",
|
|
8
|
+
"91330106MA2CFLDG4R"
|
|
9
|
+
]; _i < _iter.length; _i++) {
|
|
10
|
+
var a = _iter[_i];
|
|
11
|
+
var out = UnifiedSocialCreditCode.parse(a);
|
|
12
|
+
expect(UnifiedSocialCreditCode.format(out)).toBe(a);
|
|
13
|
+
expect(out).toMatchSnapshot();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
package/lib/cn/index.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { DivisionCode } from "./DivisionCode.js";
|
|
3
|
-
export { UnifiedSocialCreditCode } from "./UnifiedSocialCreditCode.js";
|
|
4
|
-
//# sourceMappingURL=index.js.map
|
|
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 };
|
package/lib/cn/types.d.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { formatLogObject } from "./formatLogObject.js";
|
|
2
|
-
export function createStandardConsolaReporter(
|
|
2
|
+
export function createStandardConsolaReporter() {
|
|
3
|
+
var _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _ref_format = _ref.format, format = _ref_format === void 0 ? formatLogObject : _ref_format;
|
|
3
4
|
return {
|
|
4
|
-
log: (o, ctx)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
log: function (o, ctx) {
|
|
6
|
+
var out = format(o, ctx);
|
|
7
|
+
var fn = console.log;
|
|
8
|
+
var level = o.level;
|
|
8
9
|
if (level < 1) {
|
|
9
10
|
fn = console.error;
|
|
10
11
|
}
|
|
@@ -15,4 +16,3 @@ export function createStandardConsolaReporter({ format = formatLogObject } = {})
|
|
|
15
16
|
}
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
|
-
//# sourceMappingURL=createStandardConsolaReporter.js.map
|