@wener/common 2.0.5 → 2.0.6

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 (206) hide show
  1. package/lib/ai/qwen3vl/index.js +1 -1
  2. package/lib/ai/qwen3vl/utils.js +15 -15
  3. package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
  4. package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
  5. package/lib/ai/vision/index.js +2 -2
  6. package/lib/ai/vision/resolveImageAnnotation.js +81 -95
  7. package/lib/cn/ChineseResidentIdNo.js +55 -41
  8. package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
  9. package/lib/cn/ChineseResidentIdNo.test.js +22 -21
  10. package/lib/cn/DivisionCode.js +220 -235
  11. package/lib/cn/DivisionCode.mod.js +6 -1
  12. package/lib/cn/DivisionCode.test.js +92 -121
  13. package/lib/cn/Mod11.js +18 -37
  14. package/lib/cn/Mod31.js +23 -41
  15. package/lib/cn/UnifiedSocialCreditCode.js +143 -137
  16. package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
  17. package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
  18. package/lib/cn/formatChineseAmount.js +46 -71
  19. package/lib/cn/index.js +6 -6
  20. package/lib/cn/mod.js +5 -3
  21. package/lib/cn/parseChineseNumber.js +81 -85
  22. package/lib/cn/parseChineseNumber.test.js +183 -261
  23. package/lib/cn/pinyin/cartesianProduct.js +19 -19
  24. package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
  25. package/lib/cn/pinyin/loader.js +13 -11
  26. package/lib/cn/pinyin/preload.js +2 -1
  27. package/lib/cn/pinyin/toPinyin.test.js +149 -161
  28. package/lib/cn/pinyin/toPinyinPure.js +28 -23
  29. package/lib/cn/pinyin/transform.js +11 -11
  30. package/lib/cn/types.d.js +2 -2
  31. package/lib/consola/createStandardConsolaReporter.js +14 -15
  32. package/lib/consola/formatLogObject.js +149 -133
  33. package/lib/consola/formatLogObject.test.js +167 -178
  34. package/lib/consola/index.js +2 -2
  35. package/lib/data/formatSort.js +14 -12
  36. package/lib/data/formatSort.test.js +33 -33
  37. package/lib/data/index.js +3 -3
  38. package/lib/data/maybeNumber.js +23 -23
  39. package/lib/data/parseSort.js +75 -68
  40. package/lib/data/parseSort.test.js +196 -187
  41. package/lib/data/resolvePagination.js +38 -39
  42. package/lib/data/resolvePagination.test.js +228 -218
  43. package/lib/data/types.d.js +2 -2
  44. package/lib/dayjs/dayjs.js +20 -20
  45. package/lib/dayjs/formatDuration.js +56 -56
  46. package/lib/dayjs/formatDuration.test.js +63 -77
  47. package/lib/dayjs/index.js +4 -4
  48. package/lib/dayjs/parseDuration.js +21 -26
  49. package/lib/dayjs/parseRelativeTime.js +65 -66
  50. package/lib/dayjs/parseRelativeTime.test.js +227 -243
  51. package/lib/dayjs/resolveRelativeTime.js +73 -72
  52. package/lib/dayjs/resolveRelativeTime.test.js +296 -307
  53. package/lib/decimal/index.js +1 -1
  54. package/lib/decimal/parseDecimal.js +12 -12
  55. package/lib/drain3/Drain.js +303 -338
  56. package/lib/drain3/LogCluster.js +25 -25
  57. package/lib/drain3/Node.js +24 -24
  58. package/lib/drain3/TemplateMiner.js +197 -196
  59. package/lib/drain3/index.js +5 -5
  60. package/lib/drain3/persistence/FilePersistence.js +19 -19
  61. package/lib/drain3/persistence/MemoryPersistence.js +8 -8
  62. package/lib/drain3/persistence/PersistenceHandler.js +2 -2
  63. package/lib/drain3/types.js +2 -2
  64. package/lib/emittery/emitter.js +7 -7
  65. package/lib/emittery/index.js +1 -1
  66. package/lib/foundation/schema/SexType.js +15 -12
  67. package/lib/foundation/schema/index.js +1 -1
  68. package/lib/foundation/schema/parseSexType.js +15 -16
  69. package/lib/foundation/schema/types.js +8 -6
  70. package/lib/fs/FileSystemError.js +18 -18
  71. package/lib/fs/IFileSystem.d.js +2 -2
  72. package/lib/fs/MemoryFileSystem.test.js +172 -181
  73. package/lib/fs/createBrowserFileSystem.js +222 -235
  74. package/lib/fs/createMemoryFileSystem.js +472 -510
  75. package/lib/fs/createSandboxFileSystem.js +102 -101
  76. package/lib/fs/createWebDavFileSystem.js +162 -149
  77. package/lib/fs/createWebFileSystem.js +197 -220
  78. package/lib/fs/findMimeType.js +14 -14
  79. package/lib/fs/index.js +7 -7
  80. package/lib/fs/minio/createMinioFileSystem.js +959 -956
  81. package/lib/fs/minio/index.js +1 -1
  82. package/lib/fs/orpc/FileSystemContract.js +57 -57
  83. package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
  84. package/lib/fs/orpc/index.js +2 -2
  85. package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
  86. package/lib/fs/orpc/server/index.js +1 -1
  87. package/lib/fs/s3/createS3MiniFileSystem.js +756 -737
  88. package/lib/fs/s3/index.js +1 -1
  89. package/lib/fs/s3/s3mini.test.js +524 -553
  90. package/lib/fs/scandir.js +56 -56
  91. package/lib/fs/server/createDatabaseFileSystem.js +834 -741
  92. package/lib/fs/server/createNodeFileSystem.js +407 -405
  93. package/lib/fs/server/dbfs.test.js +201 -214
  94. package/lib/fs/server/index.js +1 -1
  95. package/lib/fs/server/loadTestDatabase.js +40 -43
  96. package/lib/fs/tests/runFileSystemTest.js +352 -316
  97. package/lib/fs/types.js +17 -20
  98. package/lib/fs/utils/getFileUrl.js +24 -30
  99. package/lib/fs/utils.js +17 -17
  100. package/lib/fs/webdav/index.js +1 -1
  101. package/lib/index.js +2 -2
  102. package/lib/jsonschema/JsonSchema.js +216 -155
  103. package/lib/jsonschema/JsonSchema.test.js +123 -124
  104. package/lib/jsonschema/forEachJsonSchema.js +41 -41
  105. package/lib/jsonschema/index.js +2 -2
  106. package/lib/jsonschema/types.d.js +2 -2
  107. package/lib/meta/defineFileType.js +32 -38
  108. package/lib/meta/defineInit.js +39 -35
  109. package/lib/meta/defineMetadata.js +37 -34
  110. package/lib/meta/defineMetadata.test.js +13 -12
  111. package/lib/meta/index.js +3 -3
  112. package/lib/orpc/createOpenApiContractClient.js +26 -24
  113. package/lib/orpc/createRpcContractClient.js +37 -31
  114. package/lib/orpc/index.js +2 -2
  115. package/lib/orpc/resolveLinkPlugins.js +25 -25
  116. package/lib/password/PHC.js +187 -189
  117. package/lib/password/PHC.test.js +517 -535
  118. package/lib/password/Password.js +85 -80
  119. package/lib/password/Password.test.js +330 -364
  120. package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
  121. package/lib/password/createBase64PasswordAlgorithm.js +11 -11
  122. package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
  123. package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
  124. package/lib/password/createScryptPasswordAlgorithm.js +74 -63
  125. package/lib/password/index.js +5 -5
  126. package/lib/password/server/index.js +1 -1
  127. package/lib/resource/Identifiable.js +2 -2
  128. package/lib/resource/ListQuery.js +42 -42
  129. package/lib/resource/getTitleOfResource.js +5 -5
  130. package/lib/resource/index.js +2 -2
  131. package/lib/resource/schema/AnyResourceSchema.js +91 -89
  132. package/lib/resource/schema/BaseResourceSchema.js +26 -26
  133. package/lib/resource/schema/ResourceActionType.js +117 -115
  134. package/lib/resource/schema/ResourceStatus.js +94 -92
  135. package/lib/resource/schema/ResourceType.js +25 -23
  136. package/lib/resource/schema/index.js +5 -5
  137. package/lib/resource/schema/types.js +86 -55
  138. package/lib/resource/schema/types.test.js +16 -13
  139. package/lib/s3/formatS3Url.js +60 -60
  140. package/lib/s3/formatS3Url.test.js +238 -261
  141. package/lib/s3/index.js +2 -2
  142. package/lib/s3/parseS3Url.js +61 -60
  143. package/lib/s3/parseS3Url.test.js +270 -269
  144. package/lib/schema/SchemaRegistry.js +41 -42
  145. package/lib/schema/SchemaRegistry.mod.js +1 -1
  146. package/lib/schema/TypeSchema.d.js +2 -2
  147. package/lib/schema/createSchemaData.js +113 -67
  148. package/lib/schema/findJsonSchemaByPath.js +28 -23
  149. package/lib/schema/formatZodError.js +112 -131
  150. package/lib/schema/formatZodError.test.js +192 -195
  151. package/lib/schema/getSchemaCache.js +7 -7
  152. package/lib/schema/getSchemaOptions.js +17 -16
  153. package/lib/schema/index.js +6 -6
  154. package/lib/schema/toJsonSchema.js +195 -189
  155. package/lib/schema/toJsonSchema.test.js +34 -26
  156. package/lib/schema/validate.js +105 -96
  157. package/lib/tools/generateSchema.js +40 -40
  158. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
  159. package/lib/utils/buildBaseUrl.js +8 -8
  160. package/lib/utils/buildRedactorFormSchema.js +54 -53
  161. package/lib/utils/getEstimateProcessTime.js +24 -19
  162. package/lib/utils/index.js +3 -3
  163. package/lib/utils/resolveFeatureOptions.js +9 -9
  164. package/package.json +14 -14
  165. package/src/ai/vision/index.ts +2 -2
  166. package/src/cn/index.ts +1 -2
  167. package/src/consola/index.ts +1 -1
  168. package/src/data/index.ts +3 -4
  169. package/src/data/resolvePagination.ts +2 -2
  170. package/src/dayjs/formatDuration.ts +8 -9
  171. package/src/dayjs/index.ts +1 -1
  172. package/src/dayjs/parseRelativeTime.ts +1 -1
  173. package/src/dayjs/resolveRelativeTime.ts +1 -1
  174. package/src/drain3/Drain.test.ts +2 -2
  175. package/src/drain3/index.ts +2 -4
  176. package/src/fs/createWebDavFileSystem.ts +2 -7
  177. package/src/fs/createWebFileSystem.ts +1 -1
  178. package/src/fs/index.ts +4 -4
  179. package/src/fs/minio/createMinioFileSystem.ts +2 -2
  180. package/src/fs/minio/index.ts +1 -1
  181. package/src/fs/s3/createS3MiniFileSystem.ts +1 -1
  182. package/src/fs/server/createDatabaseFileSystem.ts +84 -120
  183. package/src/fs/server/dbfs.test.ts +14 -10
  184. package/src/fs/server/index.ts +1 -0
  185. package/src/fs/server/loadTestDatabase.ts +8 -119
  186. package/src/jsonschema/index.ts +1 -1
  187. package/src/meta/index.ts +2 -3
  188. package/src/orm/createSqliteDialect.ts +17 -0
  189. package/src/orm/index.ts +1 -0
  190. package/src/orpc/createOpenApiContractClient.ts +1 -1
  191. package/src/orpc/index.ts +1 -1
  192. package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
  193. package/src/password/index.ts +2 -2
  194. package/src/resource/index.ts +3 -3
  195. package/src/resource/schema/index.ts +4 -4
  196. package/src/s3/index.ts +1 -1
  197. package/src/schema/SchemaRegistry.ts +1 -1
  198. package/src/schema/createSchemaData.ts +1 -1
  199. package/src/schema/findJsonSchemaByPath.ts +1 -1
  200. package/src/schema/index.ts +5 -5
  201. package/src/schema/validate.ts +1 -1
  202. package/src/utils/buildRedactorFormSchema.ts +1 -1
  203. package/src/utils/formatNumber.ts +18 -0
  204. package/src/utils/formatPercent.ts +17 -0
  205. package/src/utils/index.ts +3 -3
  206. package/src/utils/resolveFeatureOptions.ts +1 -1
