@wener/common 1.0.3 → 1.0.5

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 (109) hide show
  1. package/lib/cn/DivisionCode.js.map +1 -1
  2. package/lib/cn/Mod11Checksum.js.map +1 -1
  3. package/lib/cn/Mod31Checksum.js.map +1 -1
  4. package/lib/cn/ResidentIdentityCardNumber.js.map +1 -1
  5. package/lib/cn/UnifiedSocialCreditCode.js.map +1 -1
  6. package/lib/cn/formatDate.js.map +1 -1
  7. package/lib/cn/parseSex.js.map +1 -1
  8. package/lib/cn/types.d.js.map +1 -1
  9. package/lib/consola/createStandardConsolaReporter.js +18 -0
  10. package/lib/consola/createStandardConsolaReporter.js.map +1 -0
  11. package/lib/consola/formatLogObject.js +125 -0
  12. package/lib/consola/formatLogObject.js.map +1 -0
  13. package/lib/consola/index.js +3 -0
  14. package/lib/consola/index.js.map +1 -0
  15. package/lib/data/formatSort.js +15 -0
  16. package/lib/data/formatSort.js.map +1 -0
  17. package/lib/data/index.js +4 -0
  18. package/lib/data/index.js.map +1 -0
  19. package/lib/data/maybeNumber.js +22 -0
  20. package/lib/data/maybeNumber.js.map +1 -0
  21. package/lib/data/parseSort.js +95 -0
  22. package/lib/data/parseSort.js.map +1 -0
  23. package/lib/data/resolvePagination.js +36 -0
  24. package/lib/data/resolvePagination.js.map +1 -0
  25. package/lib/data/types.d.js +3 -0
  26. package/lib/data/types.d.js.map +1 -0
  27. package/lib/index.js +6 -2
  28. package/lib/index.js.map +1 -1
  29. package/lib/jsonschema/JsonSchema.js +6 -6
  30. package/lib/jsonschema/JsonSchema.js.map +1 -1
  31. package/lib/jsonschema/types.d.js.map +1 -1
  32. package/lib/meta/defineFileType.js.map +1 -1
  33. package/lib/meta/defineInit.js.map +1 -1
  34. package/lib/meta/defineMetadata.js.map +1 -1
  35. package/lib/password/PHC.js +8 -8
  36. package/lib/password/PHC.js.map +1 -1
  37. package/lib/password/Password.js.map +1 -1
  38. package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -1
  39. package/lib/password/createBase64PasswordAlgorithm.js.map +1 -1
  40. package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -1
  41. package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -1
  42. package/lib/password/createScryptPasswordAlgorithm.js.map +1 -1
  43. package/lib/search/AdvanceSearch.js.map +1 -1
  44. package/lib/search/formatAdvanceSearch.js.map +1 -1
  45. package/lib/search/optimizeAdvanceSearch.js.map +1 -1
  46. package/lib/search/parseAdvanceSearch.js.map +1 -1
  47. package/lib/search/parser.d.js.map +1 -1
  48. package/lib/search/types.d.js.map +1 -1
  49. package/lib/tools/generateSchema.js +43 -0
  50. package/lib/tools/generateSchema.js.map +1 -0
  51. package/lib/tools/renderJsonSchemaToMarkdownDoc.js.map +1 -1
  52. package/package.json +19 -5
  53. package/src/cn/DivisionCode.test.ts +38 -45
  54. package/src/cn/DivisionCode.ts +140 -184
  55. package/src/cn/Mod11Checksum.ts +17 -17
  56. package/src/cn/Mod31Checksum.ts +25 -25
  57. package/src/cn/ResidentIdentityCardNumber.test.ts +12 -16
  58. package/src/cn/ResidentIdentityCardNumber.ts +82 -82
  59. package/src/cn/UnifiedSocialCreditCode.test.ts +11 -11
  60. package/src/cn/UnifiedSocialCreditCode.ts +115 -120
  61. package/src/cn/__snapshots__/ResidentIdentityCardNumber.test.ts.snap +1 -1
  62. package/src/cn/formatDate.ts +10 -10
  63. package/src/cn/parseSex.ts +11 -25
  64. package/src/cn/types.d.ts +43 -43
  65. package/src/consola/createStandardConsolaReporter.ts +31 -0
  66. package/src/consola/formatLogObject.ts +171 -0
  67. package/src/consola/index.ts +2 -0
  68. package/src/data/formatSort.test.ts +13 -0
  69. package/src/data/formatSort.ts +18 -0
  70. package/src/data/index.ts +5 -0
  71. package/src/data/maybeNumber.ts +23 -0
  72. package/src/data/parseSort.test.ts +67 -0
  73. package/src/data/parseSort.ts +108 -0
  74. package/src/data/resolvePagination.test.ts +58 -0
  75. package/src/data/resolvePagination.ts +60 -0
  76. package/src/data/types.d.ts +33 -0
  77. package/src/index.ts +8 -2
  78. package/src/jsonschema/JsonSchema.test.ts +13 -22
  79. package/src/jsonschema/JsonSchema.ts +146 -178
  80. package/src/jsonschema/types.d.ts +151 -161
  81. package/src/meta/defineFileType.tsx +54 -54
  82. package/src/meta/defineInit.ts +32 -53
  83. package/src/meta/defineMetadata.test.ts +5 -7
  84. package/src/meta/defineMetadata.ts +28 -46
  85. package/src/password/PHC.test.ts +186 -277
  86. package/src/password/PHC.ts +243 -243
  87. package/src/password/Password.test.ts +38 -50
  88. package/src/password/Password.ts +73 -95
  89. package/src/password/createArgon2PasswordAlgorithm.ts +65 -69
  90. package/src/password/createBase64PasswordAlgorithm.ts +9 -9
  91. package/src/password/createBcryptPasswordAlgorithm.ts +20 -22
  92. package/src/password/createPBKDF2PasswordAlgorithm.ts +49 -61
  93. package/src/password/createScryptPasswordAlgorithm.ts +48 -59
  94. package/src/search/AdvanceSearch.test.ts +136 -143
  95. package/src/search/AdvanceSearch.ts +6 -6
  96. package/src/search/formatAdvanceSearch.ts +44 -53
  97. package/src/search/optimizeAdvanceSearch.ts +70 -83
  98. package/src/search/parseAdvanceSearch.ts +16 -19
  99. package/src/search/parser.d.ts +3 -3
  100. package/src/search/types.d.ts +28 -54
  101. package/src/tools/generateSchema.ts +39 -0
  102. package/src/tools/renderJsonSchemaToMarkdownDoc.ts +69 -69
  103. package/lib/normalizePagination.js +0 -14
  104. package/lib/normalizePagination.js.map +0 -1
  105. package/lib/parseSort.js +0 -106
  106. package/lib/parseSort.js.map +0 -1
  107. package/src/normalizePagination.ts +0 -25
  108. package/src/parseSort.test.ts +0 -42
  109. package/src/parseSort.ts +0 -133
