@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.
Files changed (222) hide show
  1. package/lib/cn/ChineseResidentIdNo.js +41 -0
  2. package/lib/cn/ChineseResidentIdNo.mod.js +1 -0
  3. package/lib/cn/ChineseResidentIdNo.test.js +22 -0
  4. package/lib/cn/DivisionCode.js +214 -280
  5. package/lib/cn/DivisionCode.mod.js +1 -0
  6. package/lib/cn/DivisionCode.test.js +134 -0
  7. package/lib/cn/Mod11.js +86 -0
  8. package/lib/cn/Mod31.js +98 -0
  9. package/lib/cn/UnifiedSocialCreditCode.js +130 -109
  10. package/lib/cn/UnifiedSocialCreditCode.mod.js +1 -0
  11. package/lib/cn/UnifiedSocialCreditCode.test.js +16 -0
  12. package/lib/cn/index.js +1 -4
  13. package/lib/cn/mod.js +6 -0
  14. package/lib/cn/types.d.js +0 -2
  15. package/lib/consola/createStandardConsolaReporter.js +6 -6
  16. package/lib/consola/formatLogObject.js +147 -34
  17. package/lib/consola/index.js +0 -1
  18. package/lib/data/formatSort.js +5 -6
  19. package/lib/data/formatSort.test.js +34 -0
  20. package/lib/data/index.js +0 -1
  21. package/lib/data/maybeNumber.js +11 -5
  22. package/lib/data/parseSort.js +28 -22
  23. package/lib/data/parseSort.test.js +188 -0
  24. package/lib/data/resolvePagination.js +27 -16
  25. package/lib/data/resolvePagination.test.js +232 -0
  26. package/lib/data/types.d.js +0 -2
  27. package/lib/dayjs/dayjs.js +38 -0
  28. package/lib/dayjs/formatDuration.js +58 -0
  29. package/lib/dayjs/formatDuration.test.js +90 -0
  30. package/lib/dayjs/index.js +3 -0
  31. package/lib/dayjs/parseDuration.js +32 -0
  32. package/lib/decimal/index.js +1 -0
  33. package/lib/decimal/parseDecimal.js +13 -0
  34. package/lib/foundation/schema/SexType.js +14 -0
  35. package/lib/foundation/schema/index.js +1 -0
  36. package/lib/foundation/schema/parseSexType.js +18 -0
  37. package/lib/foundation/schema/types.js +5 -0
  38. package/lib/index.js +0 -1
  39. package/lib/jsonschema/JsonSchema.js +78 -52
  40. package/lib/jsonschema/JsonSchema.test.js +137 -0
  41. package/lib/jsonschema/index.js +0 -1
  42. package/lib/jsonschema/types.d.js +5 -3
  43. package/lib/meta/defineFileType.js +103 -20
  44. package/lib/meta/defineInit.js +250 -31
  45. package/lib/meta/defineMetadata.js +140 -24
  46. package/lib/meta/defineMetadata.test.js +13 -0
  47. package/lib/meta/index.js +0 -1
  48. package/lib/password/PHC.js +87 -63
  49. package/lib/password/PHC.test.js +539 -0
  50. package/lib/password/Password.js +295 -30
  51. package/lib/password/Password.test.js +362 -0
  52. package/lib/password/createArgon2PasswordAlgorithm.js +191 -35
  53. package/lib/password/createBase64PasswordAlgorithm.js +141 -8
  54. package/lib/password/createBcryptPasswordAlgorithm.js +168 -13
  55. package/lib/password/createPBKDF2PasswordAlgorithm.js +228 -46
  56. package/lib/password/createScryptPasswordAlgorithm.js +211 -55
  57. package/lib/password/index.js +0 -1
  58. package/lib/password/server/index.js +0 -1
  59. package/lib/resource/Identifiable.js +1 -0
  60. package/lib/resource/ListQuery.js +119 -0
  61. package/lib/resource/getTitleOfResource.js +10 -0
  62. package/lib/resource/index.js +2 -0
  63. package/lib/resource/schema/AnyResourceSchema.js +89 -0
  64. package/lib/resource/schema/BaseResourceSchema.js +29 -0
  65. package/lib/resource/schema/ResourceActionType.js +118 -0
  66. package/lib/resource/schema/ResourceStatus.js +93 -0
  67. package/lib/resource/schema/ResourceType.js +24 -0
  68. package/lib/resource/schema/index.js +5 -0
  69. package/lib/resource/schema/types.js +89 -0
  70. package/lib/resource/schema/types.test.js +14 -0
  71. package/lib/schema/SchemaRegistry.js +45 -0
  72. package/lib/schema/SchemaRegistry.mod.js +2 -0
  73. package/lib/schema/TypeSchema.d.js +1 -0
  74. package/lib/schema/createSchemaData.js +173 -0
  75. package/lib/schema/findJsonSchemaByPath.js +49 -0
  76. package/lib/schema/getSchemaCache.js +11 -0
  77. package/lib/schema/getSchemaOptions.js +24 -0
  78. package/lib/schema/index.js +6 -0
  79. package/lib/schema/toJsonSchema.js +441 -0
  80. package/lib/schema/toJsonSchema.test.js +27 -0
  81. package/lib/schema/validate.js +124 -0
  82. package/lib/tools/generateSchema.js +197 -39
  83. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +143 -55
  84. package/lib/utils/getEstimateProcessTime.js +20 -0
  85. package/lib/utils/index.js +1 -0
  86. package/package.json +38 -17
  87. package/src/cn/ChineseResidentIdNo.mod.ts +7 -0
  88. package/src/cn/ChineseResidentIdNo.test.ts +18 -0
  89. package/src/cn/ChineseResidentIdNo.ts +66 -0
  90. package/src/cn/DivisionCode.mod.ts +7 -0
  91. package/src/cn/DivisionCode.test.ts +3 -13
  92. package/src/cn/DivisionCode.ts +132 -195
  93. package/src/cn/{Mod11Checksum.ts → Mod11.ts} +3 -1
  94. package/src/cn/{Mod31Checksum.ts → Mod31.ts} +2 -0
  95. package/src/cn/UnifiedSocialCreditCode.mod.ts +7 -0
  96. package/src/cn/UnifiedSocialCreditCode.test.ts +2 -2
  97. package/src/cn/UnifiedSocialCreditCode.ts +105 -125
  98. package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +14 -0
  99. package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +18 -12
  100. package/src/cn/index.ts +1 -3
  101. package/src/cn/mod.ts +3 -0
  102. package/src/consola/formatLogObject.ts +12 -4
  103. package/src/data/maybeNumber.ts +5 -1
  104. package/src/data/resolvePagination.test.ts +1 -1
  105. package/src/data/resolvePagination.ts +18 -7
  106. package/src/data/types.d.ts +12 -0
  107. package/src/dayjs/dayjs.ts +40 -0
  108. package/src/dayjs/formatDuration.test.ts +14 -0
  109. package/src/dayjs/formatDuration.ts +86 -0
  110. package/src/dayjs/index.ts +3 -0
  111. package/src/dayjs/parseDuration.ts +40 -0
  112. package/src/decimal/index.ts +1 -0
  113. package/src/decimal/parseDecimal.ts +16 -0
  114. package/src/foundation/schema/SexType.ts +21 -0
  115. package/src/foundation/schema/index.ts +1 -0
  116. package/src/foundation/schema/parseSexType.ts +19 -0
  117. package/src/foundation/schema/types.ts +8 -0
  118. package/src/jsonschema/JsonSchema.test.ts +17 -0
  119. package/src/jsonschema/JsonSchema.ts +2 -2
  120. package/src/jsonschema/types.d.ts +63 -12
  121. package/src/password/Password.ts +2 -2
  122. package/src/resource/Identifiable.ts +3 -0
  123. package/src/resource/ListQuery.ts +53 -0
  124. package/src/resource/getTitleOfResource.tsx +6 -0
  125. package/src/resource/index.ts +4 -0
  126. package/src/resource/schema/AnyResourceSchema.ts +113 -0
  127. package/src/resource/schema/BaseResourceSchema.ts +32 -0
  128. package/src/resource/schema/ResourceActionType.ts +123 -0
  129. package/src/resource/schema/ResourceStatus.ts +94 -0
  130. package/src/resource/schema/ResourceType.ts +25 -0
  131. package/src/resource/schema/index.ts +5 -0
  132. package/src/resource/schema/types.test.ts +18 -0
  133. package/src/resource/schema/types.ts +105 -0
  134. package/src/schema/SchemaRegistry.mod.ts +1 -0
  135. package/src/schema/SchemaRegistry.ts +46 -0
  136. package/src/schema/TypeSchema.d.ts +32 -0
  137. package/src/schema/createSchemaData.ts +81 -0
  138. package/src/schema/findJsonSchemaByPath.ts +37 -0
  139. package/src/schema/getSchemaCache.ts +21 -0
  140. package/src/schema/getSchemaOptions.ts +24 -0
  141. package/src/schema/index.ts +7 -0
  142. package/src/schema/toJsonSchema.test.ts +37 -0
  143. package/src/schema/toJsonSchema.ts +200 -0
  144. package/src/schema/validate.ts +135 -0
  145. package/src/tools/generateSchema.ts +28 -28
  146. package/src/utils/getEstimateProcessTime.ts +36 -0
  147. package/src/utils/index.ts +1 -0
  148. package/lib/cn/DivisionCode.js.map +0 -1
  149. package/lib/cn/Mod11Checksum.js +0 -42
  150. package/lib/cn/Mod11Checksum.js.map +0 -1
  151. package/lib/cn/Mod31Checksum.js +0 -48
  152. package/lib/cn/Mod31Checksum.js.map +0 -1
  153. package/lib/cn/ResidentIdentityCardNumber.js +0 -50
  154. package/lib/cn/ResidentIdentityCardNumber.js.map +0 -1
  155. package/lib/cn/UnifiedSocialCreditCode.js.map +0 -1
  156. package/lib/cn/formatDate.js +0 -15
  157. package/lib/cn/formatDate.js.map +0 -1
  158. package/lib/cn/index.js.map +0 -1
  159. package/lib/cn/parseSex.js +0 -22
  160. package/lib/cn/parseSex.js.map +0 -1
  161. package/lib/cn/types.d.js.map +0 -1
  162. package/lib/consola/createStandardConsolaReporter.js.map +0 -1
  163. package/lib/consola/formatLogObject.js.map +0 -1
  164. package/lib/consola/index.js.map +0 -1
  165. package/lib/data/formatSort.js.map +0 -1
  166. package/lib/data/index.js.map +0 -1
  167. package/lib/data/maybeNumber.js.map +0 -1
  168. package/lib/data/parseSort.js.map +0 -1
  169. package/lib/data/resolvePagination.js.map +0 -1
  170. package/lib/data/types.d.js.map +0 -1
  171. package/lib/index.js.map +0 -1
  172. package/lib/jsonschema/JsonSchema.js.map +0 -1
  173. package/lib/jsonschema/index.js.map +0 -1
  174. package/lib/jsonschema/types.d.js.map +0 -1
  175. package/lib/meta/defineFileType.js.map +0 -1
  176. package/lib/meta/defineInit.js.map +0 -1
  177. package/lib/meta/defineMetadata.js.map +0 -1
  178. package/lib/meta/index.js.map +0 -1
  179. package/lib/password/PHC.js.map +0 -1
  180. package/lib/password/Password.js.map +0 -1
  181. package/lib/password/createArgon2PasswordAlgorithm.js.map +0 -1
  182. package/lib/password/createBase64PasswordAlgorithm.js.map +0 -1
  183. package/lib/password/createBcryptPasswordAlgorithm.js.map +0 -1
  184. package/lib/password/createPBKDF2PasswordAlgorithm.js.map +0 -1
  185. package/lib/password/createScryptPasswordAlgorithm.js.map +0 -1
  186. package/lib/password/index.js.map +0 -1
  187. package/lib/password/server/index.js.map +0 -1
  188. package/lib/search/AdvanceSearch.js +0 -10
  189. package/lib/search/AdvanceSearch.js.map +0 -1
  190. package/lib/search/formatAdvanceSearch.js +0 -64
  191. package/lib/search/formatAdvanceSearch.js.map +0 -1
  192. package/lib/search/index.js +0 -2
  193. package/lib/search/index.js.map +0 -1
  194. package/lib/search/optimizeAdvanceSearch.js +0 -89
  195. package/lib/search/optimizeAdvanceSearch.js.map +0 -1
  196. package/lib/search/parseAdvanceSearch.js +0 -20
  197. package/lib/search/parseAdvanceSearch.js.map +0 -1
  198. package/lib/search/parser.d.js +0 -3
  199. package/lib/search/parser.d.js.map +0 -1
  200. package/lib/search/parser.js +0 -3065
  201. package/lib/search/parser.js.map +0 -1
  202. package/lib/search/types.d.js +0 -3
  203. package/lib/search/types.d.js.map +0 -1
  204. package/lib/tools/generateSchema.js.map +0 -1
  205. package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +0 -1
  206. package/src/cn/ResidentIdentityCardNumber.test.ts +0 -17
  207. package/src/cn/ResidentIdentityCardNumber.ts +0 -96
  208. package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +0 -15
  209. package/src/cn/formatDate.ts +0 -12
  210. package/src/cn/parseSex.ts +0 -13
  211. package/src/search/AdvanceSearch.test.ts +0 -149
  212. package/src/search/AdvanceSearch.ts +0 -14
  213. package/src/search/Makefile +0 -2
  214. package/src/search/__snapshots__/AdvanceSearch.test.ts.snap +0 -675
  215. package/src/search/formatAdvanceSearch.ts +0 -52
  216. package/src/search/index.ts +0 -1
  217. package/src/search/optimizeAdvanceSearch.ts +0 -77
  218. package/src/search/parseAdvanceSearch.ts +0 -23
  219. package/src/search/parser.d.ts +0 -8
  220. package/src/search/parser.js +0 -2794
  221. package/src/search/parser.peggy +0 -237
  222. package/src/search/types.d.ts +0 -45