@@ -1,134 +1,105 @@
1
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;
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
4
+ return arr2;
7
5
  }
8
6
  function _array_with_holes(arr) {
9
- if (Array.isArray(arr))
10
- return arr;
7
+ if (Array.isArray(arr)) return arr;
11
8
  }
12
9
  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;
10
+ var _i = arr == null ? null : (typeof Symbol !== 'undefined' && arr[Symbol.iterator]) || arr['@@iterator'];
11
+ if (_i == null) return;
12
+ var _arr = [];
13
+ var _n = true;
14
+ var _d = false;
15
+ var _s, _e;
16
+ try {
17
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
18
+ _arr.push(_s.value);
19
+ if (i && _arr.length === i) break;
20
+ }
21
+ } catch (err) {
22
+ _d = true;
23
+ _e = err;
24
+ } finally {
25
+ try {
26
+ if (!_n && _i['return'] != null) _i['return']();
27
+ } finally {
28
+ if (_d) throw _e;
29
+ }
30
+ }
31
+ return _arr;
42
32
  }
43
33
  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.");
34
+ throw new TypeError(
35
+ 'Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.',
36
+ );
45
37
  }
46
38
  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();
39
+ return (
40
+ _array_with_holes(arr) ||
41
+ _iterable_to_array_limit(arr, i) ||
42
+ _unsupported_iterable_to_array(arr, i) ||
43
+ _non_iterable_rest()
44
+ );
48
45
  }