@@ -0,0 +1,43 @@
1
+ import { exec } from "node:child_process";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import * as Codegen from "@sinclair/typebox-codegen";
5
+ export async function generateSchema({ file, dir = path.dirname(file) }) {
6
+ const fn = path.basename(file).replace(/\.d\.ts$/, '.ts');
7
+ const types = await fs.readFile(file, 'utf-8');
8
+ const typeboxDir = path.join(dir, 'typebox');
9
+ const zodDir = path.join(dir, 'zod');
10
+ await fs.mkdir(typeboxDir, {
11
+ recursive: true
12
+ });
13
+ await fs.mkdir(zodDir, {
14
+ recursive: true
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));
26
+ await new Promise((resolve, reject)=>{
27
+ exec(`pnpm prettier --write "${dir}/{typebox,zod}/*.ts"`, (error, stdout, stderr)=>{
28
+ if (error) {
29
+ console.error(`exec error: ${error}`);
30
+ reject(error);
31
+ return;
32
+ }
33
+ resolve({
34
+ stderr,
35
+ stdout
36
+ });
37
+ stdout && console.log(`prettier:stdout: ${stdout}`);
38
+ stderr && console.error(`prettier:stderr: ${stderr}`);
39
+ });
40
+ });
41
+ }
42
+
43
+ //# sourceMappingURL=generateSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/tools/generateSchema.ts"],"sourcesContent":["import { exec } from 'node:child_process';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport * as Codegen from '@sinclair/typebox-codegen';\n\nexport async function generateSchema({ file, dir = path.dirname(file) }: { file: string; dir?: string }) {\n const fn = path.basename(file).replace(/\\.d\\.ts$/, '.ts');\n const types = await fs.readFile(file, 'utf-8');\n\n const typeboxDir = path.join(dir, 'typebox');\n const zodDir = path.join(dir, 'zod');\n\n await fs.mkdir(typeboxDir, { recursive: true });\n await fs.mkdir(zodDir, { recursive: true });\n\n const typeBoxFile = path.join(typeboxDir, fn);\n const zodFile = path.join(zodDir, fn);\n {\n // avoid import type error\n let out = Codegen.TypeScriptToTypeBox.Generate(types);\n out = out.replace(/^import \\{ Type, Static\\b/, `import { Type, type Static`);\n await fs.writeFile(typeBoxFile, out);\n }\n const model = Codegen.TypeScriptToModel.Generate(types);\n await fs.writeFile(zodFile, Codegen.ModelToZod.Generate(model));\n\n await new Promise((resolve, reject) => {\n exec(`pnpm prettier --write \"${dir}/{typebox,zod}/*.ts\"`, (error, stdout, stderr) => {\n if (error) {\n console.error(`exec error: ${error}`);\n reject(error);\n return;\n }\n resolve({ stderr, stdout });\n stdout && console.log(`prettier:stdout: ${stdout}`);\n stderr && console.error(`prettier:stderr: ${stderr}`);\n });\n });\n}\n"],"names":["exec","fs","path","Codegen","generateSchema","file","dir","dirname","fn","basename","replace","types","readFile","typeboxDir","join","zodDir","mkdir","recursive","typeBoxFile","zodFile","out","TypeScriptToTypeBox","Generate","writeFile","model","TypeScriptToModel","ModelToZod","Promise","resolve","reject","error","stdout","stderr","console","log"],"mappings":"AAAA,SAASA,IAAI,QAAQ,qBAAqB;AAC1C,OAAOC,QAAQ,mBAAmB;AAClC,OAAOC,UAAU,YAAY;AAC7B,YAAYC,aAAa,4BAA4B;AAErD,OAAO,eAAeC,eAAe,EAAEC,IAAI,EAAEC,MAAMJ,KAAKK,OAAO,CAACF,KAAK,EAAkC;IACrG,MAAMG,KAAKN,KAAKO,QAAQ,CAACJ,MAAMK,OAAO,CAAC,YAAY;IACnD,MAAMC,QAAQ,MAAMV,GAAGW,QAAQ,CAACP,MAAM;IAEtC,MAAMQ,aAAaX,KAAKY,IAAI,CAACR,KAAK;IAClC,MAAMS,SAASb,KAAKY,IAAI,CAACR,KAAK;IAE9B,MAAML,GAAGe,KAAK,CAACH,YAAY;QAAEI,WAAW;IAAK;IAC7C,MAAMhB,GAAGe,KAAK,CAACD,QAAQ;QAAEE,WAAW;IAAK;IAEzC,MAAMC,cAAchB,KAAKY,IAAI,CAACD,YAAYL;IAC1C,MAAMW,UAAUjB,KAAKY,IAAI,CAACC,QAAQP;IAClC;QACE,0BAA0B;QAC1B,IAAIY,MAAMjB,QAAQkB,mBAAmB,CAACC,QAAQ,CAACX;QAC/CS,MAAMA,IAAIV,OAAO,CAAC,6BAA6B,CAAC,0BAA0B,CAAC;QAC3E,MAAMT,GAAGsB,SAAS,CAACL,aAAaE;IAClC;IACA,MAAMI,QAAQrB,QAAQsB,iBAAiB,CAACH,QAAQ,CAACX;IACjD,MAAMV,GAAGsB,SAAS,CAACJ,SAAShB,QAAQuB,UAAU,CAACJ,QAAQ,CAACE;IAExD,MAAM,IAAIG,QAAQ,CAACC,SAASC;QAC1B7B,KAAK,CAAC,uBAAuB,EAAEM,IAAI,oBAAoB,CAAC,EAAE,CAACwB,OAAOC,QAAQC;YACxE,IAAIF,OAAO;gBACTG,QAAQH,KAAK,CAAC,CAAC,YAAY,EAAEA,OAAO;gBACpCD,OAAOC;gBACP;YACF;YACAF,QAAQ;gBAAEI;gBAAQD;YAAO;YACzBA,UAAUE,QAAQC,GAAG,CAAC,CAAC,iBAAiB,EAAEH,QAAQ;YAClDC,UAAUC,QAAQH,KAAK,CAAC,CAAC,iBAAiB,EAAEE,QAAQ;QACtD;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/tools/renderJsonSchemaToMarkdownDoc.ts"],"sourcesContent":["import type { TObject, TSchema } from '@sinclair/typebox';\n\nexport function renderJsonSchemaToMarkdownDoc(rootSchema: any) {\n // markdown\n const out: string[] = [];\n const all = new Set();\n const pending: TSchema[] = [];\n\n const addObject = (o: TSchema) => {\n if (all.has(o.$id)) {\n return;\n }\n all.add(o.$id);\n pending.push(o);\n };\n\n const writeObjectProps = (T: TObject, { prefix = '' }: { prefix?: string } = {}) => {\n if (!T?.properties) {\n return;\n }\n for (const [name, schema] of Object.entries(T.properties)) {\n let typ = schema.$id || schema.type;\n\n if (typ === 'array') {\n typ = `${schema.items.$id || schema.items.type}[]`;\n if (schema.items.$id) {\n addObject(schema.items);\n }\n } else if (schema.$id) {\n addObject(schema);\n }\n if (!typ) {\n if ('anyOf' in schema) {\n typ = 'enum';\n }\n }\n\n out.push(`| ${prefix}${name} | ${typ} | ${schema.title || schema.description || ''} |`);\n\n if (typ === 'object') {\n writeObjectProps(schema as TObject, { prefix: `${prefix}${name}.` });\n } else if (schema.type === 'array') {\n if (schema.items.type === 'object' && !schema.items.$id) {\n writeObjectProps(schema.items as TObject, { prefix: `${prefix}${name}[].` });\n }\n }\n }\n };\n const writeObject = (T: TObject) => {\n out.push(`### ${T.title || T.$id}`);\n out.push(`\n| $id | 名字 |\n| --- | --- |\n| ${T.$id || ''} | ${T.title || ''} | \n `);\n if (T.description) {\n out.push('');\n out.push(`> ${T.description}`);\n out.push('');\n }\n\n out.push(`| 名字 | 类型 | 说明 |`);\n out.push(`| --- | --- | --- |`);\n\n writeObjectProps(T);\n\n out.push('');\n };\n\n writeObject(rootSchema);\n\n for (const schema of pending) {\n if (schema.type === 'object') {\n writeObject(schema as TObject);\n } else if ('anyOf' in schema) {\n out.push(`### ${schema.$id || schema.title}`);\n out.push(`\n| $id | 名字 |\n| --- | --- |\n| ${schema.$id || ''} | ${schema.title || ''} | \n `);\n\n out.push(`| 值 | 说明 |`);\n out.push(`| --- | --- |`);\n for (const item of schema.anyOf) {\n out.push(`| ${item.const} | ${item.title || item.description || ''} |`);\n }\n out.push('');\n }\n }\n\n return out.join('\\n');\n}\n"],"names":["renderJsonSchemaToMarkdownDoc","rootSchema","out","all","Set","pending","addObject","o","has","$id","add","push","writeObjectProps","T","prefix","properties","name","schema","Object","entries","typ","type","items","title","description","writeObject","item","anyOf","const","join"],"mappings":"AAEA,OAAO,SAASA,8BAA8BC,UAAe;IAC3D,WAAW;IACX,MAAMC,MAAgB,EAAE;IACxB,MAAMC,MAAM,IAAIC;IAChB,MAAMC,UAAqB,EAAE;IAE7B,MAAMC,YAAY,CAACC;QACjB,IAAIJ,IAAIK,GAAG,CAACD,EAAEE,G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3,"sources":["../../src/tools/renderJsonSchemaToMarkdownDoc.ts"],"sourcesContent":["import type { TObject, TSchema } from '@sinclair/typebox';\n\nexport function renderJsonSchemaToMarkdownDoc(rootSchema: any) {\n\t// markdown\n\tconst out: string[] = [];\n\tconst all = new Set();\n\tconst pending: TSchema[] = [];\n\n\tconst addObject = (o: TSchema) => {\n\t\tif (all.has(o.$id)) {\n\t\t\treturn;\n\t\t}\n\t\tall.add(o.$id);\n\t\tpending.push(o);\n\t};\n\n\tconst writeObjectProps = (T: TObject, { prefix = '' }: { prefix?: string } = {}) => {\n\t\tif (!T?.properties) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const [name, schema] of Object.entries(T.properties)) {\n\t\t\tlet typ = schema.$id || schema.type;\n\n\t\t\tif (typ === 'array') {\n\t\t\t\ttyp = `${schema.items.$id || schema.items.type}[]`;\n\t\t\t\tif (schema.items.$id) {\n\t\t\t\t\taddObject(schema.items);\n\t\t\t\t}\n\t\t\t} else if (schema.$id) {\n\t\t\t\taddObject(schema);\n\t\t\t}\n\t\t\tif (!typ) {\n\t\t\t\tif ('anyOf' in schema) {\n\t\t\t\t\ttyp = 'enum';\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tout.push(`| ${prefix}${name} | ${typ} | ${schema.title || schema.description || ''} |`);\n\n\t\t\tif (typ === 'object') {\n\t\t\t\twriteObjectProps(schema as TObject, { prefix: `${prefix}${name}.` });\n\t\t\t} else if (schema.type === 'array') {\n\t\t\t\tif (schema.items.type === 'object' && !schema.items.$id) {\n\t\t\t\t\twriteObjectProps(schema.items as TObject, { prefix: `${prefix}${name}[].` });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\tconst writeObject = (T: TObject) => {\n\t\tout.push(`### ${T.title || T.$id}`);\n\t\tout.push(`\n| $id | 名字 |\n| --- | --- |\n| ${T.$id || ''} | ${T.title || ''} | \n `);\n\t\tif (T.description) {\n\t\t\tout.push('');\n\t\t\tout.push(`> ${T.description}`);\n\t\t\tout.push('');\n\t\t}\n\n\t\tout.push(`| 名字 | 类型 | 说明 |`);\n\t\tout.push(`| --- | --- | --- |`);\n\n\t\twriteObjectProps(T);\n\n\t\tout.push('');\n\t};\n\n\twriteObject(rootSchema);\n\n\tfor (const schema of pending) {\n\t\tif (schema.type === 'object') {\n\t\t\twriteObject(schema as TObject);\n\t\t} else if ('anyOf' in schema) {\n\t\t\tout.push(`### ${schema.$id || schema.title}`);\n\t\t\tout.push(`\n| $id | 名字 |\n| --- | --- |\n| ${schema.$id || ''} | ${schema.title || ''} | \n `);\n\n\t\t\tout.push(`| 值 | 说明 |`);\n\t\t\tout.push(`| --- | --- |`);\n\t\t\tfor (const item of schema.anyOf) {\n\t\t\t\tout.push(`| ${item.const} | ${item.title || item.description || ''} |`);\n\t\t\t}\n\t\t\tout.push('');\n\t\t}\n\t}\n\n\treturn out.join('\\n');\n}\n"],"names":["renderJsonSchemaToMarkdownDoc","rootSchema","out","all","Set","pending","addObject","o","has","$id","add","push","writeObjectProps","T","prefix","properties","name","schema","Object","entries","typ","type","items","title","description","writeObject","item","anyOf","const","join"],"mappings":"AAEA,OAAO,SAASA,8BAA8BC,UAAe;IAC5D,WAAW;IACX,MAAMC,MAAgB,EAAE;IACxB,MAAMC,MAAM,IAAIC;IAChB,MAAMC,UAAqB,EAAE;IAE7B,MAAMC,YAAY,CAACC;QAClB,IAAIJ,IAAIK,GAAG,CAACD,EAAEE,GAAG,GAAG;YACnB;QACD;QACAN,IAAIO,GAAG,CAACH,EAAEE,GAAG;QACbJ,QAAQM,IAAI,CAACJ;IACd;IAEA,MAAMK,mBAAmB,CAACC,GAAY,EAAEC,SAAS,EAAE,EAAuB,GAAG,CAAC,CAAC;QAC9E,IAAI,CAACD,GAAGE,YAAY;YACnB;QACD;QACA,KAAK,MAAM,CAACC,MAAMC,OAAO,IAAIC,OAAOC,OAAO,CAACN,EAAEE,UAAU,EAAG;YAC1D,IAAIK,MAAMH,OAAOR,GAAG,IAAIQ,OAAOI,IAAI;Y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AC;QACV;QAEAT,IAAIS,IAAI,CAAC,CAAC,gBAAgB,CAAC;QAC3BT,IAAIS,IAAI,CAAC,CAAC,mBAAmB,CAAC;QAE9BC,iBAAiBC;QAEjBX,IAAIS,IAAI,CAAC;IACV;IAEAc,YAAYxB;IAEZ,KAAK,MAAMgB,UAAUZ,QAAS;QAC7B,IAAIY,OAAOI,IAAI,KAAK,UAAU;YAC7BI,YAAYR;QACb,OAAO,IAAI,WAAWA,QAAQ;YAC7Bf,IAAIS,IAAI,CAAC,CAAC,IAAI,EAAEM,OAAOR,GAAG,IAAIQ,OAAOM,KAAK,EAAE;YAC5CrB,IAAIS,IAAI,CAAC,CAAC;;;EAGX,EAAEM,OAAOR,GAAG,IAAI,GAAG,GAAG,EAAEQ,OAAOM,KAAK,IAAI,GAAG;IACzC,CAAC;YAEFrB,IAAIS,IAAI,CAAC,CAAC,WAAW,CAAC;YACtBT,IAAIS,IAAI,CAAC,CAAC,aAAa,CAAC;YACxB,KAAK,MAAMe,QAAQT,OAAOU,KAAK,CAAE;gBAChCzB,IAAIS,IAAI,CAAC,CAAC,EAAE,EAAEe,KAAKE,KAAK,CAAC,GAAG,EAAEF,KAAKH,KAAK,IAAIG,KAAKF,WAAW,IAAI,GAAG,EAAE,CAAC;YACvE;YACAtB,IAAIS,IAAI,CAAC;QACV;IACD;IAEA,OAAOT,IAAI2B,IAAI,CAAC;AACjB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wener/common",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "author": "",
@@ -14,6 +14,14 @@
14
14
  "types": "./src/cn/index.ts",