@@ -0,0 +1,200 @@
1
+ import { omit, remove } from 'es-toolkit';
2
+ import { match, P } from 'ts-pattern';
3
+ import { z } from 'zod/v4';
4
+ import type { JsonSchemaDef } from '../jsonschema';
5
+ import { getSchemaCache } from './getSchemaCache';
6
+ import type { TypeSchema } from './TypeSchema';
7
+ import { isTypeBoxSchema, isZodSchema } from './validate';
8
+
9
+ export function toJsonSchema(schema: TypeSchema): JsonSchemaDef {
10
+ if (isZodSchema(schema)) {
11
+ return getSchemaCache(schema, 'jsonschema', () => {
12
+ // zod v4
13
+ let js = z.toJSONSchema(schema, {
14
+ unrepresentable: 'any',
15
+ override: ({ zodSchema, jsonSchema: js }) => {
16
+ const def = zodSchema._zod.def;
17
+ const meta = z.globalRegistry.get(zodSchema);
18
+ if (meta) {
19
+ Object.assign(js, meta);
20
+ }
21
+ switch (def.type) {
22
+ case 'union':
23
+ if (zodSchema._zod.traits.has('ZodDiscriminatedUnion')) {
24
+ resolveDiscriminator(js as JsonSchemaDef);
25
+ }
26
+ break;
27
+ case 'nonoptional':
28
+ // js._ref maybe true
29
+ js.nullable = false;
30
+ break;
31
+ case 'nullable':
32
+ case 'optional':
33
+ // prefer nullable
34
+ match(js)
35
+ .with({ anyOf: [P.select(), { type: 'null' }] }, (select) => {
36
+ delete js['anyOf'];
37
+ Object.assign(js, select);
38
+ js.nullable = true;
39
+ })
40
+ .otherwise((js) => {
41
+ js.nullable = true;
42
+ });
43
+ break;
44
+ }
45
+ },
46
+ }) as JsonSchemaDef;
47
+
48
+ // remove redundant nullable, ensure required is sorted
49
+ visit(js, (v) => {
50
+ if (v.nullable === false) {
51
+ delete v.nullable;
52
+ }
53
+ if (v.required) {
54
+ v.required.sort();
55
+ }
56
+ });
57
+ // maybe freeze
58
+ return js;
59
+ });
60
+ }
61
+
62
+ if (isTypeBoxSchema(schema)) {
63
+ return schema as JsonSchemaDef;
64
+ }
65
+
66
+ return schema as JsonSchemaDef;
67
+ }
68
+
69
+ function visit(js: JsonSchemaDef, f: (js: JsonSchemaDef) => void) {
70
+ const _visit = (
71
+ js: JsonSchemaDef,
72
+ f: (js: JsonSchemaDef) => void,
73
+ parent: JsonSchemaDef | undefined,
74
+ path: string[],
75
+ k?: string,
76
+ ) => {
77
+ if (!js) {
78
+ return;
79
+ }
80
+ f(js);
81
+ if (js.properties) {
82
+ for (const [k, v] of Object.entries(js.properties)) {
83
+ if (v) {
84
+ _visit(v, f, js, path.concat(k), 'properties');
85
+ }
86
+ }
87
+ } else if (js.items) {
88
+ if (Array.isArray(js.items)) {
89
+ for (const v of js.items) {
90
+ _visit(v, f, js, path, 'items');
91
+ }
92
+ } else {
93
+ _visit(js.items, f, js, path, 'items');
94
+ }
95
+ } else if (js.anyOf) {
96
+ for (const v of js.anyOf) {
97
+ _visit(v, f, js, path, 'anyOf');
98
+ }
99
+ } else if (js.oneOf) {
100
+ for (const v of js.oneOf) {
101
+ _visit(v, f, js, path, 'oneOf');
102
+ }
103
+ } else if (js.allOf) {
104
+ for (const v of js.allOf) {
105
+ _visit(v, f, js, path, 'allOf');
106
+ }
107
+ }
108
+ };
109
+ _visit(js, f, undefined, []);
110
+ }
111
+
112
+ function resolveJsonSchemaDef(
113
+ js: JsonSchemaDef,
114
+ ctx?: {
115
+ parent: JsonSchemaDef;
116
+ key: string;
117
+ },
118
+ ) {
119
+ return match(js)
120
+ .with(
121
+ {
122
+ anyOf: [P.select(), { type: 'null' }],
123
+ },
124
+ (select) => {
125
+ return { ...omit(js, ['anyOf']), ...select, nullable: true };
126
+ },
127
+ )
128
+ .with({ properties: P.nonNullable }, (schema: JsonSchemaDef) => {
129
+ for (const key in schema.properties) {
130
+ const prop = schema.properties[key];
131
+ if (prop) {
132
+ schema.properties[key] = resolveJsonSchemaDef(prop, { parent: schema, key });
133
+ }
134
+ }
135
+ return schema;
136
+ })
137
+ .otherwise(() => {
138
+ return js;
139
+ });
140
+ }
141
+
142
+ function resolveDiscriminator(jsd: JsonSchemaDef) {
143
+ if (!(jsd.anyOf && jsd.anyOf.length > 1)) {
144
+ return;
145
+ }
146
+ if (jsd.discriminator) {
147
+ return;
148
+ }
149
+
150
+ let names: string[] = [];
151
+ {
152
+ // candidate for discriminator
153
+ const v = jsd.anyOf[0];
154
+ if (v && v.type === 'object' && v.properties) {
155
+ if (Array.isArray(v.required)) {
156
+ for (const k of v.required) {
157
+ if (v.properties[k].const !== undefined) {
158
+ names.push(k);
159
+ }
160
+ }
161
+ }
162
+ }
163
+ }
164
+ if (names.length >= 1) {
165
+ for (let i = 0; i < jsd.anyOf.length; i++) {
166
+ if (i === 0) {
167
+ // skip first
168
+ continue;
169
+ }
170
+ if (!names.length) {
171
+ break;
172
+ }
173
+
174
+ const v = jsd.anyOf[i];
175
+ if (v && v.type === 'object' && v.properties) {
176
+ const props = v.properties;
177
+ remove(names, (k) => {
178
+ // dont care the mapping
179
+ let p = props[k];
180
+ switch (typeof p.const) {
181
+ case 'string':
182
+ case 'number':
183
+ case 'boolean':
184
+ return false;
185
+ default:
186
+ return true;
187
+ }
188
+ });
189
+ } else {
190
+ names = [];
191
+ break;
192
+ }
193
+ }
194
+ }
195
+ if (names.length === 1) {
196
+ jsd.discriminator = {
197
+ propertyName: names[0],
198
+ };
199
+ }
200
+ }
@@ -0,0 +1,135 @@
1
+ import { Kind as TypeBoxKind, type TSchema } from '@sinclair/typebox';
2
+ import '@sinclair/typebox';
3
+ import { TypeCompiler } from '@sinclair/typebox/compiler';
4
+ import { ifPresent } from '@wener/utils';
5
+ import { Ajv } from 'ajv';
6
+ import addFormats from 'ajv-formats';
7
+ import type { ZodType } from 'zod/v4';
8
+ import type { JsonSchemaDef } from '../jsonschema';
9
+ import type { SchemaOutput, TypeSchema } from './TypeSchema';
10
+
11
+ /*
12
+ https://github.com/react-hook-form/resolvers
13
+ https://github.com/decs/typeschema/tree/main/packages
14
+ */
15
+
16
+ export function validate<S extends TypeSchema>(schema: S, data: unknown): ValidationResult<SchemaOutput<S>> {
17
+ if (isZodSchema(schema)) {
18
+ const result = schema.safeParse(data);
19
+ if (result.success) {
20
+ return {
21
+ success: true,
22
+ data: result.data as any,
23
+ };
24
+ }
25
+
26
+ return {
27
+ issues: result.error.issues.map(({ message, path, code }) => ({ message, path, code })),
28
+ // message: z.prettifyError(result.error),
29
+ success: false,
30
+ };
31
+ }
32
+
33
+ if (isTypeBoxSchema(schema)) {
34
+ const checker = TypeCompiler.Compile(schema);
35
+ if (checker.Check(data)) {
36
+ return {
37
+ success: true,
38
+ data: data as any,
39
+ };
40
+ }
41
+ return {
42
+ issues: Array.from(checker.Errors(data)).map(({ message, path }) => {
43
+ return { message, path: [path] };
44
+ }),
45
+ // message: '',
46
+ success: false,
47
+ };
48
+ }
49
+
50
+ if (isJsonSchema(schema)) {
51
+ const ajv = new Ajv({
52
+ allErrors: true,
53
+ validateSchema: true,
54
+ });
55
+ addFormats(ajv);
56
+ const validator = ajv.compile(schema);
57
+ if (validator(data)) {
58
+ return {
59
+ data: data as any,
60
+ success: true,
61
+ };
62
+ }
63
+
64
+ const issues =
65
+ validator.errors?.map((error) => {
66
+ const message = error.message || 'Unknown error';
67
+ const path = error.instancePath
68
+ .split('/')
69
+ .filter(Boolean)
70
+ .map((p) => p as PropertyKey);
71
+ return { message, path };
72
+ }) || [];
73
+ return {
74
+ success: false,
75
+ // message: 'Invalid data',
76
+ issues,
77
+ };
78
+ }
79
+
80
+ return {
81
+ success: false,
82
+ // message: 'Invalid schema',
83
+ issues: [
84
+ {
85
+ message: 'Unknown schema type',
86
+ },
87
+ ],
88
+ };
89
+ }
90
+
91
+ export function parseData<S extends TypeSchema>(schema: S, data: unknown): SchemaOutput<S> {
92
+ let result = validate(schema, data);
93
+ if (result.success) {
94
+ return result.data;
95
+ }
96
+ throw Object.assign(
97
+ new Error(
98
+ result.issues
99
+ .map((v) => {
100
+ return `${ifPresent(v.path?.join(), (v) => `[${v}]`)}: ${v.message}`;
101
+ })
102
+ .join('; '),
103
+ ),
104
+ {
105
+ issues: result.issues,
106
+ },
107
+ );
108
+ }
109
+
110
+ function formatIssues(schema: TypeSchema, issues: Array<ValidationIssue>): string {
111
+ return '';
112
+ }
113
+
114
+ export function isZodSchema<I = any, O = any>(schema: any | TypeSchema<I, O>): schema is ZodType<O, I> {
115
+ return typeof schema === 'object' && 'parse' in schema;
116
+ }
117
+
118
+ export function isTypeBoxSchema(schema: any): schema is TSchema {
119
+ return typeof schema === 'object' && TypeBoxKind in schema;
120
+ }
121
+
122
+ export function isJsonSchema(schema: any): schema is JsonSchemaDef {
123
+ let sc: JsonSchemaDef = schema;
124
+ return typeof schema === 'object' && Boolean(sc.type || sc.properties || sc.anyOf || sc.oneOf || sc.$ref || sc.items);
125
+ }
126
+
127
+ export type ValidationIssue = {
128
+ message: string;
129
+ path?: Array<PropertyKey>;
130
+ code?: string;
131
+ };
132
+
133
+ export type ValidationResult<TOutput> =
134
+ | { success: true; data: TOutput }
135
+ | { success: false; issues: Array<ValidationIssue> };
@@ -4,36 +4,36 @@ import path from 'node:path';
4
4
  import * as Codegen from '@sinclair/typebox-codegen';