49
46
  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);
47
+ if (!o) return;
48
+ if (typeof o === 'string') return _array_like_to_array(o, minLen);
49
+ var n = Object.prototype.toString.call(o).slice(8, -1);
50
+ if (n === 'Object' && o.constructor) n = o.constructor.name;
51
+ if (n === 'Map' || n === 'Set') return Array.from(n);
52
+ if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
61
53
  }
62
- import { describe, expect, it } from "vitest";
63
- import { DivisionCode } from "./index.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
- });
54
+
55
+ import { describe, expect, it } from 'vitest';
56
+ import { DivisionCode } from './index.js';
57
+
58
+ describe('DivisionCode', () => {
59
+ it('should parse', () => {
60
+ for (
61
+ var _i = 0,
62
+ _iter = [
63
+ [
64
+ '441900003001',
65
+ {
66
+ codes: ['44', '19', '00', '003', '001'],
67
+ },
68
+ ],
69
+ [
70
+ 441900003001,
71
+ {
72
+ codes: ['44', '19', '00', '003', '001'],
73
+ },
74
+ ],
75
+ [
76
+ 441900,
77
+ {
78
+ codes: ['44', '19', '00'],
79
+ },
80
+ ],
81
+ [
82
+ '31',
83
+ {
84
+ codes: ['31'],
85
+ },
86
+ ],
87
+ ['4', undefined],
88
+ ['', undefined],
89
+ [null, undefined],
90
+ [undefined, undefined],
91
+ ];
92
+ _i < _iter.length;
93
+ _i++
94
+ ) {
95
+ var _iter__i = _sliced_to_array(_iter[_i], 2),
96
+ a = _iter__i[0],
97
+ b = _iter__i[1];
98
+ var out = DivisionCode.parse(a);
99
+ expect(out).toMatchObject(b);
100
+ if (out) {
101
+ expect(DivisionCode.format(out)).toBe(String(a));
102
+ }
103
+ }
104
+ });
134
105
  });