15
15
  "default": "./lib/cn/index.js"
16
16
  },
17
+ "./consola": {
18
+ "types": "./src/consola/index.ts",
19
+ "default": "./lib/consola/index.js"
20
+ },
21
+ "./data": {
22
+ "types": "./src/data/index.ts",
23
+ "default": "./lib/data/index.js"
24
+ },
17
25
  "./jsonschema": {
18
26
  "types": "./src/jsonschema/index.ts",
19
27
  "default": "./lib/jsonschema/index.js"
@@ -40,12 +48,15 @@
40
48
  ],
41
49
  "keywords": [],
42
50
  "dependencies": {
43
- "es-toolkit": "^1.31.0",
44
- "ts-pattern": "^5.6.0",
51
+ "es-toolkit": "^1.32.0",
52
+ "std-env": "^3.8.1",
53
+ "ts-pattern": "^5.6.2",
54
+ "zod": "^3.24.2",
45
55
  "@wener/utils": "1.1.51"
46
56
  },
47
57
  "devDependencies": {
48
- "@sinclair/typebox": "^0.34.13",
58
+ "@sinclair/typebox": "^0.34.28",
59
+ "@sinclair/typebox-codegen": "^0.10.5",
49
60
  "@types/argon2-browser": "^1.18.4",
50
61
  "@types/bcrypt": "^5.0.2",
51
62
  "@types/bcryptjs": "^2.4.6",
@@ -56,7 +67,10 @@
56
67
  "argon2": "^0.41.1",
57
68
  "argon2-browser": "^1.18.0",
58
69
  "bcrypt": "^5.1.1",
59
- "bcryptjs": "^2.4.3"
70
+ "bcryptjs": "^3.0.2",
71
+ "chalk": "^5.4.1",
72
+ "consola": "^3.4.2",
73
+ "dayjs": "^1.11.13"
60
74
  },