5
5
 
6
6
  export async function generateSchema({ file, dir = path.dirname(file) }: { file: string; dir?: string }) {
7
- const fn = path.basename(file).replace(/\.d\.ts$/, '.ts');
8
- const types = await fs.readFile(file, 'utf-8');
7
+ const fn = path.basename(file).replace(/\.d\.ts$/, '.ts');
8
+ const types = await fs.readFile(file, 'utf-8');
9
9
 
10
- const typeboxDir = path.join(dir, 'typebox');
11
- const zodDir = path.join(dir, 'zod');
10
+ const typeboxDir = path.join(dir, 'typebox');
11
+ const zodDir = path.join(dir, 'zod');
12
12
 
13
- await fs.mkdir(typeboxDir, { recursive: true });
14
- await fs.mkdir(zodDir, { recursive: true });
13
+ await fs.mkdir(typeboxDir, { recursive: true });
14
+ await fs.mkdir(zodDir, { recursive: true });
15
15
 
16
- const typeBoxFile = path.join(typeboxDir, fn);
17
- const zodFile = path.join(zodDir, fn);
18
- {
19
- // avoid import type error
20
- let out = Codegen.TypeScriptToTypeBox.Generate(types);
21
- out = out.replace(/^import \{ Type, Static\b/, `import { Type, type Static`);
22
- await fs.writeFile(typeBoxFile, out);
23
- }
24
- const model = Codegen.TypeScriptToModel.Generate(types);
25
- await fs.writeFile(zodFile, Codegen.ModelToZod.Generate(model));
16
+ const typeBoxFile = path.join(typeboxDir, fn);
17
+ const zodFile = path.join(zodDir, fn);
18
+ {
19
+ // avoid import type error
20
+ let out = Codegen.TypeScriptToTypeBox.Generate(types);
21
+ out = out.replace(/^import \{ Type, Static\b/, `import { Type, type Static`);
22
+ await fs.writeFile(typeBoxFile, out);
23
+ }
24
+ const model = Codegen.TypeScriptToModel.Generate(types);
25
+ await fs.writeFile(zodFile, Codegen.ModelToZod.Generate(model));
26
26
 
27
- await new Promise((resolve, reject) => {
28
- exec(`pnpm prettier --write "${dir}/{typebox,zod}/*.ts"`, (error, stdout, stderr) => {
29
- if (error) {
30
- console.error(`exec error: ${error}`);
31
- reject(error);
32
- return;
33
- }
34
- resolve({ stderr, stdout });
35
- stdout && console.log(`prettier:stdout: ${stdout}`);
36
- stderr && console.error(`prettier:stderr: ${stderr}`);
37
- });
38
- });
27
+ await new Promise((resolve, reject) => {
28
+ exec(`pnpm prettier --write "${dir}/{typebox,zod}/*.ts"`, (error, stdout, stderr) => {
29
+ if (error) {
30
+ console.error(`exec error: ${error}`);
31
+ reject(error);
32
+ return;
33
+ }
34
+ resolve({ stderr, stdout });
35
+ stdout && console.log(`prettier:stdout: ${stdout}`);
36
+ stderr && console.error(`prettier:stderr: ${stderr}`);
37
+ });
38
+ });
39
39
  }
@@ -0,0 +1,36 @@
1
+ type EstimateProcessTimeResult = {
2
+ eta: number; // estimated time of arrival in seconds
3
+ elapsed: number; // in seconds
4
+ endTime: Date; // estimated end time
5
+ rate: number; // rate of processing in items per second
6
+ };
7
+
8
+ export function getEstimateProcessTime({
9
+ total,
10
+ processed,
11
+ startTime,
12
+ elapsed = startTime ? (Date.now() - startTime.getTime()) / 1000 : undefined,
13
+ }: {
14
+ total?: number;
15
+ processed?: number;
16
+ startTime?: Date;
17
+ elapsed?: number; // in seconds
18
+ }): EstimateProcessTimeResult | undefined {
19
+ if (typeof total !== 'number' || typeof processed !== 'number' || !elapsed || processed === 0 || processed >= total) {
20
+ return undefined;
21
+ }
22
+ const now = new Date();
23
+ const rate = processed / elapsed;
24
+ if (rate === 0) {
25
+ return undefined;
26
+ }
27
+ const remaining = total - processed;
28
+ const eta = Math.round(remaining / rate);
29
+ const endTime = new Date(now.getTime() + eta * 1000);
30
+ return {
31
+ eta,
32
+ elapsed,
33
+ endTime,
34
+ rate,
35
+ };
36
+ }
@@ -0,0 +1 @@
1
+ export { getEstimateProcessTime } from './getEstimateProcessTime';
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/DivisionCode.ts"],"sourcesContent":["const DivisionCodeLevels: Array<{ level: number; code: string; length: number; size: number; label: string }> = [\n\t{ level: 1, code: 'Province', length: 2, size: 2, label: '省' },\n\t{ level: 2, code: 'City', length: 4, size: 2, label: '市' },\n\t{ level: 3, code: 'County', length: 6, size: 2, label: '区县' },\n\t{ level: 4, code: 'Town', length: 9, size: 3, label: '乡镇' },\n\t{ level: 5, code: 'Village', length: 12, size: 3, label: '村' },\n] as const;\n\n// String(Number.MAX_SAFE_INTEGER).length=16\n// 12 is safe int\n\n/**\n * Codes for the administrative divisions of the People's Republic of China\n *\n * @see https://zh.wikipedia.org/wiki/GB/T_2260 中华人民共和国行政区划代码\n */\nexport namespace DivisionCode {\n\tenum DivisionCodeLevel {\n\t\tProvince = 1,\n\t\tCity = 2,\n\t\tCounty = 3,\n\t\tTown = 4,\n\t\tVillage = 5,\n\t}\n\n\texport const levels = DivisionCodeLevels;\n\n\texport const regex = /^(?<province>\\d{2})(?<city>\\d{2})?(?<county>\\d{2})?(?<town>\\d{3})?(?<village>\\d{3})?$/;\n\n\tconst root: CodeValue[] = [\n\t\t{ value: '11', label: '北京市' },\n\t\t{ value: '12', label: '天津市' },\n\t\t{ value: '13', label: '河北省' },\n\t\t{ value: '14', label: '山西省' },\n\t\t{ value: '15', label: '内蒙古自治区' },\n\t\t{ value: '21', label: '辽宁省' },\n\t\t{ value: '22', label: '吉林省' },\n\t\t{ value: '23', label: '黑龙江省' },\n\t\t{ value: '31', label: '上海市' },\n\t\t{ value: '32', label: '江苏省' },\n\t\t{ value: '33', label: '浙江省' },\n\t\t{ value: '34', label: '安徽省' },\n\t\t{ value: '35', label: '福建省' },\n\t\t{ value: '36', label: '江西省' },\n\t\t{ value: '37', label: '山东省' },\n\t\t{ value: '41', label: '河南省' },\n\t\t{ value: '42', label: '湖北省' },\n\t\t{ value: '43', label: '湖南省' },\n\t\t{ value: '44', label: '广东省' },\n\t\t{ value: '45', label: '广西壮族自治区' },\n\t\t{ value: '46', label: '海南省' },\n\t\t{ value: '50', label: '重庆市' },\n\t\t{ value: '51', label: '四川省' },\n\t\t{ value: '52', label: '贵州省' },\n\t\t{ value: '53', label: '云南省' },\n\t\t{ value: '54', label: '西藏自治区' },\n\t\t{ value: '61', label: '陕西省' },\n\t\t{ value: '62', label: '甘肃省' },\n\t\t{ value: '63', label: '青海省' },\n\t\t{ value: '64', label: '宁夏回族自治区' },\n\t\t{ value: '65', label: '新疆维吾尔自治区' },\n\t\t{ value: '71', label: '台湾省' },\n\t\t{ value: '81', label: '香港特别行政区' },\n\t\t{ value: '82', label: '澳门特别行政区' },\n\t\t// 9 国外\n\t];\n\n\texport type ParsedCode = {\n\t\tprovince: string;\n\t\tcity?: string;\n\t\tcounty?: string;\n\t\ttown?: string;\n\t\tvillage?: string;\n\t\tcodes: string[];\n\t\tlevel: DivisionCodeLevel;\n\t\tlabels: string[];\n\t};\n\n\texport function parse(code: string | undefined | null | number): ParsedCode | undefined {\n\t\tif (!code) return;\n\t\tcode = String(code);\n\t\tconst match = regex.exec(code);\n\t\tif (!match) return;\n\t\tconst { province, city, county, town, village } = match.groups ?? {};\n\t\tif (!province) return;\n\n\t\tlet codes = [province, city, county, town, village].filter(Boolean);\n\t\treturn { province, city, county, town, village, codes: codes, level: codes.length as DivisionCodeLevel };\n\t}\n\n\texport function format({\n\t\tprovince,\n\t\tcity,\n\t\tcounty,\n\t\ttown,\n\t\tvillage,\n\t}: {\n\t\tprovince: string | number;\n\t\tcity?: string | number;\n\t\tcounty?: string | number;\n\t\ttown?: string | number;\n\t\tvillage?: string | number;\n\t}): string {\n\t\tconst codes: string[] = [];\n\t\tfor (let i = 0; i < [province, city, county, town, village].length; i++) {\n\t\t\tlet x = [province, city, county, town, village][i];\n\t\t\tif (x === undefined || x === null || x === '') {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlet len = levels[i].size;\n\t\t\tcodes.push(String(x).padStart(len, '0').slice(0, len));\n\t\t}\n\t\treturn codes.join('');\n\t}\n\n\t// export function random(level: DivisionCodeLevel = 'County'): string {\n\t// const l = DivisionCodeLevels.find((v) => v.code === level) || DivisionCodeLevels[2];\n\t// const l1 = randomPick(provinces);\n\t// if (l.level === 1) {\n\t// return String(l1[0]);\n\t// }\n\t// return l1 + String(Math.floor(Math.random() * parseFloat(`1e${l.length - 2}`) - 1));\n\t// }\n}\n\ninterface DivisionTreeNode {\n\tsub: string; // sub code\n\tchildren?: Record<string, DivisionTreeNode>;\n\n\tcode: string; // full code\n\tname?: string; // name of division\n}\n\n// export type DivisionCodeLevel = 'Village' | 'Town' | 'County' | 'City' | 'Province';\n\n// export interface ParsedDivisionCode {\n// level: DivisionCodeLevel;\n// code: string;\n// name?: string;\n// fullName?: string;\n// names: string[];\n// // 村级(村委会、居委会)\n// // 12 位\n// village?: CodeName;\n// // 乡级(乡镇、街道)\n// // 9 位\n// town?: CodeName;\n// // 县级(区县)\n// // 6 位 - 常用 - 2985 个\n// county?: CodeName;\n// // 地级(城市)\n// // 4 位 - 343 个\n// city?: CodeName;\n// // 省级(省份、直辖市、自治区)\n// // 2 位 - 32 个\n// province: CodeName;\n//\n// children?: Array<{ code: string; name?: string }>;\n// }\n\n// export interface CodeName {\n// code: string;\n// name: string;\n// }\n\n// export function getSimpleProvinceLabel(value: string) {\n// if (!value) {\n// return;\n// }\n// let label = value;\n// if (/[0-9]/.test(label)) {\n// label = label.slice(0, 2);\n// label = options.find((v) => v.value === label)?.label || label;\n// }\n// return label.replace(/省|市|(回族|维吾尔|壮族)?自治区|特别行政区$/, '');\n// }\n\nexport function randomPick<T>(s: T[]) {\n\treturn s[Math.floor(Math.random() * s.length)];\n}\n\nfunction lookup(opts: { values: string[]; root: CodeValue[] }): { found: CodeValue[] } {\n\tconst { values, root } = opts;\n\tconst found: CodeValue[] = [];\n\tlet currentLevel = root;\n\n\tfor (const v of values) {\n\t\tconst node = currentLevel.find((n) => n.value === v);\n\t\tif (!node) {\n\t\t\tbreak;\n\t\t}\n\n\t\tfound.push(node);\n\n\t\tif (node.children) {\n\t\t\tcurrentLevel = node.children;\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn { found };\n}\n\ninterface CodeValue {\n\tvalue: string;\n\tlabel: string;\n\tchildren?: Array<CodeValue>;\n}\n"],"names":["DivisionCodeLevels","level","code","length","size","label","DivisionCode","DivisionCodeLevel","levels","regex","root","value","parse","String","match","exec","province","city","county","town","village","groups","codes","filter","Boolean","format","i","x","undefined","len","push","padStart","slice","join","randomPick","s","Math","floor","random","lookup","opts","values","found","currentLevel","v","node","find","n","children"],"mappings":"AAAA,MAAMA,qBAA0G;IAC/G;QAAEC,OAAO;QAAGC,MAAM;QAAYC,QAAQ;QAAGC,MAAM;QAAGC,OAAO;IAAI;IAC7D;QAAEJ,OAAO;QAAGC,MAAM;QAAQC,QAAQ;QAAGC,MAAM;QAAGC,OAAO;IAAI;IACzD;QAAEJ,OAAO;QAAGC,MAAM;QAAUC,QAAQ;QAAGC,MAAM;QAAGC,OAAO;IAAK;IAC5D;QAAEJ,OAAO;QAAGC,MAAM;QAAQC,QAAQ;QAAGC,MAAM;QAAGC,OAAO;IAAK;IAC1D;QAAEJ,OAAO;QAAGC,MAAM;QAAWC,QAAQ;QAAIC,MAAM;QAAGC,OAAO;IAAI;CAC7D;UAUgBC;IAChB,IAAA,AAAKC,2CAAAA;;;;;;eAAAA;;iBAQQC,SAASR;iBAETS,QAAQ;IAErB,MAAMC,OAAoB;QACzB;YAAEC,OAAO;YAAMN,OAAO;QAAM;QAC5B;YAAEM,OAAO;YAAMN,OAAO;QAAM;QAC5B;YAAEM,OAAO;YAAMN,OAAO;QAAM;QAC5B;YA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
- 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]) * 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
- }
40
- }
41
-
42
- //# sourceMappingURL=Mod11Checksum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/Mod11Checksum.ts"],"sourcesContent":["/**\n * ISO 7064:1983, MOD 11-2.\n */\nexport class Mod11Checksum {\n\tweights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1];\n\n\tvalidate(s: string) {\n\t\treturn s.at(-1) === this.compute(s.slice(0, s.length - 1));\n\t}\n\n\tcompute(s: string) {\n\t\tconst { weights } = this;\n\t\tlet sum = 0;\n\t\tfor (let i = 0; i < s.length; i++) {\n\t\t\tsum += parseInt(s[i]) * weights[i];\n\t\t}\n\t\tconst num = (12 - (sum % 11)) % 11;\n\t\tif (num < 10) {\n\t\t\treturn num.toString();\n\t\t} else {\n\t\t\treturn 'X';\n\t\t}\n\t}\n}\n"],"names":["Mod11Checksum","weights","validate","s","at","compute","slice","length","sum","i","parseInt","num","toString"],"mappings":"AAAA;;CAEC,GACD,OAAO,MAAMA;IACZC,UAAU;QAAC;QAAG;QAAG;QAAI;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAI;QAAG;QAAG;QAAG;QAAG;KAAE,CAAC;IAEnEC,SAASC,CAAS,EAAE;QACnB,OAAOA,EAAEC,EAAE,CAAC,CAAC,OAAO,IAAI,CAACC,OAAO,CAACF,EAAEG,KAAK,CAAC,GAAGH,EAAEI,MAAM,GAAG;IACxD;IAEAF,QAAQF,CAAS,EAAE;QAClB,MAAM,EAAEF,OAAO,EAAE,GAAG,IAAI;QACxB,IAAIO,MAAM;QACV,IAAK,IAAIC,IAAI,GAAGA,IAAIN,EAAEI,MAAM,EAAEE,IAAK;YAClCD,OAAOE,SAASP,CAAC,CAACM,EAAE,IAAIR,OAAO,CAACQ,EAAE;QACnC;QACA,MAAME,MAAM,AAAC,CAAA,KAAMH,MAAM,EAAE,IAAK;QAChC,IAAIG,MAAM,IAAI;YACb,OAAOA,IAAIC,QAAQ;QACpB,OAAO;YACN,OAAO;QACR;IACD;AACD"}
@@ -1,48 +0,0 @@
1
- /**
2
- * GB/T 17710(采ISO 7064)的模31校验码
3
- *
4
- * Mod31-3
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
- }
46
- }
47
-
48
- //# sourceMappingURL=Mod31Checksum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/Mod31Checksum.ts"],"sourcesContent":["/**\n * GB/T 17710(采ISO 7064)的模31校验码\n *\n * Mod31-3\n */\nexport class Mod31Checksum {\n\tweights = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];\n\tchars = '0123456789ABCDEFGHJKLMNPQRTUWXY';\n\tnumbers: Record<string, number> = this.chars.split('').reduce(\n\t\t(acc, cur, i) => {\n\t\t\tacc[cur] = i;\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record<string, number>,\n\t);\n\n\ttoChar(n: number) {\n\t\treturn this.chars[n];\n\t}\n\n\ttoNumber(c: string) {\n\t\treturn this.numbers[c];\n\t}\n\n\tvalidate(s: string) {\n\t\treturn s.at(-1) === this.compute(s.slice(0, s.length - 1));\n\t}\n\n\tcompute(s: string) {\n\t\tlet sum = 0;\n\t\tfor (let i = 0; i < s.length; i++) {\n\t\t\tsum += this.numbers[s[i]] * this.weights[i];\n\t\t}\n\t\treturn this.toChar(31 - (sum % 31));\n\t}\n}\n"],"names":["Mod31Checksum","weights","chars","numbers","split","reduce","acc","cur","i","toChar","n","toNumber","c","validate","s","at","compute","slice","length","sum"],"mappings":"AAAA;;;;CAIC,GACD,OAAO,MAAMA;IACZC,UAAU;QAAC;QAAG;QAAG;QAAG;QAAI;QAAI;QAAI;QAAI;QAAI;QAAI;QAAI;QAAI;QAAI;QAAG;QAAI;QAAI;QAAI;KAAG,CAAC;IAC3EC,QAAQ,kCAAkC;IAC1CC,UAAkC,IAAI,CAACD,KAAK,CAACE,KAAK,CAAC,IAAIC,MAAM,CAC5D,CAACC,KAAKC,KAAKC;QACVF,GAAG,CAACC,IAAI,GAAGC;QACX,OAAOF;IACR,GACA,CAAC,GACA;IAEFG,OAAOC,CAAS,EAAE;QACjB,OAAO,IAAI,CAACR,KAAK,CAACQ,EAAE;IACrB;IAEAC,SAASC,CAAS,EAAE;QACnB,OAAO,IAAI,CAACT,OAAO,CAACS,EAAE;IACvB;IAEAC,SAASC,CAAS,EAAE;QACnB,OAAOA,EAAEC,EAAE,CAAC,CAAC,OAAO,IAAI,CAACC,OAAO,CAACF,EAAEG,KAAK,CAAC,GAAGH,EAAEI,MAAM,GAAG;IACxD;IAEAF,QAAQF,CAAS,EAAE;QAClB,IAAIK,MAAM;QACV,IAAK,IAAIX,IAAI,GAAGA,IAAIM,EAAEI,MAAM,EAAEV,IAAK;YAClCW,OAAO,IAAI,CAAChB,OAAO,CAACW,CAAC,CAACN,EAAE,CAAC,GAAG,IAAI,CAACP,OAAO,CAACO,EAAE;QAC5C;QACA,OAAO,IAAI,CAACC,MAAM,CAAC,KAAMU,MAAM;IAChC;AACD"}
@@ -1,50 +0,0 @@
1
- import { formatDate } from "./formatDate.js";
2
- import { Mod11Checksum } from "./Mod11Checksum.js";
3
- (function (ResidentIdentityCardNumber) {
4
- ResidentIdentityCardNumber.Checksum = new Mod11Checksum();
5
- function parse(s) {
6
- const division = s.slice(0, 6);
7
- const birthDate = s.slice(6, 14);
8
- const sequence = parseInt(s.slice(14, 17), 10);
9
- const checksum = s.slice(17, 18);
10
- const valid = ResidentIdentityCardNumber.Checksum.validate(s);
11
- const sex = sequence % 2 === 1 ? "Male" : "Female";
12
- return {
13
- division,
14
- birthDate,
15
- sequence,
16
- checksum,
17
- valid,
18
- sex,
19
- male: sex === "Male",
20
- female: sex === "Female",
21
- age: new Date().getFullYear() - parseInt(birthDate.slice(0, 4), 10)
22
- };
23
- }
24
- /*
25
- export const length = 18;
26
- export const pattern = /^\d{6}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[0-9Xx]$/;
27
- */ ResidentIdentityCardNumber.parse = parse;
28
- function format({ division, birthDate, sequence, checksum }) {
29
- if (typeof birthDate !== "string") {
30
- birthDate = formatDate(birthDate, "yyyyMMDD");
31
- }
32
- if (birthDate.includes("-")) {
33
- birthDate = birthDate.replace(/-/g, "");
34
- }
35
- typeof sequence === "number" && (sequence = sequence.toString());
36
- sequence = sequence.padStart(3, "0");
37
- const base = [
38
- division,
39
- birthDate,
40
- sequence
41
- ].join("");
42
- if (base.length !== 17)
43
- throw new Error("Invalid params");
44
- checksum ||= ResidentIdentityCardNumber.Checksum.compute(base);
45
- return base + checksum;
46
- }
47
- ResidentIdentityCardNumber.format = format;
48
- })(ResidentIdentityCardNumber || (ResidentIdentityCardNumber = {}));
49
- export var ResidentIdentityCardNumber;
50
- //# sourceMappingURL=ResidentIdentityCardNumber.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/ResidentIdentityCardNumber.ts"],"sourcesContent":["import { formatDate } from './formatDate';\nimport { Mod11Checksum } from './Mod11Checksum';\n\nexport namespace ResidentIdentityCardNumber {\n\texport const Checksum = new Mod11Checksum();\n\n\t/*\n export const length = 18;\n export const pattern = /^\\d{6}(18|19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[0-9Xx]$/;\n */\n\n\texport function parse(s: string): ParsedResidentIdentityCardNumber {\n\t\tconst division = s.slice(0, 6);\n\t\tconst birthDate = s.slice(6, 14);\n\t\tconst sequence = parseInt(s.slice(14, 17), 10);\n\t\tconst checksum = s.slice(17, 18);\n\t\tconst valid = Checksum.validate(s);\n\t\tconst sex = sequence % 2 === 1 ? 'Male' : 'Female';\n\t\treturn {\n\t\t\tdivision,\n\t\t\tbirthDate,\n\t\t\tsequence,\n\t\t\tchecksum,\n\t\t\tvalid,\n\t\t\tsex,\n\t\t\tmale: sex === 'Male',\n\t\t\tfemale: sex === 'Female',\n\t\t\tage: new Date().getFullYear() - parseInt(birthDate.slice(0, 4), 10),\n\t\t};\n\t}\n\n\texport function format({\n\t\tdivision,\n\t\tbirthDate,\n\t\tsequence,\n\t\tchecksum,\n\t}: {\n\t\tdivision: string;\n\t\tbirthDate: string | Date;\n\t\tsequence: number | string;\n\t\tchecksum?: string;\n\t}) {\n\t\tif (typeof birthDate !== 'string') {\n\t\t\tbirthDate = formatDate(birthDate, 'yyyyMMDD');\n\t\t}\n\t\tif (birthDate.includes('-')) {\n\t\t\tbirthDate = birthDate.replace(/-/g, '');\n\t\t}\n\t\ttypeof sequence === 'number' && (sequence = sequence.toString());\n\t\tsequence = sequence.padStart(3, '0');\n\t\tconst base = [division, birthDate, sequence].join('');\n\t\tif (base.length !== 17) throw new Error('Invalid params');\n\t\tchecksum ||= Checksum.compute(base);\n\t\treturn base + checksum;\n\t}\n}\nexport interface ParsedResidentIdentityCardNumber {\n\t/**\n\t * @title 行政区划代码\n\t */\n\tdivision: string;\n\t/**\n\t * @title 出生日期\n\t * 格式 yyyyMMDD\n\t */\n\tbirthDate: string;\n\t/**\n\t * @title 顺序码\n\t */\n\tsequence: number;\n\t/**\n\t * @title 校验位\n\t */\n\tchecksum: string;\n\n\t/**\n\t * @title 是否有效\n\t */\n\tvalid: boolean;\n\t/**\n\t * @title 是否男性\n\t */\n\tmale: boolean;\n\t/**\n\t * @title 是否女性\n\t */\n\tfemale: boolean;\n\t/**\n\t * @title 性别\n\t */\n\tsex: 'Male' | 'Female';\n\t/**\n\t * @title 年龄\n\t */\n\tage: number;\n}\n"],"names":["formatDate","Mod11Checksum","ResidentIdentityCardNumber","Checksum","parse","s","division","slice","birthDate","sequence","parseInt","checksum","valid","validate","sex","male","female","age","Date","getFullYear","format","includes","replace","toString","padStart","base","join","length","Error","compute"],"mappings":"AAAA,SAASA,UAAU,QAAQ,eAAe;AAC1C,SAASC,aAAa,QAAQ,kBAAkB;UAE/BC;+BACHC,WAAW,IAAIF;IAOrB,SAASG,MAAMC,CAAS;QAC9B,MAAMC,WAAWD,EAAEE,KAAK,CAAC,GAAG;QAC5B,MAAMC,YAAYH,EAAEE,KAAK,CAAC,GAAG;QAC7B,MAAME,WAAWC,SAASL,EAAEE,KAAK,CAAC,IAAI,KAAK;QAC3C,MAAMI,WAAWN,EAAEE,KAAK,CAAC,IAAI;QAC7B,MAAMK,QAAQT,2BAAAA,SAASU,QAAQ,CAACR;QAChC,MAAMS,MAAML,WAAW,MAAM,IAAI,SAAS;QAC1C,OAAO;YACNH;YACAE;YACAC;YACAE;YACAC;YACAE;YACAC,MAAMD,QAAQ;YACdE,QAAQF,QAAQ;YAChBG,KAAK,IAAIC,OAAOC,WAAW,KAAKT,SAASF,UAAUD,KAAK,CAAC,GAAG,IAAI;QACjE;IACD;IAvBA;;;GAGE,8BAEcH,QAAAA;IAoBT,SAASgB,OAAO,EACtBd,QAAQ,EACRE,SAAS,EACTC,QAAQ,EACRE,QAAQ,EAMR;QACA,IAAI,OAAOH,cAAc,UAAU;YAClCA,YAAYR,WAAWQ,WAAW;QACnC;QACA,IAAIA,UAAUa,QAAQ,CAAC,MAAM;YAC5Bb,YAAYA,UAAUc,OAAO,CAAC,MAAM;QACrC;QACA,OAAOb,aAAa,YAAaA,CAAAA,WAAWA,SAASc,QAAQ,EAAC;QAC9Dd,WAAWA,SAASe,QAAQ,CAAC,GAAG;QAChC,MAAMC,OAAO;YAACnB;YAAUE;YAAWC;SAAS,CAACiB,IAAI,CAAC;QAClD,IAAID,KAAKE,MAAM,KAAK,IAAI,MAAM,IAAIC,MAAM;QACxCjB,aAAaR,2BAAAA,SAAS0B,OAAO,CAACJ;QAC9B,OAAOA,OAAOd;IACf;+BAvBgBS,SAAAA;AAwBjB,GApDiBlB,+BAAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/UnifiedSocialCreditCode.ts"],"sourcesContent":["import { Mod31Checksum } from './Mod31Checksum';\n\n/**\n * 统一社会信用代码\n *\n * - GB 11714-1997 全国组织机构代码编制规则\n */\nexport namespace UnifiedSocialCreditCode {\n\tinterface CodeValue {\n\t\tlabel: string;\n\t\tchildren?: Record<string, CodeValue>;\n\t}\n\n\tconst CodeLabels: Record<string, CodeValue> = {\n\t\t1: {\n\t\t\tlabel: '机构编制',\n\t\t\tchildren: {\n\t\t\t\t1: { label: '机关' },\n\t\t\t\t2: { label: '事业单位' },\n\t\t\t\t3: { label: '中央编办直接管理机构编制的群众团体' },\n\t\t\t\t9: { label: '其他' },\n\t\t\t},\n\t\t},\n\t\t5: {\n\t\t\tlabel: '民政',\n\t\t\tchildren: {\n\t\t\t\t1: { label: '社会团体' },\n\t\t\t\t2: { label: '民办非企业单位' },\n\t\t\t\t3: { label: '基金会' },\n\t\t\t\t9: { label: '其他' },\n\t\t\t},\n\t\t},\n\t\t9: {\n\t\t\tlabel: '工商',\n\t\t\tchildren: {\n\t\t\t\t1: { label: '企业' },\n\t\t\t\t2: { label: '个体工商户' },\n\t\t\t\t3: { label: '农民专业合作社' },\n\t\t\t\t9: { label: '其他' },\n\t\t\t},\n\t\t},\n\t\tY: { label: '其他', children: { 1: { label: '其他' } } },\n\t};\n\n\texport const pattern = /^([159][1239]|Y1)[0-9]{6}[0-9A-HJ-NP-RTUWXY]{10}$/; // 无 I O Z S V\n\n\texport const Checksum = new Mod31Checksum();\n\n\texport function parse(s: string): ParsedUnifiedSocialCreditCode {\n\t\tlet bureau = s[0];\n\t\tlet subjectType = s[1];\n\t\tlet division = s.slice(2, 8); // 第3~8位,共6位,正确\n\t\tlet subject = s.slice(8, 17); // 第9~17位,共9位\n\t\tlet checksum = s.slice(17, 18); // 第18位,校验码\n\n\t\tconst labels: string[] = [];\n\t\tlet l1 = CodeLabels[bureau];\n\t\tl1 && labels.push(l1?.label);\n\t\tlet l2 = l1?.children?.[subjectType];\n\t\tl2 && labels.push(l2?.label);\n\n\t\treturn {\n\t\t\tbureau,\n\t\t\tsubjectType,\n\t\t\tdivision,\n\t\t\tsubject,\n\t\t\tchecksum,\n\t\t\tcodes: [bureau, subjectType, division, subject],\n\t\t\tlabels,\n\t\t};\n\t}\n\n\texport function format({\n\t\tbureau,\n\t\tsubjectType,\n\t\tdivision,\n\t\tsubject,\n\t\tchecksum,\n\t}: {\n\t\tbureau: string;\n\t\tsubjectType: string;\n\t\tdivision: string;\n\t\tsubject: string;\n\t\tchecksum?: string;\n\t}): string {\n\t\tconst base = `${bureau}${subjectType}${division}${subject}`;\n\t\tchecksum ||= Checksum.compute(base);\n\t\treturn `${base}${checksum}`;\n\t}\n\n\texport function next(s: string, delta: number = 1) {\n\t\tconst sp = s.split('').map((v) => Checksum.numbers[v]);\n\t\tfor (let i = sp.length - 1; i >= 0; i--) {\n\t\t\tif ((delta > 0 && sp[i] < 30) || (delta < 0 && sp[i] > 0)) {\n\t\t\t\tsp[i] += delta;\n\t\t\t\tbreak;\n\t\t\t} else if (delta > 0 && sp[i] === 30) {\n\t\t\t\tsp[i] = 0;\n\t\t\t} else if (delta < 0 && sp[i] === 0) {\n\t\t\t\tsp[i] = 30;\n\t\t\t}\n\t\t}\n\t\treturn sp.map((v) => Checksum.chars[v]).join('');\n\t}\n}\n\n/**\n * 解析后的统一社会信用代码信息\n */\ninterface ParsedUnifiedSocialCreditCode {\n\t/**\n\t * @title 登记管理部门代码\n\t * 对应统一社会信用代码的第1位字符,用于标识发证机构类别(登记管理部门)。\n\t */\n\tbureau: string;\n\n\t/**\n\t * @title 机构类别代码\n\t * 对应统一社会信用代码的第2位字符,用于标识被赋码主体的类型(如企业、事业单位、社会组织等)。\n\t */\n\tsubjectType: string;\n\n\t/**\n\t * @title 登记管理机关行政区划代码\n\t * 对应统一社会信用代码的第3至第8位字符,用于标识该主体登记机关所在的行政区划。\n\t */\n\tdivision: string;\n\n\t/**\n\t * @title 主体标识码\n\t * 对应统一社会信用代码的第9至第17位字符,用于标识特定的市场主体或法人单位。\n\t */\n\tsubject: string;\n\n\t/**\n\t * @title 校验码\n\t * 对应统一社会信用代码的最后一位字符,用特定算法计算,用于校验代码有效性。\n\t */\n\tchecksum: string;\n\n\tcodes: string[];\n\tlabels: string[];\n}\n"],"names":["Mod31Checksum","UnifiedSocialCreditCode","CodeLabels","label","children","Y","pattern","Checksum","parse","s","bureau","subjectType","division","slice","subject","checksum","labels","l1","push","l2","codes","format","base","compute","next","delta","sp","split","map","v","numbers","i","length","chars","join"],"mappings":"AAAA,SAASA,aAAa,QAAQ,kBAAkB;UAO/BC;IAMhB,MAAMC,aAAwC;QAC7C,GAAG;YACFC,OAAO;YACPC,UAAU;gBACT,GAAG;oBAAED,OAAO;gBAAK;gBACjB,GAAG;oBAAEA,OAAO;gBAAO;gBACnB,GAAG;oBAAEA,OAAO;gBAAoB;gBA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ACPC,QAAQ,EAOR;QACA,MAAMO,OAAO,GAAGZ,SAASC,cAAcC,WAAWE,SAAS;QAC3DC,aAAaR,wBAAAA,SAASgB,OAAO,CAACD;QAC9B,OAAO,GAAGA,OAAOP,UAAU;IAC5B;4BAhBgBM,SAAAA;IAkBT,SAASG,KAAKf,CAAS,EAAEgB,QAAgB,CAAC;QAChD,MAAMC,KAAKjB,EAAEkB,KAAK,CAAC,IAAIC,GAAG,CAAC,CAACC,IAAMtB,wBAAAA,SAASuB,OAAO,CAACD,EAAE;QACrD,IAAK,IAAIE,IAAIL,GAAGM,MAAM,GAAG,GAAGD,KAAK,GAAGA,IAAK;YACxC,IAAI,AAACN,QAAQ,KAAKC,EAAE,CAACK,EAAE,GAAG,MAAQN,QAAQ,KAAKC,EAAE,CAACK,EAAE,GAAG,GAAI;gBAC1DL,EAAE,CAACK,EAAE,IAAIN;gBACT;YACD,OAAO,IAAIA,QAAQ,KAAKC,EAAE,CAACK,EAAE,KAAK,IAAI;gBACrCL,EAAE,CAACK,EAAE,GAAG;YACT,OAAO,IAAIN,QAAQ,KAAKC,EAAE,CAACK,EAAE,KAAK,GAAG;gBACpCL,EAAE,CAACK,EAAE,GAAG;YACT;QACD;QACA,OAAOL,GAAGE,GAAG,CAAC,CAACC,IAAMtB,wBAAAA,SAAS0B,KAAK,CAACJ,EAAE,EAAEK,IAAI,CAAC;IAC9C;4BAbgBV,OAAAA;AAcjB,GAjGiBvB,4BAAAA"}
@@ -1,15 +0,0 @@
1
- export function formatDate(date, format) {
2
- switch(format){
3
- case 'yyyyMMDD':
4
- {
5
- const year = date.getFullYear();
6
- const month = (date.getMonth() + 1).toString().padStart(2, '0');
7
- const day = date.getDate().toString().padStart(2, '0');
8
- return `${year}${month}${day}`;
9
- }
10
- default:
11
- throw new Error(`Invalid format`);
12
- }
13
- }
14
-
15
- //# sourceMappingURL=formatDate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/cn/formatDate.ts"],"sourcesContent":["export function formatDate(date: Date, format: 'yyyyMMDD') {\n\tswitch (format) {\n\t\tcase 'yyyyMMDD': {\n\t\t\tconst year = date.getFullYear();\n\t\t\tconst month = (date.getMonth() + 1).toString().padStart(2, '0');\n\t\t\tconst day = date.getDate().toString().padStart(2, '0');\n\t\t\treturn `${year}${month}${day}`;\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`Invalid format`);\n\t}\n}\n"],"names":["formatDate","date","format","year","getFullYear","month","getMonth","toString","padStart","day","getDate","Error"],"mappings":"AAAA,OAAO,SAASA,WAAWC,IAAU,EAAEC,MAAkB;IACxD,OAAQA;QACP,KAAK;YAAY;gBAChB,MAAMC,OAAOF,KAAKG,WAAW;gBAC7B,MAAMC,QAAQ,AAACJ,CAAAA,KAAKK,QAAQ,KAAK,CAAA,EAAGC,QAAQ,GAAGC,QAAQ,CAAC,GAAG;gBAC3D,MAAMC,MAAMR,KAAKS,OAAO,GAAGH,QAAQ,GAAGC,QAAQ,CAAC,GAAG;gBAClD,OAAO,GAAGL,OAAOE,QAAQI,KAAK;YAC/B;QACA;YACC,MAAM,IAAIE,MAAM,CAAC,cAAc,CAAC;IAClC;AACD"}