package/lib/cn/Mod11.js CHANGED
@@ -1,43 +1,24 @@
1
1
  /**
2
2
  * ISO 7064:1983, MOD 11-2.
3
3
  */ export class Mod11Checksum {
4
- weights = [
5
- 7,
6
- 9,
7
- 10,
8
- 5,
9
- 8,
10
- 4,
11
- 2,
12
- 1,
13
- 6,
14
- 3,
15
- 7,
16
- 9,
17
- 10,
18
- 5,
19
- 8,
20
- 4,
21
- 2,
22
- 1
23
- ];
24
- validate(s) {
25
- return s.at(-1) === this.compute(s.slice(0, s.length - 1));
26
- }
27
- compute(s) {
28
- const { weights } = this;
29
- let sum = 0;
30
- for(let i = 0; i < s.length; i++){
31
- sum += parseInt(s[i], 10) * weights[i];
32
- }
33
- const num = (12 - sum % 11) % 11;
34
- if (num < 10) {
35
- return num.toString();
36
- } else {
37
- return 'X';
38
- }
39
- }
4
+ weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1];
5
+ validate(s) {
6
+ return s.at(-1) === this.compute(s.slice(0, s.length - 1));
7
+ }
8
+ compute(s) {
9
+ const { weights } = this;
10
+ let sum = 0;
11
+ for (let i = 0; i < s.length; i++) {
12
+ sum += parseInt(s[i], 10) * weights[i];
13
+ }
14
+ const num = (12 - (sum % 11)) % 11;
15
+ if (num < 10) {
16
+ return num.toString();
17
+ } else {
18
+ return 'X';
19
+ }
20
+ }
40
21
  }