61
75
  "scripts": {
62
76
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -2,49 +2,42 @@ import { describe, expect, it } from 'vitest';
2
2
  import { DivisionCode } from './DivisionCode';
3
3
 
4
4
  describe('DivisionCode', () => {
5
- it('should parse', () => {
6
- for (const [a, b] of [
7
- [
8
- '441900003001',
9
- {
10
- province: '44',
11
- city: '19',
12
- county: '00',
13
- town: '003',
14
- village: '001',
15
- codes: ['44', '19', '00', '003', '001'],
16
- },
17
- ],
18
- [
19
- 441900003001,
20
- {
21
- province: '44',
22
- city: '19',
23
- county: '00',
24
- town: '003',
25
- village: '001',
26
- codes: ['44', '19', '00', '003', '001'],
27
- },
28
- ],
29
- [
30
- 441900,
31
- {
32
- province: '44',
33
- city: '19',
34
- county: '00',
35
- },
36
- ],
37
- ['31', { province: '31' }],
38
- ['4', undefined],
39
- ['', undefined],
40
- [null, undefined],
41
- [undefined, undefined],
42
- ] as Array<[string, any]>) {
43
- let out = DivisionCode.parse(a);
44
- expect(out).toMatchObject(b);
45
- if (out) {
46
- expect(DivisionCode.format(out)).toBe(String(a));
47
- }
48
- }
49
- });
5
+ it('should parse', () => {
6
+ for (const [a, b] of [
7
+ [
8
+ '441900003001',
9
+ {
10
+ province: '44',
11
+ city: '19',
12
+ county: '00',
13
+ town: '003',
14
+ village: '001',
15
+ codes: ['44', '19', '00', '003', '001'],
16
+ },
17
+ ],
18
+ [
19
+ 441900003001,
20
+ {
21
+ province: '44',
22
+ city: '19',
23
+ county: '00',
24
+ town: '003',
25
+ village: '001',
26
+ codes: ['44', '19', '00', '003', '001'],
27
+ },
28
+ ],
29
+ [441900, { province: '44', city: '19', county: '00' }],
30
+ ['31', { province: '31' }],
31
+ ['4', undefined],
32
+ ['', undefined],
33
+ [null, undefined],
34
+ [undefined, undefined],
35
+ ] as Array<[string, any]>) {
36
+ let out = DivisionCode.parse(a);
37
+ expect(out).toMatchObject(b);
38
+ if (out) {
39
+ expect(DivisionCode.format(out)).toBe(String(a));
40
+ }
41
+ }
42
+ });
50
43
  });
@@ -1,45 +1,9 @@
1
- const DivisionCodeLevels: Array<{
2
- level: number;
3
- code: string;
4
- length: number;
5
- size: number;
6
- label: string;
7
- }> = [
8
- {
9
- level: 1,
10
- code: 'Province',
11
- length: 2,
12
- size: 2,
13
- label: '省',
14
- },
15
- {
16
- level: 2,
17
- code: 'City',
18
- length: 4,
19
- size: 2,
20
- label: '市',
21
- },
22
- {
23
- level: 3,
24
- code: 'County',
25
- length: 6,
26
- size: 2,
27
- label: '区县',
28
- },
29
- {
30
- level: 4,
31
- code: 'Town',
32
- length: 9,
33
- size: 3,
34
- label: '乡镇',
35
- },
36
- {
37
- level: 5,
38
- code: 'Village',
39
- length: 12,
40
- size: 3,
41
- label: '村',
42
- },
1
+ const DivisionCodeLevels: Array<{ level: number; code: string; length: number; size: number; label: string }> = [
2
+ { level: 1, code: 'Province', length: 2, size: 2, label: '省' },
3
+ { level: 2, code: 'City', length: 4, size: 2, label: '市' },
4
+ { level: 3, code: 'County', length: 6, size: 2, label: '区县' },
5
+ { level: 4, code: 'Town', length: 9, size: 3, label: '乡镇' },
6
+ { level: 5, code: 'Village', length: 12, size: 3, label: '村' },
43
7
  ] as const;
44
8
 
45
9
  // String(Number.MAX_SAFE_INTEGER).length=16
@@ -51,128 +15,120 @@ const DivisionCodeLevels: Array<{
51
15
  * @see https://zh.wikipedia.org/wiki/GB/T_2260 中华人民共和国行政区划代码
52
16
  */
53
17
  export namespace DivisionCode {
54
- enum DivisionCodeLevel {
55
- Province = 1,
56
- City = 2,
57
- County = 3,
58
- Town = 4,
59
- Village = 5,
60
- }
61
-
62
- export const levels = DivisionCodeLevels;
63
-
64
- export const regex = /^(?<province>\d{2})(?<city>\d{2})?(?<county>\d{2})?(?<town>\d{3})?(?<village>\d{3})?$/;
65
-
66
- const root: CodeValue[] = [
67
- { value: '11', label: '北京市' },
68
- { value: '12', label: '天津市' },
69
- { value: '13', label: '河北省' },
70
- { value: '14', label: '山西省' },
71
- { value: '15', label: '内蒙古自治区' },
72
- { value: '21', label: '辽宁省' },
73
- { value: '22', label: '吉林省' },
74
- { value: '23', label: '黑龙江省' },
75
- { value: '31', label: '上海市' },
76
- { value: '32', label: '江苏省' },
77
- { value: '33', label: '浙江省' },
78
- { value: '34', label: '安徽省' },
79
- { value: '35', label: '福建省' },
80
- { value: '36', label: '江西省' },
81
- { value: '37', label: '山东省' },
82
- { value: '41', label: '河南省' },
83
- { value: '42', label: '湖北省' },
84
- { value: '43', label: '湖南省' },
85
- { value: '44', label: '广东省' },
86
- { value: '45', label: '广西壮族自治区' },
87
- { value: '46', label: '海南省' },
88
- { value: '50', label: '重庆市' },
89
- { value: '51', label: '四川省' },
90
- { value: '52', label: '贵州省' },
91
- { value: '53', label: '云南省' },
92
- { value: '54', label: '西藏自治区' },
93
- { value: '61', label: '陕西省' },
94
- { value: '62', label: '甘肃省' },
95
- { value: '63', label: '青海省' },
96
- { value: '64', label: '宁夏回族自治区' },
97
- { value: '65', label: '新疆维吾尔自治区' },
98
- { value: '71', label: '台湾省' },
99
- { value: '81', label: '香港特别行政区' },
100
- { value: '82', label: '澳门特别行政区' },
101
- // 9 国外
102
- ];
103
-
104
- export type ParsedCode = {
105
- province: string;
106
- city?: string;
107
- county?: string;
108
- town?: string;
109
- village?: string;
110
- codes: string[];
111
- level: DivisionCodeLevel;
112
- labels: string[];
113
- };
114
-
115
- export function parse(code: string | undefined | null | number): ParsedCode | undefined {
116
- if (!code) return;
117
- code = String(code);
118
- const match = regex.exec(code);
119
- if (!match) return;
120
- const { province, city, county, town, village } = match.groups ?? {};
121
- if (!province) return;
122
-
123
- let codes = [province, city, county, town, village].filter(Boolean);
124
- return {
125
- province,
126
- city,
127
- county,
128
- town,
129
- village,
130
- codes: codes,
131
- level: codes.length as DivisionCodeLevel,
132
- };
133
- }
134
-
135
- export function format({
136
- province,
137
- city,
138
- county,
139
- town,
140
- village,
141
- }: {
142
- province: string | number;
143
- city?: string | number;
144
- county?: string | number;
145
- town?: string | number;
146
- village?: string | number;
147
- }): string {
148
- const codes: string[] = [];
149
- for (let i = 0; i < [province, city, county, town, village].length; i++) {
150
- let x = [province, city, county, town, village][i];
151
- if (x === undefined || x === null || x === '') {
152
- break;
153
- }
154
- let len = levels[i].size;
155
- codes.push(String(x).padStart(len, '0').slice(0, len));
156
- }
157
- return codes.join('');
158
- }
159
-
160
- // export function random(level: DivisionCodeLevel = 'County'): string {
161
- // const l = DivisionCodeLevels.find((v) => v.code === level) || DivisionCodeLevels[2];
162
- // const l1 = randomPick(provinces);
163
- // if (l.level === 1) {
164
- // return String(l1[0]);
165
- // }
166
- // return l1 + String(Math.floor(Math.random() * parseFloat(`1e${l.length - 2}`) - 1));
167
- // }
18
+ enum DivisionCodeLevel {
19
+ Province = 1,
20
+ City = 2,
21
+ County = 3,
22
+ Town = 4,
23
+ Village = 5,
24
+ }
25
+
26
+ export const levels = DivisionCodeLevels;
27
+
28
+ export const regex = /^(?<province>\d{2})(?<city>\d{2})?(?<county>\d{2})?(?<town>\d{3})?(?<village>\d{3})?$/;
29
+
30
+ const root: CodeValue[] = [
31
+ { value: '11', label: '北京市' },
32
+ { value: '12', label: '天津市' },
33
+ { value: '13', label: '河北省' },
34
+ { value: '14', label: '山西省' },
35
+ { value: '15', label: '内蒙古自治区' },
36
+ { value: '21', label: '辽宁省' },
37
+ { value: '22', label: '吉林省' },
38
+ { value: '23', label: '黑龙江省' },
39
+ { value: '31', label: '上海市' },
40
+ { value: '32', label: '江苏省' },
41
+ { value: '33', label: '浙江省' },
42
+ { value: '34', label: '安徽省' },
43
+ { value: '35', label: '福建省' },
44
+ { value: '36', label: '江西省' },
45
+ { value: '37', label: '山东省' },
46
+ { value: '41', label: '河南省' },
47
+ { value: '42', label: '湖北省' },
48
+ { value: '43', label: '湖南省' },
49
+ { value: '44', label: '广东省' },
50
+ { value: '45', label: '广西壮族自治区' },
51
+ { value: '46', label: '海南省' },
52
+ { value: '50', label: '重庆市' },
53
+ { value: '51', label: '四川省' },
54
+ { value: '52', label: '贵州省' },
55
+ { value: '53', label: '云南省' },
56
+ { value: '54', label: '西藏自治区' },
57
+ { value: '61', label: '陕西省' },
58
+ { value: '62', label: '甘肃省' },
59
+ { value: '63', label: '青海省' },
60
+ { value: '64', label: '宁夏回族自治区' },
61
+ { value: '65', label: '新疆维吾尔自治区' },
62
+ { value: '71', label: '台湾省' },
63
+ { value: '81', label: '香港特别行政区' },
64
+ { value: '82', label: '澳门特别行政区' },
65
+ // 9 国外
66
+ ];
67
+
68
+ export type ParsedCode = {
69
+ province: string;
70
+ city?: string;
71
+ county?: string;
72
+ town?: string;
73
+ village?: string;
74
+ codes: string[];
75
+ level: DivisionCodeLevel;
76
+ labels: string[];
77
+ };
78
+
79
+ export function parse(code: string | undefined | null | number): ParsedCode | undefined {
80
+ if (!code) return;
81
+ code = String(code);
82
+ const match = regex.exec(code);
83
+ if (!match) return;
84
+ const { province, city, county, town, village } = match.groups ?? {};
85
+ if (!province) return;
86
+
87
+ let codes = [province, city, county, town, village].filter(Boolean);
88
+ return { province, city, county, town, village, codes: codes, level: codes.length as DivisionCodeLevel };
89
+ }
90
+
91
+ export function format({
92
+ province,
93
+ city,
94
+ county,
95
+ town,
96
+ village,
97
+ }: {
98
+ province: string | number;
99
+ city?: string | number;
100
+ county?: string | number;
101
+ town?: string | number;
102
+ village?: string | number;
103
+ }): string {
104
+ const codes: string[] = [];
105
+ for (let i = 0; i < [province, city, county, town, village].length; i++) {
106
+ let x = [province, city, county, town, village][i];
107
+ if (x === undefined || x === null || x === '') {
108
+ break;
109
+ }
110
+ let len = levels[i].size;
111
+ codes.push(String(x).padStart(len, '0').slice(0, len));
112
+ }
113
+ return codes.join('');
114
+ }
115
+
116
+ // export function random(level: DivisionCodeLevel = 'County'): string {
117
+ // const l = DivisionCodeLevels.find((v) => v.code === level) || DivisionCodeLevels[2];
118
+ // const l1 = randomPick(provinces);
119
+ // if (l.level === 1) {
120
+ // return String(l1[0]);
121
+ // }
122
+ // return l1 + String(Math.floor(Math.random() * parseFloat(`1e${l.length - 2}`) - 1));
123
+ // }
168
124
  }
169
125
 
170
126
  interface DivisionTreeNode {
171
- sub: string; // sub code
172
- children?: Record<string, DivisionTreeNode>;
127
+ sub: string; // sub code
128
+ children?: Record<string, DivisionTreeNode>;
173
129
 
174
- code: string; // full code
175
- name?: string; // name of division
130
+ code: string; // full code
131
+ name?: string; // name of division
176
132
  }
177
133
 
178
134
  // export type DivisionCodeLevel = 'Village' | 'Town' | 'County' | 'City' | 'Province';
@@ -220,34 +176,34 @@ interface DivisionTreeNode {
220
176
  // }
221
177
 
222
178
  export function randomPick<T>(s: T[]) {
223
- return s[Math.floor(Math.random() * s.length)];
179
+ return s[Math.floor(Math.random() * s.length)];
224
180
  }
225
181
 
226
182
  function lookup(opts: { values: string[]; root: CodeValue[] }): { found: CodeValue[] } {
227
- const { values, root } = opts;
228
- const found: CodeValue[] = [];
229
- let currentLevel = root;
230
-
231
- for (const v of values) {
232
- const node = currentLevel.find((n) => n.value === v);
233
- if (!node) {
234
- break;
235
- }
236
-
237
- found.push(node);
238
-
239
- if (node.children) {
240
- currentLevel = node.children;
241
- } else {
242
- break;
243
- }
244
- }
245
-
246
- return { found };
183
+ const { values, root } = opts;
184
+ const found: CodeValue[] = [];
185
+ let currentLevel = root;
186
+
187
+ for (const v of values) {
188
+ const node = currentLevel.find((n) => n.value === v);
189
+ if (!node) {
190
+ break;
191
+ }
192
+
193
+ found.push(node);
194
+
195
+ if (node.children) {
196
+ currentLevel = node.children;
197
+ } else {
198
+ break;
199
+ }
200
+ }
201
+
202
+ return { found };
247
203
  }
248
204
 
249
205
  interface CodeValue {
250
- value: string;
251
- label: string;
252
- children?: Array<CodeValue>;
206
+ value: string;
207
+ label: string;
208
+ children?: Array<CodeValue>;
253
209
  }
@@ -2,23 +2,23 @@
2
2
  * ISO 7064:1983, MOD 11-2.
3
3
  */
4
4
  export class Mod11Checksum {
5
- weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1];
5
+ weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1];
6
6
 
7
- validate(s: string) {
8
- return s.at(-1) === this.compute(s.slice(0, s.length - 1));
9
- }
7
+ validate(s: string) {
8
+ return s.at(-1) === this.compute(s.slice(0, s.length - 1));
9
+ }
10
10
 
11
- compute(s: string) {
12
- const { weights } = this;
13
- let sum = 0;
14
- for (let i = 0; i < s.length; i++) {
15
- sum += parseInt(s[i]) * weights[i];
16
- }
17
- const num = (12 - (sum % 11)) % 11;
18
- if (num < 10) {
19
- return num.toString();
20
- } else {
21
- return 'X';
22
- }
23
- }
11
+ compute(s: string) {
12
+ const { weights } = this;
13
+ let sum = 0;
14
+ for (let i = 0; i < s.length; i++) {
15
+ sum += parseInt(s[i]) * weights[i];
16
+ }
17
+ const num = (12 - (sum % 11)) % 11;
18
+ if (num < 10) {
19
+ return num.toString();
20
+ } else {
21
+ return 'X';
22
+ }
23
+ }
24
24
  }