41
22
  export const Mod11 = new Mod11Checksum();
42
23
 
43
- //# sourceMappingURL=Mod11.js.map
24
+ //# sourceMappingURL=Mod11.js.map
package/lib/cn/Mod31.js CHANGED
@@ -3,47 +3,29 @@
3
3
  *
4
4
  * Mod31-3
5
5
  */ export class Mod31Checksum {
6
- weights = [
7
- 1,
8
- 3,
9
- 9,
10
- 27,
11
- 19,
12
- 26,
13
- 16,
14
- 17,
15
- 20,
16
- 29,
17
- 25,
18
- 13,
19
- 8,
20
- 24,
21
- 10,
22
- 30,
23
- 28
24
- ];
25
- chars = '0123456789ABCDEFGHJKLMNPQRTUWXY';
26
- numbers = this.chars.split('').reduce((acc, cur, i)=>{
27
- acc[cur] = i;
28
- return acc;
29
- }, {});
30
- toChar(n) {
31
- return this.chars[n];
32
- }
33
- toNumber(c) {
34
- return this.numbers[c];
35
- }
36
- validate(s) {
37
- return s.at(-1) === this.compute(s.slice(0, s.length - 1));
38
- }
39
- compute(s) {
40
- let sum = 0;
41
- for(let i = 0; i < s.length; i++){
42
- sum += this.numbers[s[i]] * this.weights[i];
43
- }
44
- return this.toChar(31 - sum % 31);
45
- }
6
+ weights = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];
7
+ chars = '0123456789ABCDEFGHJKLMNPQRTUWXY';
8
+ numbers = this.chars.split('').reduce((acc, cur, i) => {
9
+ acc[cur] = i;
10
+ return acc;
11
+ }, {});
12
+ toChar(n) {
13
+ return this.chars[n];
14
+ }
15
+ toNumber(c) {
16
+ return this.numbers[c];
17
+ }
18
+ validate(s) {
19
+ return s.at(-1) === this.compute(s.slice(0, s.length - 1));
20
+ }
21
+ compute(s) {
22
+ let sum = 0;
23
+ for (let i = 0; i < s.length; i++) {
24
+ sum += this.numbers[s[i]] * this.weights[i];
25
+ }
26
+ return this.toChar(31 - (sum % 31));
27
+ }
46
28
  }
47
29
  export const Mod31 = new Mod31Checksum();
48
30
 
49
- //# sourceMappingURL=Mod31.js.map
31
+ //# sourceMappingURL=Mod31.js.map
@@ -1,148 +1,154 @@
1
- import { z } from "zod/v4";
2
- import { Mod31 } from "./Mod31.js";
1
+ import { z } from 'zod/v4';
2
+ import { Mod31 } from './Mod31.js';
3
+
3
4
  const 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"
18
- }
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"
35
- }
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"
52
- }
53
- }
54
- },
55
- Y: {
56
- name: "\u5176\u4ED6",
57
- children: {
58
- 1: {
59
- name: "\u5176\u4ED6"
60
- }
61
- }
62
- }
5
+ 1: {
6
+ name: '\u673A\u6784\u7F16\u5236',
7
+ children: {
8
+ 1: {
9
+ name: '\u673A\u5173',
10
+ },
11
+ 2: {
12
+ name: '\u4E8B\u4E1A\u5355\u4F4D',
13
+ },
14
+ 3: {
15
+ name: '\u4E2D\u592E\u7F16\u529E\u76F4\u63A5\u7BA1\u7406\u673A\u6784\u7F16\u5236\u7684\u7FA4\u4F17\u56E2\u4F53',
16
+ },
17
+ 9: {
18
+ name: '\u5176\u4ED6',
19
+ },
20
+ },
21
+ },
22
+ 5: {
23
+ name: '\u6C11\u653F',
24
+ children: {
25
+ 1: {
26
+ name: '\u793E\u4F1A\u56E2\u4F53',
27
+ },
28
+ 2: {
29
+ name: '\u6C11\u529E\u975E\u4F01\u4E1A\u5355\u4F4D',
30
+ },
31
+ 3: {
32
+ name: '\u57FA\u91D1\u4F1A',
33
+ },
34
+ 9: {
35
+ name: '\u5176\u4ED6',
36
+ },
37
+ },
38
+ },
39
+ 9: {
40
+ name: '\u5DE5\u5546',
41
+ children: {
42
+ 1: {
43
+ name: '\u4F01\u4E1A',
44
+ },
45
+ 2: {
46
+ name: '\u4E2A\u4F53\u5DE5\u5546\u6237',
47
+ },
48
+ 3: {
49
+ name: '\u519C\u6C11\u4E13\u4E1A\u5408\u4F5C\u793E',
50
+ },
51
+ 9: {
52
+ name: '\u5176\u4ED6',
53
+ },
54
+ },
55
+ },
56
+ Y: {
57
+ name: '\u5176\u4ED6',
58
+ children: {
59
+ 1: {
60
+ name: '\u5176\u4ED6',
61
+ },
62
+ },
63
+ },
63
64
  };
64
- export const 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");
65
+ export const ParsedUnifiedSocialCreditCodeSchema = z
66
+ .object({
67
+ raw: z.string().length(18).describe('\u7EDF\u4E00\u793E\u4F1A\u4FE1\u7528\u4EE3\u7801'),
68
+ registrationAuthorityCode: z.string().length(1).describe('\u767B\u8BB0\u7BA1\u7406\u90E8\u95E8\u4EE3\u7801'),
69
+ entityCategoryCode: z.string().length(1).describe('\u673A\u6784\u7C7B\u522B\u4EE3\u7801'),
70
+ adminDivisionCode: z
71
+ .string()
72
+ .length(6)
73
+ .describe('\u767B\u8BB0\u7BA1\u7406\u673A\u5173\u884C\u653F\u533A\u5212\u7801 '),
74
+ organizationCode: z
75
+ .string()
76
+ .length(9)
77
+ .describe('\u4E3B\u4F53\u6807\u8BC6\u7801/\u7EC4\u7EC7\u673A\u6784\u4EE3\u7801'),
78
+ checkDigit: z.string().length(1).describe('\u6821\u9A8C\u7801'),
79
+ codes: z.string().array().describe('\u4EE3\u7801\u6570\u7EC4'),
80
+ names: z.string().array().describe('\u4EE3\u7801\u540D\u79F0'),
81
+ valid: z.boolean().optional().describe('\u662F\u5426\u6709\u6548'),
82
+ })
83
+ .describe('\u7EDF\u4E00\u793E\u4F1A\u4FE1\u7528\u4EE3\u7801');
75
84
  export const UnifiedSocialCreditCodeRegex = /^([159][1239]|Y1)[0-9]{6}[0-9A-HJ-NP-RTUWXY]{10}$/;
76
85
  export function parseUnifiedSocialCreditCode(s) {
77
- if (!s || s.length !== 18)
78
- return undefined;
79
- const registrationAuthorityCode = s[0];
80
- const entityCategoryCode = s[1];
81
- const adminDivisionCode = s.slice(2, 8);
82
- const organizationCode = s.slice(8, 17);
83
- const checkDigit = s[17];
84
- const codes = [
85
- registrationAuthorityCode,
86
- entityCategoryCode,
87
- adminDivisionCode,
88
- organizationCode,
89
- checkDigit
90
- ];
91
- const names = [];
92
- const bureau = CodeNames[registrationAuthorityCode];
93
- if (bureau) {
94
- names.push(bureau.name);
95
- const subject = bureau.children?.[entityCategoryCode];
96
- if (subject) {
97
- names.push(subject.name);
98
- }
99
- }
100
- return {
101
- raw: s,
102
- registrationAuthorityCode,
103
- entityCategoryCode,
104
- adminDivisionCode,
105
- organizationCode,
106
- checkDigit,
107
- codes,
108
- names,
109
- valid: UnifiedSocialCreditCodeRegex.test(s) && Mod31.validate(s)
110
- };
86
+ if (!s || s.length !== 18) return undefined;
87
+ const registrationAuthorityCode = s[0];
88
+ const entityCategoryCode = s[1];
89
+ const adminDivisionCode = s.slice(2, 8);
90
+ const organizationCode = s.slice(8, 17);
91
+ const checkDigit = s[17];
92
+ const codes = [registrationAuthorityCode, entityCategoryCode, adminDivisionCode, organizationCode, checkDigit];
93
+ const names = [];
94
+ const bureau = CodeNames[registrationAuthorityCode];
95
+ if (bureau) {
96
+ names.push(bureau.name);
97
+ const subject = bureau.children?.[entityCategoryCode];
98
+ if (subject) {
99
+ names.push(subject.name);
100
+ }
101
+ }
102
+ return {
103
+ raw: s,
104
+ registrationAuthorityCode,
105
+ entityCategoryCode,
106
+ adminDivisionCode,
107
+ organizationCode,
108
+ checkDigit,
109
+ codes,
110
+ names,
111
+ valid: UnifiedSocialCreditCodeRegex.test(s) && Mod31.validate(s),
112
+ };
111
113
  }
112
- export function formatUnifiedSocialCreditCode({ registrationAuthorityCode, entityCategoryCode, adminDivisionCode, organizationCode, checkDigit }) {
113
- const base = `${registrationAuthorityCode}${entityCategoryCode}${adminDivisionCode}${organizationCode}`;
114
- checkDigit ||= Mod31.compute(base);
115
- return `${base}${checkDigit}`;
114
+ export function formatUnifiedSocialCreditCode({
115
+ registrationAuthorityCode,
116
+ entityCategoryCode,
117
+ adminDivisionCode,
118
+ organizationCode,
119
+ checkDigit,
120
+ }) {
121
+ const base = `${registrationAuthorityCode}${entityCategoryCode}${adminDivisionCode}${organizationCode}`;
122
+ checkDigit ||= Mod31.compute(base);
123
+ return `${base}${checkDigit}`;
116
124
  }
117
125
  export function next(s, delta = 1) {
118
- const sp = s.split("").map((v) => Mod31.numbers[v]);
119
- for (let i = sp.length - 1; i >= 0; i--) {
120
- if (delta > 0 && sp[i] < 30 || delta < 0 && sp[i] > 0) {
121
- sp[i] += delta;
122
- break;
123
- }
124
- else if (delta > 0 && sp[i] === 30) {
125
- sp[i] = 0;
126
- }
127
- else if (delta < 0 && sp[i] === 0) {
128
- sp[i] = 30;
129
- }
130
- }
131
- return sp.map((v) => Mod31.chars[v]).join("");
126
+ const sp = s.split('').map((v) => Mod31.numbers[v]);
127
+ for (let i = sp.length - 1; i >= 0; i--) {
128
+ if ((delta > 0 && sp[i] < 30) || (delta < 0 && sp[i] > 0)) {
129
+ sp[i] += delta;
130
+ break;
131
+ } else if (delta > 0 && sp[i] === 30) {
132
+ sp[i] = 0;
133
+ } else if (delta < 0 && sp[i] === 0) {
134
+ sp[i] = 30;
135
+ }
136
+ }
137
+ return sp.map((v) => Mod31.chars[v]).join('');
132
138
  }
133
- (function (UnifiedSocialCreditCode) {
134
- UnifiedSocialCreditCode.regex = UnifiedSocialCreditCodeRegex;
135
- UnifiedSocialCreditCode.parse = parseUnifiedSocialCreditCode;
136
- UnifiedSocialCreditCode.format = formatUnifiedSocialCreditCode;
137
- UnifiedSocialCreditCode.ResultSchema = ParsedUnifiedSocialCreditCodeSchema;
138
- function test(s) {
139
- if (!s) {
140
- return false;
141
- }
142
- // fast check
143
- return UnifiedSocialCreditCode.regex.test(s) && Mod31.validate(s);
144
- }
145
- UnifiedSocialCreditCode.test = test;
139
+ ((UnifiedSocialCreditCode) => {
140
+ UnifiedSocialCreditCode.regex = UnifiedSocialCreditCodeRegex;
141
+ UnifiedSocialCreditCode.parse = parseUnifiedSocialCreditCode;
142
+ UnifiedSocialCreditCode.format = formatUnifiedSocialCreditCode;
143
+ UnifiedSocialCreditCode.ResultSchema = ParsedUnifiedSocialCreditCodeSchema;
144
+ function test(s) {
145
+ if (!s) {
146
+ return false;
147
+ }
148
+ // fast check
149
+ return UnifiedSocialCreditCode.regex.test(s) && Mod31.validate(s);
150
+ }
151
+ UnifiedSocialCreditCode.test = test;
146
152
  })(UnifiedSocialCreditCode || (UnifiedSocialCreditCode = {}));
147
153
  export var UnifiedSocialCreditCode;
148
154
  //# sourceMappingURL=UnifiedSocialCreditCode.js.map
@@ -1 +1,6 @@
1
- export { UnifiedSocialCreditCodeRegex as regex, ParsedUnifiedSocialCreditCodeSchema as ResultSchema, parseUnifiedSocialCreditCode as parse, formatUnifiedSocialCreditCode as format } from "./UnifiedSocialCreditCode.js";
1
+ export {
2
+ formatUnifiedSocialCreditCode as format,
3
+ ParsedUnifiedSocialCreditCodeSchema as ResultSchema,
4
+ parseUnifiedSocialCreditCode as parse,
5
+ UnifiedSocialCreditCodeRegex as regex,
6
+ } from './UnifiedSocialCreditCode.js';