@wener/common 2.0.3 → 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 (312) hide show
  1. package/lib/ai/qwen3vl/index.js +1 -1
  2. package/lib/ai/qwen3vl/utils.js +15 -15
  3. package/lib/ai/qwen3vl/utils.js.map +1 -1
  4. package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
  5. package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
  6. package/lib/ai/vision/index.js +2 -2
  7. package/lib/ai/vision/resolveImageAnnotation.js +81 -95
  8. package/lib/cn/ChineseResidentIdNo.js +55 -41
  9. package/lib/cn/ChineseResidentIdNo.js.map +1 -1
  10. package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
  11. package/lib/cn/ChineseResidentIdNo.test.js +22 -21
  12. package/lib/cn/DivisionCode.js +220 -235
  13. package/lib/cn/DivisionCode.mod.js +6 -1
  14. package/lib/cn/DivisionCode.test.js +92 -121
  15. package/lib/cn/Mod11.js +18 -37
  16. package/lib/cn/Mod11.js.map +1 -1
  17. package/lib/cn/Mod31.js +23 -41
  18. package/lib/cn/UnifiedSocialCreditCode.js +143 -137
  19. package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
  20. package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
  21. package/lib/cn/formatChineseAmount.js +46 -71
  22. package/lib/cn/index.js +6 -6
  23. package/lib/cn/mod.js +5 -3
  24. package/lib/cn/parseChineseNumber.js +81 -85
  25. package/lib/cn/parseChineseNumber.test.js +183 -261
  26. package/lib/cn/pinyin/cartesianProduct.js +19 -19
  27. package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
  28. package/lib/cn/pinyin/loader.js +13 -11
  29. package/lib/cn/pinyin/preload.js +2 -1
  30. package/lib/cn/pinyin/toPinyin.test.js +149 -161
  31. package/lib/cn/pinyin/toPinyinPure.js +28 -23
  32. package/lib/cn/pinyin/transform.js +11 -11
  33. package/lib/cn/types.d.js +2 -2
  34. package/lib/consola/createStandardConsolaReporter.js +14 -15
  35. package/lib/consola/formatLogObject.js +149 -133
  36. package/lib/consola/formatLogObject.js.map +1 -1
  37. package/lib/consola/formatLogObject.test.js +167 -178
  38. package/lib/consola/index.js +2 -2
  39. package/lib/data/formatSort.js +14 -12
  40. package/lib/data/formatSort.test.js +33 -33
  41. package/lib/data/index.js +3 -3
  42. package/lib/data/maybeNumber.js +23 -23
  43. package/lib/data/maybeNumber.js.map +1 -1
  44. package/lib/data/parseSort.js +75 -68
  45. package/lib/data/parseSort.test.js +196 -187
  46. package/lib/data/resolvePagination.js +38 -39
  47. package/lib/data/resolvePagination.test.js +228 -218
  48. package/lib/data/types.d.js +2 -2
  49. package/lib/data/types.d.js.map +1 -1
  50. package/lib/dayjs/dayjs.js +20 -20
  51. package/lib/dayjs/formatDuration.js +56 -56
  52. package/lib/dayjs/formatDuration.js.map +1 -1
  53. package/lib/dayjs/formatDuration.test.js +63 -77
  54. package/lib/dayjs/index.js +4 -4
  55. package/lib/dayjs/parseDuration.js +21 -26
  56. package/lib/dayjs/parseRelativeTime.js +65 -66
  57. package/lib/dayjs/parseRelativeTime.test.js +227 -243
  58. package/lib/dayjs/resolveRelativeTime.js +74 -144
  59. package/lib/dayjs/resolveRelativeTime.js.map +1 -1
  60. package/lib/dayjs/resolveRelativeTime.test.js +296 -307
  61. package/lib/decimal/index.js +1 -1
  62. package/lib/decimal/parseDecimal.js +12 -12
  63. package/lib/drain3/Drain.js +321 -0
  64. package/lib/drain3/Drain.js.map +1 -0
  65. package/lib/drain3/LogCluster.js +38 -0
  66. package/lib/drain3/LogCluster.js.map +1 -0
  67. package/lib/drain3/Node.js +39 -0
  68. package/lib/drain3/Node.js.map +1 -0
  69. package/lib/drain3/TemplateMiner.js +205 -0
  70. package/lib/drain3/TemplateMiner.js.map +1 -0
  71. package/lib/drain3/index.js +31 -0
  72. package/lib/drain3/index.js.map +1 -0
  73. package/lib/drain3/persistence/FilePersistence.js +24 -0
  74. package/lib/drain3/persistence/FilePersistence.js.map +1 -0
  75. package/lib/drain3/persistence/MemoryPersistence.js +18 -0
  76. package/lib/drain3/persistence/MemoryPersistence.js.map +1 -0
  77. package/lib/drain3/persistence/PersistenceHandler.js +5 -0
  78. package/lib/drain3/persistence/PersistenceHandler.js.map +1 -0
  79. package/lib/drain3/types.js +7 -0
  80. package/lib/drain3/types.js.map +1 -0
  81. package/lib/emittery/emitter.js +7 -7
  82. package/lib/emittery/index.js +1 -1
  83. package/lib/foundation/schema/SexType.js +15 -12
  84. package/lib/foundation/schema/index.js +1 -1
  85. package/lib/foundation/schema/parseSexType.js +15 -16
  86. package/lib/foundation/schema/types.js +8 -6
  87. package/lib/fs/FileSystemError.js +18 -18
  88. package/lib/fs/IFileSystem.d.js +2 -2
  89. package/lib/fs/IFileSystem.d.js.map +1 -1
  90. package/lib/fs/MemoryFileSystem.test.js +172 -181
  91. package/lib/fs/createBrowserFileSystem.js +222 -233
  92. package/lib/fs/createBrowserFileSystem.js.map +1 -1
  93. package/lib/fs/createMemoryFileSystem.js +473 -510
  94. package/lib/fs/createMemoryFileSystem.js.map +1 -1
  95. package/lib/fs/createSandboxFileSystem.js +102 -101
  96. package/lib/fs/createSandboxFileSystem.js.map +1 -1
  97. package/lib/fs/createWebDavFileSystem.js +162 -132
  98. package/lib/fs/createWebDavFileSystem.js.map +1 -1
  99. package/lib/fs/createWebFileSystem.js +202 -0
  100. package/lib/fs/createWebFileSystem.js.map +1 -0
  101. package/lib/fs/findMimeType.js +14 -14
  102. package/lib/fs/findMimeType.js.map +1 -1
  103. package/lib/fs/index.js +7 -7
  104. package/lib/fs/index.js.map +1 -1
  105. package/lib/fs/minio/createMinioFileSystem.js +977 -0
  106. package/lib/fs/minio/createMinioFileSystem.js.map +1 -0
  107. package/lib/fs/minio/index.js +2 -0
  108. package/lib/fs/minio/index.js.map +1 -0
  109. package/lib/fs/orpc/FileSystemContract.js +57 -57
  110. package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
  111. package/lib/fs/orpc/createContractClientFileSystem.js.map +1 -1
  112. package/lib/fs/orpc/index.js +2 -2
  113. package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
  114. package/lib/fs/orpc/server/createFileSystemContractImpl.js.map +1 -1
  115. package/lib/fs/orpc/server/index.js +1 -1
  116. package/lib/fs/s3/createS3MiniFileSystem.js +756 -689
  117. package/lib/fs/s3/createS3MiniFileSystem.js.map +1 -1
  118. package/lib/fs/s3/index.js +1 -1
  119. package/lib/fs/s3/s3mini.test.js +524 -553
  120. package/lib/fs/scandir.js +56 -56
  121. package/lib/fs/server/createDatabaseFileSystem.js +834 -741
  122. package/lib/fs/server/createDatabaseFileSystem.js.map +1 -1
  123. package/lib/fs/server/createNodeFileSystem.js +407 -380
  124. package/lib/fs/server/createNodeFileSystem.js.map +1 -1
  125. package/lib/fs/server/dbfs.test.js +201 -214
  126. package/lib/fs/server/index.js +1 -1
  127. package/lib/fs/server/loadTestDatabase.js +40 -43
  128. package/lib/fs/tests/runFileSystemTest.js +352 -315
  129. package/lib/fs/tests/runFileSystemTest.js.map +1 -1
  130. package/lib/fs/types.js +17 -20
  131. package/lib/fs/utils/getFileUrl.js +24 -30
  132. package/lib/fs/utils.js +17 -17
  133. package/lib/fs/utils.js.map +1 -1
  134. package/lib/fs/webdav/index.js +2 -0
  135. package/lib/fs/webdav/index.js.map +1 -0
  136. package/lib/index.js +2 -2
  137. package/lib/jsonschema/JsonSchema.js +216 -155
  138. package/lib/jsonschema/JsonSchema.js.map +1 -1
  139. package/lib/jsonschema/JsonSchema.test.js +123 -124
  140. package/lib/jsonschema/forEachJsonSchema.js +41 -41
  141. package/lib/jsonschema/forEachJsonSchema.js.map +1 -1
  142. package/lib/jsonschema/index.js +2 -2
  143. package/lib/jsonschema/types.d.js +2 -2
  144. package/lib/jsonschema/types.d.js.map +1 -1
  145. package/lib/meta/defineFileType.js +32 -38
  146. package/lib/meta/defineInit.js +39 -35
  147. package/lib/meta/defineMetadata.js +37 -34
  148. package/lib/meta/defineMetadata.js.map +1 -1
  149. package/lib/meta/defineMetadata.test.js +13 -12
  150. package/lib/meta/index.js +3 -3
  151. package/lib/orpc/createOpenApiContractClient.js +26 -24
  152. package/lib/orpc/createOpenApiContractClient.js.map +1 -1
  153. package/lib/orpc/createRpcContractClient.js +37 -31
  154. package/lib/orpc/index.js +2 -2
  155. package/lib/orpc/resolveLinkPlugins.js +25 -25
  156. package/lib/password/PHC.js +187 -189
  157. package/lib/password/PHC.js.map +1 -1
  158. package/lib/password/PHC.test.js +517 -535
  159. package/lib/password/Password.js +85 -80
  160. package/lib/password/Password.test.js +330 -364
  161. package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
  162. package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -1
  163. package/lib/password/createBase64PasswordAlgorithm.js +11 -11
  164. package/lib/password/createBase64PasswordAlgorithm.js.map +1 -1
  165. package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
  166. package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -1
  167. package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
  168. package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -1
  169. package/lib/password/createScryptPasswordAlgorithm.js +74 -63
  170. package/lib/password/createScryptPasswordAlgorithm.js.map +1 -1
  171. package/lib/password/index.js +5 -5
  172. package/lib/password/server/index.js +1 -1
  173. package/lib/resource/Identifiable.js +2 -2
  174. package/lib/resource/ListQuery.js +42 -42
  175. package/lib/resource/ListQuery.js.map +1 -1
  176. package/lib/resource/getTitleOfResource.js +5 -5
  177. package/lib/resource/index.js +2 -2
  178. package/lib/resource/index.js.map +1 -1
  179. package/lib/resource/schema/AnyResourceSchema.js +91 -89
  180. package/lib/resource/schema/BaseResourceSchema.js +26 -26
  181. package/lib/resource/schema/ResourceActionType.js +117 -115
  182. package/lib/resource/schema/ResourceStatus.js +94 -92
  183. package/lib/resource/schema/ResourceType.js +25 -23
  184. package/lib/resource/schema/index.js +5 -5
  185. package/lib/resource/schema/types.js +86 -55
  186. package/lib/resource/schema/types.test.js +16 -13
  187. package/lib/s3/formatS3Url.js +60 -60
  188. package/lib/s3/formatS3Url.js.map +1 -1
  189. package/lib/s3/formatS3Url.test.js +238 -261
  190. package/lib/s3/index.js +2 -2
  191. package/lib/s3/parseS3Url.js +61 -60
  192. package/lib/s3/parseS3Url.js.map +1 -1
  193. package/lib/s3/parseS3Url.test.js +270 -269
  194. package/lib/schema/SchemaRegistry.js +41 -42
  195. package/lib/schema/SchemaRegistry.js.map +1 -1
  196. package/lib/schema/SchemaRegistry.mod.js +1 -1
  197. package/lib/schema/TypeSchema.d.js +2 -2
  198. package/lib/schema/TypeSchema.d.js.map +1 -1
  199. package/lib/schema/createSchemaData.js +113 -67
  200. package/lib/schema/createSchemaData.js.map +1 -1
  201. package/lib/schema/findJsonSchemaByPath.js +28 -23
  202. package/lib/schema/findJsonSchemaByPath.js.map +1 -1
  203. package/lib/schema/formatZodError.js +113 -134
  204. package/lib/schema/formatZodError.js.map +1 -1
  205. package/lib/schema/formatZodError.test.js +192 -195
  206. package/lib/schema/getSchemaCache.js +7 -7
  207. package/lib/schema/getSchemaOptions.js +17 -16
  208. package/lib/schema/index.js +6 -6
  209. package/lib/schema/toJsonSchema.js +196 -190
  210. package/lib/schema/toJsonSchema.js.map +1 -1
  211. package/lib/schema/toJsonSchema.test.js +34 -26
  212. package/lib/schema/validate.js +106 -97
  213. package/lib/schema/validate.js.map +1 -1
  214. package/lib/tools/generateSchema.js +40 -40
  215. package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
  216. package/lib/utils/buildBaseUrl.js +8 -8
  217. package/lib/utils/buildRedactorFormSchema.js +55 -54
  218. package/lib/utils/buildRedactorFormSchema.js.map +1 -1
  219. package/lib/utils/getEstimateProcessTime.js +24 -19
  220. package/lib/utils/index.js +3 -3
  221. package/lib/utils/resolveFeatureOptions.js +9 -9
  222. package/package.json +37 -18
  223. package/src/ai/qwen3vl/utils.ts +1 -1
  224. package/src/ai/vision/index.ts +2 -2
  225. package/src/cn/ChineseResidentIdNo.ts +1 -1
  226. package/src/cn/Mod11.ts +1 -1
  227. package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +1 -1
  228. package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +0 -23
  229. package/src/cn/index.ts +1 -2
  230. package/src/cn/parseChineseNumber.test.ts +4 -4
  231. package/src/consola/formatLogObject.ts +6 -6
  232. package/src/consola/index.ts +1 -1
  233. package/src/data/index.ts +3 -4
  234. package/src/data/maybeNumber.ts +1 -1
  235. package/src/data/parseSort.test.ts +0 -1
  236. package/src/data/resolvePagination.ts +2 -2
  237. package/src/data/types.d.ts +2 -2
  238. package/src/dayjs/formatDuration.ts +10 -11
  239. package/src/dayjs/index.ts +1 -1
  240. package/src/dayjs/parseRelativeTime.ts +1 -1
  241. package/src/dayjs/resolveRelativeTime.ts +11 -14
  242. package/src/drain3/Drain.test.ts +378 -0
  243. package/src/drain3/Drain.ts +394 -0
  244. package/src/drain3/LogCluster.ts +46 -0
  245. package/src/drain3/Node.ts +53 -0
  246. package/src/drain3/TemplateMiner.ts +246 -0
  247. package/src/drain3/index.ts +34 -0
  248. package/src/drain3/persistence/FilePersistence.ts +24 -0
  249. package/src/drain3/persistence/MemoryPersistence.ts +23 -0
  250. package/src/drain3/persistence/PersistenceHandler.ts +19 -0
  251. package/src/drain3/types.ts +75 -0
  252. package/src/fs/IFileSystem.d.ts +1 -2
  253. package/src/fs/createBrowserFileSystem.ts +7 -5
  254. package/src/fs/createMemoryFileSystem.ts +9 -13
  255. package/src/fs/createSandboxFileSystem.ts +1 -1
  256. package/src/fs/createWebDavFileSystem.ts +30 -17
  257. package/src/fs/createWebFileSystem.ts +242 -0
  258. package/src/fs/findMimeType.ts +1 -4
  259. package/src/fs/index.ts +5 -5
  260. package/src/fs/minio/createMinioFileSystem.ts +1148 -0
  261. package/src/fs/minio/index.ts +1 -0
  262. package/src/fs/orpc/createContractClientFileSystem.ts +5 -5
  263. package/src/fs/orpc/server/createFileSystemContractImpl.ts +1 -1
  264. package/src/fs/s3/createS3MiniFileSystem.ts +120 -79
  265. package/src/fs/s3/s3fs.test.ts +441 -0
  266. package/src/fs/s3/s3mini.test.ts +2 -2
  267. package/src/fs/server/createDatabaseFileSystem.ts +78 -114
  268. package/src/fs/server/createNodeFileSystem.ts +32 -13
  269. package/src/fs/server/dbfs.test.ts +13 -8
  270. package/src/fs/server/index.ts +1 -0
  271. package/src/fs/server/loadTestDatabase.ts +8 -119
  272. package/src/fs/tests/runFileSystemTest.ts +29 -28
  273. package/src/fs/utils.ts +1 -1
  274. package/src/fs/webdav/index.ts +1 -0
  275. package/src/jsonschema/JsonSchema.ts +5 -5
  276. package/src/jsonschema/forEachJsonSchema.ts +1 -1
  277. package/src/jsonschema/index.ts +1 -1
  278. package/src/jsonschema/types.d.ts +1 -1
  279. package/src/meta/defineMetadata.ts +1 -1
  280. package/src/meta/index.ts +2 -3
  281. package/src/orm/createSqliteDialect.ts +17 -0
  282. package/src/orm/index.ts +1 -0
  283. package/src/orpc/createOpenApiContractClient.ts +3 -3
  284. package/src/orpc/index.ts +1 -1
  285. package/src/password/PHC.ts +3 -3
  286. package/src/password/createArgon2PasswordAlgorithm.ts +2 -2
  287. package/src/password/createBase64PasswordAlgorithm.ts +2 -2
  288. package/src/password/createBcryptPasswordAlgorithm.ts +4 -2
  289. package/src/password/createPBKDF2PasswordAlgorithm.ts +2 -2
  290. package/src/password/createScryptPasswordAlgorithm.ts +4 -4
  291. package/src/password/index.ts +2 -2
  292. package/src/resource/ListQuery.ts +4 -1
  293. package/src/resource/index.ts +3 -3
  294. package/src/resource/schema/index.ts +4 -4
  295. package/src/s3/formatS3Url.test.ts +1 -1
  296. package/src/s3/formatS3Url.ts +2 -2
  297. package/src/s3/index.ts +1 -1
  298. package/src/s3/parseS3Url.ts +1 -1
  299. package/src/schema/SchemaRegistry.ts +2 -2
  300. package/src/schema/TypeSchema.d.ts +6 -6
  301. package/src/schema/createSchemaData.ts +5 -5
  302. package/src/schema/findJsonSchemaByPath.ts +5 -5
  303. package/src/schema/formatZodError.test.ts +2 -1
  304. package/src/schema/formatZodError.ts +50 -62
  305. package/src/schema/index.ts +5 -5
  306. package/src/schema/toJsonSchema.ts +6 -6
  307. package/src/schema/validate.ts +2 -2
  308. package/src/utils/buildRedactorFormSchema.ts +4 -4
  309. package/src/utils/formatNumber.ts +18 -0
  310. package/src/utils/formatPercent.ts +17 -0
  311. package/src/utils/index.ts +3 -3
  312. package/src/utils/resolveFeatureOptions.ts +1 -1
@@ -1,2 +1,2 @@
1
- export { fromQwen3VlBbox2d, toQwen3VlBbox2d } from "./utils.js";
1
+ export { fromQwen3VlBbox2d, toQwen3VlBbox2d } from './utils.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -5,13 +5,13 @@
5
5
  * @param bbox Bbox in Qwen3V format [x1, y1, x2, y2] where each value is 0-1000
6
6
  * @returns Absolute pixel coordinates [x1, y1, x2, y2]
7
7
  */ export function fromQwen3VlBbox2d({ width, height }, bbox) {
8
- const [x1, y1, x2, y2] = bbox;
9
- return [
10
- Math.floor(x1 / 1000 * width),
11
- Math.floor(y1 / 1000 * height),
12
- Math.floor(x2 / 1000 * width),
13
- Math.floor(y2 / 1000 * height)
14
- ];
8
+ const [x1, y1, x2, y2] = bbox;
9
+ return [
10
+ Math.floor((x1 / 1000) * width),
11
+ Math.floor((y1 / 1000) * height),
12
+ Math.floor((x2 / 1000) * width),
13
+ Math.floor((y2 / 1000) * height),
14
+ ];
15
15
  }
16
16
  /**
17
17
  * Convert absolute pixel coordinates to Qwen3V format bbox (0-1000 range)
@@ -19,13 +19,13 @@
19
19
  * @param bbox Absolute pixel coordinates [x1, y1, x2, y2]
20
20
  * @returns Bbox in Qwen3V format [x1, y1, x2, y2] where each value is 0-1000
21
21
  */ export function toQwen3VlBbox2d({ width, height }, bbox) {
22
- const [x1, y1, x2, y2] = bbox;
23
- return [
24
- Math.round(x1 / width * 1000),
25
- Math.round(y1 / height * 1000),
26
- Math.round(x2 / width * 1000),
27
- Math.round(y2 / height * 1000)
28
- ];
22
+ const [x1, y1, x2, y2] = bbox;
23
+ return [
24
+ Math.round((x1 / width) * 1000),
25
+ Math.round((y1 / height) * 1000),
26
+ Math.round((x2 / width) * 1000),
27
+ Math.round((y2 / height) * 1000),
28
+ ];
29
29
  }
30
30
 
31
- //# sourceMappingURL=utils.js.map
31
+ //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/ai/qwen3vl/utils.ts"],"sourcesContent":["// xyxy\ntype Bbox2d = [number, number, number, number];\ntype Dimensions = { width: number; height: number };\n// x_center, y_center, z_center, x_size, y_size, z_size, roll, pitch, yaw\ntype Bbox3d = [number, number, number, number, number, number, number, number, number];\n/**\n * Convert Qwen3V format bbox (0-1000 range) to absolute pixel coordinates\n * @param dimensions Image dimensions {width, height}\n * @param bbox Bbox in Qwen3V format [x1, y1, x2, y2] where each value is 0-1000\n * @returns Absolute pixel coordinates [x1, y1, x2, y2]\n */\nexport function fromQwen3VlBbox2d({ width, height }: Dimensions, bbox: Bbox2d): Bbox2d {\n\tconst [x1, y1, x2, y2] = bbox;\n\treturn [\n\t\tMath.floor((x1 / 1000) * width),\n\t\tMath.floor((y1 / 1000) * height),\n\t\tMath.floor((x2 / 1000) * width),\n\t\tMath.floor((y2 / 1000) * height),\n\t];\n}\n\n/**\n * Convert absolute pixel coordinates to Qwen3V format bbox (0-1000 range)\n * @param dimensions Image dimensions {width, height}\n * @param bbox Absolute pixel coordinates [x1, y1, x2, y2]\n * @returns Bbox in Qwen3V format [x1, y1, x2, y2] where each value is 0-1000\n */\nexport function toQwen3VlBbox2d({ width, height }: Dimensions, bbox: Bbox2d): Bbox2d {\n\tconst [x1, y1, x2, y2] = bbox;\n\treturn [\n\t\tMath.round((x1 / width) * 1000),\n\t\tMath.round((y1 / height) * 1000),\n\t\tMath.round((x2 / width) * 1000),\n\t\tMath.round((y2 / height) * 1000),\n\t];\n}\n"],"names":["fromQwen3VlBbox2d","width","height","bbox","x1","y1","x2","y2","Math","floor","toQwen3VlBbox2d","round"],"mappings":"AAAA,OAAO;AAKP;;;;;CAKC,GACD,OAAO,SAASA,kBAAkB,EAAEC,KAAK,EAAEC,MAAM,EAAc,EAAEC,IAAY;IAC5E,MAAM,CAACC,IAAIC,IAAIC,IAAIC,GAAG,GAAGJ;IACzB,OAAO;QACNK,KAAKC,KAAK,CAAC,AAACL,KAAK,OAAQH;QACzBO,KAAKC,KAAK,CAAC,AAACJ,KAAK,OAAQH;QACzBM,KAAKC,KAAK,CAAC,AAACH,KAAK,OAAQL;QACzBO,KAAKC,KAAK,CAAC,AAACF,KAAK,OAAQL;KACzB;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASQ,gBAAgB,EAAET,KAAK,EAAEC,MAAM,EAAc,EAAEC,IAAY;IAC1E,MAAM,CAACC,IAAIC,IAAIC,IAAIC,GAAG,GAAGJ;IACzB,OAAO;QACNK,KAAKG,KAAK,CAAC,AAACP,KAAKH,QAAS;QAC1BO,KAAKG,KAAK,CAAC,AAACN,KAAKH,SAAU;QAC3BM,KAAKG,KAAK,CAAC,AAACL,KAAKL,QAAS;QAC1BO,KAAKG,KAAK,CAAC,AAACJ,KAAKL,SAAU;KAC3B;AACF"}
1
+ {"version":3,"sources":["../../../src/ai/qwen3vl/utils.ts"],"sourcesContent":["// xyxy\ntype Bbox2d = [number, number, number, number];\ntype Dimensions = { width: number; height: number };\n// x_center, y_center, z_center, x_size, y_size, z_size, roll, pitch, yaw\ntype _Bbox3d = [number, number, number, number, number, number, number, number, number];\n/**\n * Convert Qwen3V format bbox (0-1000 range) to absolute pixel coordinates\n * @param dimensions Image dimensions {width, height}\n * @param bbox Bbox in Qwen3V format [x1, y1, x2, y2] where each value is 0-1000\n * @returns Absolute pixel coordinates [x1, y1, x2, y2]\n */\nexport function fromQwen3VlBbox2d({ width, height }: Dimensions, bbox: Bbox2d): Bbox2d {\n\tconst [x1, y1, x2, y2] = bbox;\n\treturn [\n\t\tMath.floor((x1 / 1000) * width),\n\t\tMath.floor((y1 / 1000) * height),\n\t\tMath.floor((x2 / 1000) * width),\n\t\tMath.floor((y2 / 1000) * height),\n\t];\n}\n\n/**\n * Convert absolute pixel coordinates to Qwen3V format bbox (0-1000 range)\n * @param dimensions Image dimensions {width, height}\n * @param bbox Absolute pixel coordinates [x1, y1, x2, y2]\n * @returns Bbox in Qwen3V format [x1, y1, x2, y2] where each value is 0-1000\n */\nexport function toQwen3VlBbox2d({ width, height }: Dimensions, bbox: Bbox2d): Bbox2d {\n\tconst [x1, y1, x2, y2] = bbox;\n\treturn [\n\t\tMath.round((x1 / width) * 1000),\n\t\tMath.round((y1 / height) * 1000),\n\t\tMath.round((x2 / width) * 1000),\n\t\tMath.round((y2 / height) * 1000),\n\t];\n}\n"],"names":["fromQwen3VlBbox2d","width","height","bbox","x1","y1","x2","y2","Math","floor","toQwen3VlBbox2d","round"],"mappings":"AAAA,OAAO;AAKP;;;;;CAKC,GACD,OAAO,SAASA,kBAAkB,EAAEC,KAAK,EAAEC,MAAM,EAAc,EAAEC,IAAY;IAC5E,MAAM,CAACC,IAAIC,IAAIC,IAAIC,GAAG,GAAGJ;IACzB,OAAO;QACNK,KAAKC,KAAK,CAAC,AAACL,KAAK,OAAQH;QACzBO,KAAKC,KAAK,CAAC,AAACJ,KAAK,OAAQH;QACzBM,KAAKC,KAAK,CAAC,AAACH,KAAK,OAAQL;QACzBO,KAAKC,KAAK,CAAC,AAACF,KAAK,OAAQL;KACzB;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASQ,gBAAgB,EAAET,KAAK,EAAEC,MAAM,EAAc,EAAEC,IAAY;IAC1E,MAAM,CAACC,IAAIC,IAAIC,IAAIC,GAAG,GAAGJ;IACzB,OAAO;QACNK,KAAKG,KAAK,CAAC,AAACP,KAAKH,QAAS;QAC1BO,KAAKG,KAAK,CAAC,AAACN,KAAKH,SAAU;QAC3BM,KAAKG,KAAK,CAAC,AAACL,KAAKL,QAAS;QAC1BO,KAAKG,KAAK,CAAC,AAACJ,KAAKL,SAAU;KAC3B;AACF"}
@@ -1,28 +1,28 @@
1
- import { z } from "zod";
1
+ import { z } from 'zod';
2
2
  // based on DocLayout-YOLO
3
3
  export const DocLayoutElementType = Object.freeze({
4
- Title: 'Title',
5
- PlainText: 'PlainText',
6
- Abandon: 'Abandon',
7
- Figure: 'Figure',
8
- FigureCaption: 'FigureCaption',
9
- Table: 'Table',
10
- TableCaption: 'TableCaption',
11
- TableFootnote: 'TableFootnote',
12
- IsolateFormula: 'IsolateFormula',
13
- FormulaCaption: 'FormulaCaption'
4
+ Title: 'Title',
5
+ PlainText: 'PlainText',
6
+ Abandon: 'Abandon',
7
+ Figure: 'Figure',
8
+ FigureCaption: 'FigureCaption',
9
+ Table: 'Table',
10
+ TableCaption: 'TableCaption',
11
+ TableFootnote: 'TableFootnote',
12
+ IsolateFormula: 'IsolateFormula',
13
+ FormulaCaption: 'FormulaCaption',
14
14
  });
15
15
  export const DocLayoutElementTypeSchema = z.union([
16
- z.literal(DocLayoutElementType.Title).describe('标题'),
17
- z.literal(DocLayoutElementType.PlainText).describe('纯文本'),
18
- z.literal(DocLayoutElementType.Abandon).describe('废弃'),
19
- z.literal(DocLayoutElementType.Figure).describe('图片'),
20
- z.literal(DocLayoutElementType.FigureCaption).describe('图片说明'),
21
- z.literal(DocLayoutElementType.Table).describe('表格'),
22
- z.literal(DocLayoutElementType.TableCaption).describe('表格标题'),
23
- z.literal(DocLayoutElementType.TableFootnote).describe('表格脚注'),
24
- z.literal(DocLayoutElementType.IsolateFormula).describe('独立公式'),
25
- z.literal(DocLayoutElementType.FormulaCaption).describe('公式说明')
16
+ z.literal(DocLayoutElementType.Title).describe('标题'),
17
+ z.literal(DocLayoutElementType.PlainText).describe('纯文本'),
18
+ z.literal(DocLayoutElementType.Abandon).describe('废弃'),
19
+ z.literal(DocLayoutElementType.Figure).describe('图片'),
20
+ z.literal(DocLayoutElementType.FigureCaption).describe('图片说明'),
21
+ z.literal(DocLayoutElementType.Table).describe('表格'),
22
+ z.literal(DocLayoutElementType.TableCaption).describe('表格标题'),
23
+ z.literal(DocLayoutElementType.TableFootnote).describe('表格脚注'),
24
+ z.literal(DocLayoutElementType.IsolateFormula).describe('独立公式'),
25
+ z.literal(DocLayoutElementType.FormulaCaption).describe('公式说明'),
26
26
  ]);
27
27
 
28
- //# sourceMappingURL=DocLayoutElementTypeSchema.js.map
28
+ //# sourceMappingURL=DocLayoutElementTypeSchema.js.map
@@ -1,50 +1,66 @@
1
- import { z } from "zod";
1
+ import { z } from 'zod';
2
2
  export const ImageAnnotationSchema = z.looseObject({
3
- id: z.string().optional(),
4
- title: z.string().trim().optional().describe('标题'),
5
- description: z.string().trim().optional().describe('描述'),
6
- type: z.string().trim().optional().describe('类型'),
7
- // 内容字段
8
- text: z.string().optional().describe('文本内容'),
9
- markdown: z.string().optional().describe('Markdown 内容'),
10
- csv: z.string().optional().describe('CSV 内容'),
11
- html: z.string().optional().describe('HTML 内容'),
12
- data: z.any().optional().describe('任意数据'),
13
- // 定位信息
14
- field: z.string().trim().optional().describe('目标字段'),
15
- file: z.string().trim().optional().describe('源文件'),
16
- page: z.coerce.number().int().nonnegative().optional().describe('页码'),
17
- // 几何/边界框信息
18
- bbox: z.array(z.number()).optional().describe('边界框'),
19
- xywh: z.array(z.number()).length(4, {
20
- error: 'xywh 必须包含4个数字 [x, y, width, height]'
21
- }).optional().describe('XYWH'),
22
- xyxy: z.array(z.number()).length(4, {
23
- error: 'xyxy 必须包含4个数字 [x1, y1, x2, y2]'
24
- }).optional().describe('XYXY'),
25
- polygon: z.array(z.number().array()).optional().describe('Polygon'),
26
- x: z.coerce.number().optional().describe('X 坐标'),
27
- y: z.coerce.number().optional().describe('Y 坐标'),
28
- w: z.coerce.number().nonnegative().optional().describe('宽度'),
29
- h: z.coerce.number().nonnegative().optional().describe('高度'),
30
- label: z.string().trim().optional().describe('标签'),
31
- confidence: z.coerce.number().min(0).max(1).optional().describe('置信度'),
32
- score: z.coerce.number().optional().describe('原始分数'),
33
- classes: z.array(z.object({
34
- label: z.string().nonempty({
35
- error: '分类标签不能为空'
36
- }).describe('分类标签'),
37
- confidence: z.coerce.number().min(0).max(1).optional().describe('分类置信度 (0-1)'),
38
- score: z.coerce.number().optional().describe('分类原始分数')
39
- })).optional().describe('多分类结果'),
40
- // 元数据和标签
41
- tags: z.array(z.string()).optional().describe('标签'),
42
- metadata: z.record(z.string(), z.any()).optional().describe('元数据'),
43
- attributes: z.record(z.string(), z.any()).optional().describe('属性'),
44
- properties: z.record(z.string(), z.any()).optional().describe('属性'),
45
- get annotations () {
46
- return z.array(ImageAnnotationSchema).optional().describe('子注释');
47
- }
3
+ id: z.string().optional(),
4
+ title: z.string().trim().optional().describe('标题'),
5
+ description: z.string().trim().optional().describe('描述'),
6
+ type: z.string().trim().optional().describe('类型'),
7
+ // 内容字段
8
+ text: z.string().optional().describe('文本内容'),
9
+ markdown: z.string().optional().describe('Markdown 内容'),
10
+ csv: z.string().optional().describe('CSV 内容'),
11
+ html: z.string().optional().describe('HTML 内容'),
12
+ data: z.any().optional().describe('任意数据'),
13
+ // 定位信息
14
+ field: z.string().trim().optional().describe('目标字段'),
15
+ file: z.string().trim().optional().describe('源文件'),
16
+ page: z.coerce.number().int().nonnegative().optional().describe('页码'),
17
+ // 几何/边界框信息
18
+ bbox: z.array(z.number()).optional().describe('边界框'),
19
+ xywh: z
20
+ .array(z.number())
21
+ .length(4, {
22
+ error: 'xywh 必须包含4个数字 [x, y, width, height]',
23
+ })
24
+ .optional()
25
+ .describe('XYWH'),
26
+ xyxy: z
27
+ .array(z.number())
28
+ .length(4, {
29
+ error: 'xyxy 必须包含4个数字 [x1, y1, x2, y2]',
30
+ })
31
+ .optional()
32
+ .describe('XYXY'),
33
+ polygon: z.array(z.number().array()).optional().describe('Polygon'),
34
+ x: z.coerce.number().optional().describe('X 坐标'),
35
+ y: z.coerce.number().optional().describe('Y 坐标'),
36
+ w: z.coerce.number().nonnegative().optional().describe('宽度'),
37
+ h: z.coerce.number().nonnegative().optional().describe('高度'),
38
+ label: z.string().trim().optional().describe('标签'),
39
+ confidence: z.coerce.number().min(0).max(1).optional().describe('置信度'),
40
+ score: z.coerce.number().optional().describe('原始分数'),
41
+ classes: z
42
+ .array(
43
+ z.object({
44
+ label: z
45
+ .string()
46
+ .nonempty({
47
+ error: '分类标签不能为空',
48
+ })
49
+ .describe('分类标签'),
50
+ confidence: z.coerce.number().min(0).max(1).optional().describe('分类置信度 (0-1)'),
51
+ score: z.coerce.number().optional().describe('分类原始分数'),
52
+ }),
53
+ )
54
+ .optional()
55
+ .describe('多分类结果'),
56
+ // 元数据和标签
57
+ tags: z.array(z.string()).optional().describe('标签'),
58
+ metadata: z.record(z.string(), z.any()).optional().describe('元数据'),
59
+ attributes: z.record(z.string(), z.any()).optional().describe('属性'),
60
+ properties: z.record(z.string(), z.any()).optional().describe('属性'),
61
+ get annotations() {
62
+ return z.array(ImageAnnotationSchema).optional().describe('子注释');
63
+ },
48
64
  });
49
65
 
50
- //# sourceMappingURL=ImageAnnotationSchema.js.map
66
+ //# sourceMappingURL=ImageAnnotationSchema.js.map
@@ -1,3 +1,3 @@
1
- export { ImageAnnotationSchema } from "./ImageAnnotationSchema.js";
2
- export { resolveImageAnnotation } from "./resolveImageAnnotation.js";
1
+ export { ImageAnnotationSchema } from './ImageAnnotationSchema.js';
2
+ export { resolveImageAnnotation } from './resolveImageAnnotation.js';
3
3
  //# sourceMappingURL=index.js.map
@@ -1,105 +1,91 @@
1
1
  export { resolveImageAnnotation };
2
2
  function resolveImageAnnotation(input) {
3
- const normalize = (input, { path = [], level = 0 } = {})=>{
4
- input.id ||= path.join('.') || 'ROOT';
5
- input.annotations ||= [];
6
- input.tags ||= [];
7
- input.attributes ||= {};
8
- input.metadata ||= {};
9
- if (!input.csv && input.html?.includes('<table') && globalThis.DOMParser) {
10
- const parser = new DOMParser();
11
- const doc = parser.parseFromString(input.html, 'text/html');
12
- const table = doc.querySelector('table');
13
- if (table) {
14
- const rows = Array.from(table.querySelectorAll('tr'));
15
- input.data = rows.map((row)=>Array.from(row.querySelectorAll('td')).map((td)=>td.textContent?.trim() || ''));
16
- }
17
- }
18
- input.annotations.forEach((v, i)=>normalize(v, {
19
- path: [
20
- ...path,
21
- i
22
- ],
23
- level: level + 1
24
- }));
25
- resolveBBox(input);
26
- // can get bbox from annotations
27
- let first = input.annotations.find((v)=>v.xyxy)?.xyxy;
28
- if (!input.xyxy && first) {
29
- const xyxy = input.annotations.reduce((acc, v)=>{
30
- if (!v.xyxy) return acc;
31
- return [
32
- Math.min(acc[0], v.xyxy[0]),
33
- Math.min(acc[1], v.xyxy[1]),
34
- Math.max(acc[2], v.xyxy[2]),
35
- Math.max(acc[3], v.xyxy[3])
36
- ];
37
- }, first);
38
- input.xyxy = xyxy;
39
- input.xywh = xyxy2xywh(xyxy);
40
- }
41
- };
42
- const out = input;
43
- normalize(out);
44
- // out.annotations.forEach((v) => norm(v));
45
- // only merge for root node
46
- if (!out.markdown) {
47
- out.markdown = out.annotations.map((v)=>v.markdown).join('\n');
48
- out.markdown ||= undefined;
49
- }
50
- if (!out.text) {
51
- out.text = out.annotations.map((v)=>v.text).join('\n');
52
- out.text ||= undefined;
53
- }
54
- // fallback
55
- out.text ||= out.markdown;
56
- out.markdown ||= out.text;
57
- return out;
3
+ const normalize = (input, { path = [], level = 0 } = {}) => {
4
+ input.id ||= path.join('.') || 'ROOT';
5
+ input.annotations ||= [];
6
+ input.tags ||= [];
7
+ input.attributes ||= {};
8
+ input.metadata ||= {};
9
+ if (!input.csv && input.html?.includes('<table') && globalThis.DOMParser) {
10
+ const parser = new DOMParser();
11
+ const doc = parser.parseFromString(input.html, 'text/html');
12
+ const table = doc.querySelector('table');
13
+ if (table) {
14
+ const rows = Array.from(table.querySelectorAll('tr'));
15
+ input.data = rows.map((row) =>
16
+ Array.from(row.querySelectorAll('td')).map((td) => td.textContent?.trim() || ''),
17
+ );
18
+ }
19
+ }
20
+ input.annotations.forEach((v, i) =>
21
+ normalize(v, {
22
+ path: [...path, i],
23
+ level: level + 1,
24
+ }),
25
+ );
26
+ resolveBBox(input);
27
+ // can get bbox from annotations
28
+ let first = input.annotations.find((v) => v.xyxy)?.xyxy;
29
+ if (!input.xyxy && first) {
30
+ const xyxy = input.annotations.reduce((acc, v) => {
31
+ if (!v.xyxy) return acc;
32
+ return [
33
+ Math.min(acc[0], v.xyxy[0]),
34
+ Math.min(acc[1], v.xyxy[1]),
35
+ Math.max(acc[2], v.xyxy[2]),
36
+ Math.max(acc[3], v.xyxy[3]),
37
+ ];
38
+ }, first);
39
+ input.xyxy = xyxy;
40
+ input.xywh = xyxy2xywh(xyxy);
41
+ }
42
+ };
43
+ const out = input;
44
+ normalize(out);
45
+ // out.annotations.forEach((v) => norm(v));
46
+ // only merge for root node
47
+ if (!out.markdown) {
48
+ out.markdown = out.annotations.map((v) => v.markdown).join('\n');
49
+ out.markdown ||= undefined;
50
+ }
51
+ if (!out.text) {
52
+ out.text = out.annotations.map((v) => v.text).join('\n');
53
+ out.text ||= undefined;
54
+ }
55
+ // fallback
56
+ out.text ||= out.markdown;
57
+ out.markdown ||= out.text;
58
+ return out;
58
59
  }
59
60
  function xywh2xyxy(input) {
60
- if (!input) return;
61
- const [x, y, w, h] = input;
62
- return [
63
- x,
64
- y,
65
- x + w,
66
- y + h
67
- ];
61
+ if (!input) return;
62
+ const [x, y, w, h] = input;
63
+ return [x, y, x + w, y + h];
68
64
  }
69
65
  function xyxy2xywh(input) {
70
- if (!input) return;
71
- const [x1, y1, x2, y2] = input;
72
- return [
73
- x1,
74
- y1,
75
- x2 - x1,
76
- y2 - y1
77
- ];
66
+ if (!input) return;
67
+ const [x1, y1, x2, y2] = input;
68
+ return [x1, y1, x2 - x1, y2 - y1];
78
69
  }
79
70
  function resolveBBox(input) {
80
- let { x, y, w, h } = input;
81
- let isNil = (v)=>v === undefined || v === null;
82
- if (isNil(x) && input.xywh?.length) {
83
- [x, y, w, h] = input.xywh;
84
- }
85
- if (isNil(x) && input.xyxy?.length) {
86
- [x, y, w, h] = xyxy2xywh(input.xyxy);
87
- }
88
- if (!isNil(x)) {
89
- input.xywh ||= [
90
- x,
91
- y,
92
- w,
93
- h
94
- ];
95
- input.xyxy ||= xywh2xyxy(input.xywh);
96
- input.x = x;
97
- input.y = y;
98
- input.w = w;
99
- input.h = h;
100
- return input;
101
- }
102
- return;
71
+ let { x, y, w, h } = input;
72
+ let isNil = (v) => v === undefined || v === null;
73
+ if (isNil(x) && input.xywh?.length) {
74
+ [x, y, w, h] = input.xywh;
75
+ }
76
+ if (isNil(x) && input.xyxy?.length) {
77
+ [x, y, w, h] = xyxy2xywh(input.xyxy);
78
+ }
79
+ if (!isNil(x)) {
80
+ input.xywh ||= [x, y, w, h];
81
+ input.xyxy ||= xywh2xyxy(input.xywh);
82
+ input.x = x;
83
+ input.y = y;
84
+ input.w = w;
85
+ input.h = h;
86
+ return input;
87
+ }
88
+ return;
103
89
  }
104
90
 
105
- //# sourceMappingURL=resolveImageAnnotation.js.map
91
+ //# sourceMappingURL=resolveImageAnnotation.js.map
@@ -1,48 +1,62 @@
1
- import { z } from "zod/v4";
2
- import { SexType, SexTypeSchema } from "../foundation/schema/index.js";
3
- import { Mod11 } from "./Mod11.js";
4
- export const ChineseResidentIdNoRegex = /^(?<division>[1-9]\d{5})(?<year>(18|19|20)\d{2})(?<month>0[1-9]|1[0-2])(?<day>0[1-9]|[12]\d|3[01])(?<sequence>\d{3})(?<checkDigit>[0-9Xx])$/;
5
- export const ParsedChineseResidentIdNoSchema = z.object({
6
- raw: z.string().regex(ChineseResidentIdNoRegex, "\u65E0\u6548\u768418\u4F4D\u8EAB\u4EFD\u8BC1\u53F7\u7801\u683C\u5F0F").describe("\u8EAB\u4EFD\u8BC1\u53F7\u7801"),
7
- addressCode: z.string().length(6).describe("\u5730\u5740\u7801 "),
8
- birthDate: z.iso.date().describe("\u51FA\u751F\u65E5\u671F"),
9
- sequence: z.int().max(999).min(0).describe("\u987A\u5E8F\u7801"),
10
- checkDigit: z.int().min(0).max(10).describe("\u6821\u9A8C\u7801"),
11
- sex: SexTypeSchema.describe("\u6027\u522B"),
12
- age: z.number().optional(),
13
- valid: z.boolean().optional().describe("\u662F\u5426\u6709\u6548")
14
- }).describe("\u5C45\u6C11\u8EAB\u4EFD\u8BC1\u53F7\u7801\u89E3\u6790\u5185\u5BB9");
1
+ import { z } from 'zod/v4';
2
+ import { SexType, SexTypeSchema } from '../foundation/schema/index.js';
3
+ import { Mod11 } from './Mod11.js';
4
+ export const ChineseResidentIdNoRegex =
5
+ /^(?<division>[1-9]\d{5})(?<year>(18|19|20)\d{2})(?<month>0[1-9]|1[0-2])(?<day>0[1-9]|[12]\d|3[01])(?<sequence>\d{3})(?<checkDigit>[0-9Xx])$/;
6
+ export const ParsedChineseResidentIdNoSchema = z
7
+ .object({
8
+ raw: z
9
+ .string()
10
+ .regex(ChineseResidentIdNoRegex, '\u65E0\u6548\u768418\u4F4D\u8EAB\u4EFD\u8BC1\u53F7\u7801\u683C\u5F0F')
11
+ .describe('\u8EAB\u4EFD\u8BC1\u53F7\u7801'),
12
+ addressCode: z.string().length(6).describe('\u5730\u5740\u7801 '),
13
+ birthDate: z.iso.date().describe('\u51FA\u751F\u65E5\u671F'),
14
+ sequence: z.int().max(999).min(0).describe('\u987A\u5E8F\u7801'),
15
+ checkDigit: z.int().min(0).max(10).describe('\u6821\u9A8C\u7801'),
16
+ sex: SexTypeSchema.describe('\u6027\u522B'),
17
+ age: z.number().optional(),
18
+ valid: z.boolean().optional().describe('\u662F\u5426\u6709\u6548'),
19
+ })
20
+ .describe('\u5C45\u6C11\u8EAB\u4EFD\u8BC1\u53F7\u7801\u89E3\u6790\u5185\u5BB9');
15
21
  export function parseChineseResidentIdNo(idNo) {
16
- const reg = ChineseResidentIdNoRegex;
17
- const match = idNo.match(reg);
18
- if (!match || !match.groups) {
19
- return undefined;
20
- }
21
- const { division, year, month, day, sequence, checkDigit } = match.groups;
22
- let seq = parseInt(sequence, 10);
23
- return {
24
- raw: idNo,
25
- addressCode: division,
26
- birthDate: `${year}-${month}-${day}`,
27
- sequence: seq,
28
- checkDigit: checkDigit.toUpperCase() === "X" ? 10 : parseInt(checkDigit),
29
- sex: seq % 2 === 0 ? SexType.Male : SexType.Female,
30
- age: new Date().getFullYear() - parseInt(year, 10),
31
- valid: Mod11.validate(idNo)
32
- };
22
+ const reg = ChineseResidentIdNoRegex;
23
+ const match = idNo.match(reg);
24
+ if (!match || !match.groups) {
25
+ return undefined;
26
+ }
27
+ const { division, year, month, day, sequence, checkDigit } = match.groups;
28
+ let seq = parseInt(sequence, 10);
29
+ return {
30
+ raw: idNo,
31
+ addressCode: division,
32
+ birthDate: `${year}-${month}-${day}`,
33
+ sequence: seq,
34
+ checkDigit: checkDigit.toUpperCase() === 'X' ? 10 : parseInt(checkDigit, 10),
35
+ sex: seq % 2 === 0 ? SexType.Male : SexType.Female,
36
+ age: new Date().getFullYear() - parseInt(year, 10),
37
+ valid: Mod11.validate(idNo),
38
+ };
33
39
  }
34
40
  export function formatChineseResidentIdNo({ addressCode, birthDate, sequence, checkDigit }) {
35
- const date = typeof birthDate === "string" ? birthDate.replace(/-/g, "") : `${birthDate.getFullYear()}${String(birthDate.getMonth() + 1).padStart(2, "0")}${String(birthDate.getDate()).padStart(2, "0")}`;
36
- const seq = String(sequence).padStart(3, "0");
37
- const major = `${addressCode}${date}${seq}`;
38
- const check = typeof checkDigit === "number" ? checkDigit === 10 ? "X" : String(checkDigit) : checkDigit?.toUpperCase() || Mod11.compute(major);
39
- return `${major}${check}`;
41
+ const date =
42
+ typeof birthDate === 'string'
43
+ ? birthDate.replace(/-/g, '')
44
+ : `${birthDate.getFullYear()}${String(birthDate.getMonth() + 1).padStart(2, '0')}${String(birthDate.getDate()).padStart(2, '0')}`;
45
+ const seq = String(sequence).padStart(3, '0');
46
+ const major = `${addressCode}${date}${seq}`;
47
+ const check =
48
+ typeof checkDigit === 'number'
49
+ ? checkDigit === 10
50
+ ? 'X'
51
+ : String(checkDigit)
52
+ : checkDigit?.toUpperCase() || Mod11.compute(major);
53
+ return `${major}${check}`;
40
54
  }
41
- (function (ChineseResidentIdNo) {
42
- ChineseResidentIdNo.regex = ChineseResidentIdNoRegex;
43
- ChineseResidentIdNo.parse = parseChineseResidentIdNo;
44
- ChineseResidentIdNo.format = formatChineseResidentIdNo;
45
- ChineseResidentIdNo.ResultSchema = ParsedChineseResidentIdNoSchema;
55
+ ((ChineseResidentIdNo) => {
56
+ ChineseResidentIdNo.regex = ChineseResidentIdNoRegex;
57
+ ChineseResidentIdNo.parse = parseChineseResidentIdNo;
58
+ ChineseResidentIdNo.format = formatChineseResidentIdNo;
59
+ ChineseResidentIdNo.ResultSchema = ParsedChineseResidentIdNoSchema;
46
60
  })(ChineseResidentIdNo || (ChineseResidentIdNo = {}));
47
61
  export var ChineseResidentIdNo;
48
62
  //# sourceMappingURL=ChineseResidentIdNo.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cn/ChineseResidentIdNo.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport { SexType, SexTypeSchema } from '../foundation/schema';\nimport { Mod11 } from './Mod11';\n\nexport const ChineseResidentIdNoRegex =\n\t/^(?<division>[1-9]\\d{5})(?<year>(18|19|20)\\d{2})(?<month>0[1-9]|1[0-2])(?<day>0[1-9]|[12]\\d|3[01])(?<sequence>\\d{3})(?<checkDigit>[0-9Xx])$/;\n\nexport type ParsedChineseResidentIdNo = z.infer<typeof ParsedChineseResidentIdNoSchema>;\nexport const ParsedChineseResidentIdNoSchema = z\n\t.object({\n\t\traw: z.string().regex(ChineseResidentIdNoRegex, '无效的18位身份证号码格式').describe('身份证号码'),\n\t\taddressCode: z.string().length(6).describe('地址码 '),\n\t\tbirthDate: z.iso.date().describe('出生日期'),\n\t\tsequence: z.int().max(999).min(0).describe('顺序码'),\n\t\tcheckDigit: z.int().min(0).max(10).describe('校验码'),\n\t\tsex: SexTypeSchema.describe('性别'),\n\t\tage: z.number().optional(),\n\t\tvalid: z.boolean().optional().describe('是否有效'),\n\t})\n\t.describe('居民身份证号码解析内容');\n\nexport function parseChineseResidentIdNo(idNo: string): ParsedChineseResidentIdNo | undefined {\n\tconst reg = ChineseResidentIdNoRegex;\n\tconst match = idNo.match(reg);\n\tif (!match || !match.groups) {\n\t\treturn undefined;\n\t}\n\tconst { division, year, month, day, sequence, checkDigit } = match.groups;\n\tlet seq = parseInt(sequence, 10);\n\treturn {\n\t\traw: idNo,\n\t\taddressCode: division,\n\t\tbirthDate: `${year}-${month}-${day}`,\n\t\tsequence: seq,\n\t\tcheckDigit: checkDigit.toUpperCase() === 'X' ? 10 : parseInt(checkDigit),\n\t\tsex: seq % 2 === 0 ? SexType.Male : SexType.Female,\n\t\tage: new Date().getFullYear() - parseInt(year, 10),\n\t\tvalid: Mod11.validate(idNo),\n\t};\n}\n\nexport function formatChineseResidentIdNo({\n\taddressCode,\n\tbirthDate,\n\tsequence,\n\tcheckDigit,\n}: {\n\taddressCode: string;\n\tbirthDate: string | Date;\n\tsequence: number | string;\n\tcheckDigit?: string | number;\n}): string {\n\tconst date =\n\t\ttypeof birthDate === 'string'\n\t\t\t? birthDate.replace(/-/g, '')\n\t\t\t: `${birthDate.getFullYear()}${String(birthDate.getMonth() + 1).padStart(2, '0')}${String(birthDate.getDate()).padStart(2, '0')}`;\n\tconst seq = String(sequence).padStart(3, '0');\n\tconst major = `${addressCode}${date}${seq}`;\n\tconst check =\n\t\ttypeof checkDigit === 'number'\n\t\t\t? checkDigit === 10\n\t\t\t\t? 'X'\n\t\t\t\t: String(checkDigit)\n\t\t\t: checkDigit?.toUpperCase() || Mod11.compute(major);\n\treturn `${major}${check}`;\n}\n\nexport namespace ChineseResidentIdNo {\n\texport const regex = ChineseResidentIdNoRegex;\n\texport const parse = parseChineseResidentIdNo;\n\texport const format = formatChineseResidentIdNo;\n\texport type Result = ParsedChineseResidentIdNo;\n\texport const ResultSchema = ParsedChineseResidentIdNoSchema;\n}\n"],"names":["z","SexType","SexTypeSchema","Mod11","ChineseResidentIdNoRegex","ParsedChineseResidentIdNoSchema","object","raw","string","regex","describe","addressCode","length","birthDate","iso","date","sequence","int","max","min","checkDigit","sex","age","number","optional","valid","boolean","parseChineseResidentIdNo","idNo","reg","match","groups","undefined","division","year","month","day","seq","parseInt","toUpperCase","Male","Female","Date","getFullYear","validate","formatChineseResidentIdNo","replace","String","getMonth","padStart","getDate","major","check","compute","ChineseResidentIdNo","parse","format","ResultSchema"],"mappings":"AAAA,SAASA,CAAC,QAAQ,SAAS;AAC3B,SAASC,OAAO,EAAEC,aAAa,QAAQ,uBAAuB;AAC9D,SAASC,KAAK,QAAQ,UAAU;AAEhC,OAAO,MAAMC,2BACZ,8IAA8I;AAG/I,OAAO,MAAMC,kCAAkCL,EAC7CM,MAAM,CAAC;IACPC,KAAKP,EAAEQ,MAAM,GAAGC,KAAK,CAACL,0BAA0B,iBAAiBM,QAAQ,CAAC;IAC1EC,aAAaX,EAAEQ,MAAM,GAAGI,MAAM,CAAC,GAAGF,QAAQ,CAAC;IAC3CG,WAAWb,EAAEc,GAAG,CAACC,IAAI,GAAGL,QAAQ,CAAC;IACjCM,UAAUhB,EAAEiB,GAAG,GAAGC,GAAG,CAAC,KAAKC,GAAG,CAAC,GAAGT,QAAQ,CAAC;IAC3CU,YAAYpB,EAAEiB,GAAG,GAAGE,GAAG,CAAC,GAAGD,GAAG,CAAC,IAAIR,QAAQ,CAAC;IAC5CW,KAAKnB,cAAcQ,QAAQ,CAAC;IAC5BY,KAAKtB,EAAEuB,MAAM,GAAGC,QAAQ;IACxBC,OAAOzB,EAAE0B,OAAO,GAAGF,QAAQ,GAAGd,QAAQ,CAAC;AACxC,GACCA,QAAQ,CAAC,eAAe;AAE1B,OAAO,SAASiB,yBAAyBC,IAAY;IACpD,MAAMC,MAAMzB;IACZ,MAAM0B,QAAQF,KAAKE,KAAK,CAACD;IACzB,IAAI,CAACC,SAAS,CAACA,MAAMC,MAAM,EAAE;QAC5B,OAAOC;IACR;IACA,MAAM,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,KAAK,EAAEC,GAAG,EAAEpB,QAAQ,EAAEI,UAAU,EAAE,GAAGU,MAAMC,MAAM;IACzE,IAAIM,MAAMC,SAAStB,UAAU;IAC7B,OAAO;QACNT,KAAKqB;QACLjB,aAAasB;QACbpB,WAAW,GAAGqB,KAAK,CAAC,EAAEC,MAAM,CAAC,EAAEC,KAAK;QACpCpB,UAAUqB;QACVjB,YAAYA,WAAWmB,WAAW,OAAO,MAAM,KAAKD,SAASlB;QAC7DC,KAAKgB,MAAM,MAAM,IAAIpC,QAAQuC,IAAI,GAAGvC,QAAQwC,MAAM;QAClDnB,KAAK,IAAIoB,OAAOC,WAAW,KAAKL,SAASJ,MAAM;QAC/CT,OAAOtB,MAAMyC,QAAQ,CAAChB;IACvB;AACD;AAEA,OAAO,SAASiB,0BAA0B,EACzClC,WAAW,EACXE,SAAS,EACTG,QAAQ,EACRI,UAAU,EAMV;IACA,MAAML,OACL,OAAOF,cAAc,WAClBA,UAAUiC,OAAO,CAAC,MAAM,MACxB,GAAGjC,UAAU8B,WAAW,KAAKI,OAAOlC,UAAUmC,QAAQ,KAAK,GAAGC,QAAQ,CAAC,GAAG,OAAOF,OAAOlC,UAAUqC,OAAO,IAAID,QAAQ,CAAC,GAAG,MAAM;IACnI,MAAMZ,MAAMU,OAAO/B,UAAUiC,QAAQ,CAAC,GAAG;IACzC,MAAME,QAAQ,GAAGxC,cAAcI,OAAOsB,KAAK;IAC3C,MAAMe,QACL,OAAOhC,eAAe,WACnBA,eAAe,KACd,MACA2B,OAAO3B,cACRA,YAAYmB,iBAAiBpC,MAAMkD,OAAO,CAACF;IAC/C,OAAO,GAAGA,QAAQC,OAAO;AAC1B;UAEiBE;wBACH7C,QAAQL;wBACRmD,QAAQ5B;wBACR6B,SAASX;wBAETY,eAAepD;AAC7B,GANiBiD,wBAAAA"}
1
+ {"version":3,"sources":["../../src/cn/ChineseResidentIdNo.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport { SexType, SexTypeSchema } from '../foundation/schema';\nimport { Mod11 } from './Mod11';\n\nexport const ChineseResidentIdNoRegex =\n\t/^(?<division>[1-9]\\d{5})(?<year>(18|19|20)\\d{2})(?<month>0[1-9]|1[0-2])(?<day>0[1-9]|[12]\\d|3[01])(?<sequence>\\d{3})(?<checkDigit>[0-9Xx])$/;\n\nexport type ParsedChineseResidentIdNo = z.infer<typeof ParsedChineseResidentIdNoSchema>;\nexport const ParsedChineseResidentIdNoSchema = z\n\t.object({\n\t\traw: z.string().regex(ChineseResidentIdNoRegex, '无效的18位身份证号码格式').describe('身份证号码'),\n\t\taddressCode: z.string().length(6).describe('地址码 '),\n\t\tbirthDate: z.iso.date().describe('出生日期'),\n\t\tsequence: z.int().max(999).min(0).describe('顺序码'),\n\t\tcheckDigit: z.int().min(0).max(10).describe('校验码'),\n\t\tsex: SexTypeSchema.describe('性别'),\n\t\tage: z.number().optional(),\n\t\tvalid: z.boolean().optional().describe('是否有效'),\n\t})\n\t.describe('居民身份证号码解析内容');\n\nexport function parseChineseResidentIdNo(idNo: string): ParsedChineseResidentIdNo | undefined {\n\tconst reg = ChineseResidentIdNoRegex;\n\tconst match = idNo.match(reg);\n\tif (!match || !match.groups) {\n\t\treturn undefined;\n\t}\n\tconst { division, year, month, day, sequence, checkDigit } = match.groups;\n\tlet seq = parseInt(sequence, 10);\n\treturn {\n\t\traw: idNo,\n\t\taddressCode: division,\n\t\tbirthDate: `${year}-${month}-${day}`,\n\t\tsequence: seq,\n\t\tcheckDigit: checkDigit.toUpperCase() === 'X' ? 10 : parseInt(checkDigit, 10),\n\t\tsex: seq % 2 === 0 ? SexType.Male : SexType.Female,\n\t\tage: new Date().getFullYear() - parseInt(year, 10),\n\t\tvalid: Mod11.validate(idNo),\n\t};\n}\n\nexport function formatChineseResidentIdNo({\n\taddressCode,\n\tbirthDate,\n\tsequence,\n\tcheckDigit,\n}: {\n\taddressCode: string;\n\tbirthDate: string | Date;\n\tsequence: number | string;\n\tcheckDigit?: string | number;\n}): string {\n\tconst date =\n\t\ttypeof birthDate === 'string'\n\t\t\t? birthDate.replace(/-/g, '')\n\t\t\t: `${birthDate.getFullYear()}${String(birthDate.getMonth() + 1).padStart(2, '0')}${String(birthDate.getDate()).padStart(2, '0')}`;\n\tconst seq = String(sequence).padStart(3, '0');\n\tconst major = `${addressCode}${date}${seq}`;\n\tconst check =\n\t\ttypeof checkDigit === 'number'\n\t\t\t? checkDigit === 10\n\t\t\t\t? 'X'\n\t\t\t\t: String(checkDigit)\n\t\t\t: checkDigit?.toUpperCase() || Mod11.compute(major);\n\treturn `${major}${check}`;\n}\n\nexport namespace ChineseResidentIdNo {\n\texport const regex = ChineseResidentIdNoRegex;\n\texport const parse = parseChineseResidentIdNo;\n\texport const format = formatChineseResidentIdNo;\n\texport type Result = ParsedChineseResidentIdNo;\n\texport const ResultSchema = ParsedChineseResidentIdNoSchema;\n}\n"],"names":["z","SexType","SexTypeSchema","Mod11","ChineseResidentIdNoRegex","ParsedChineseResidentIdNoSchema","object","raw","string","regex","describe","addressCode","length","birthDate","iso","date","sequence","int","max","min","checkDigit","sex","age","number","optional","valid","boolean","parseChineseResidentIdNo","idNo","reg","match","groups","undefined","division","year","month","day","seq","parseInt","toUpperCase","Male","Female","Date","getFullYear","validate","formatChineseResidentIdNo","replace","String","getMonth","padStart","getDate","major","check","compute","ChineseResidentIdNo","parse","format","ResultSchema"],"mappings":"AAAA,SAASA,CAAC,QAAQ,SAAS;AAC3B,SAASC,OAAO,EAAEC,aAAa,QAAQ,uBAAuB;AAC9D,SAASC,KAAK,QAAQ,UAAU;AAEhC,OAAO,MAAMC,2BACZ,8IAA8I;AAG/I,OAAO,MAAMC,kCAAkCL,EAC7CM,MAAM,CAAC;IACPC,KAAKP,EAAEQ,MAAM,GAAGC,KAAK,CAACL,0BAA0B,iBAAiBM,QAAQ,CAAC;IAC1EC,aAAaX,EAAEQ,MAAM,GAAGI,MAAM,CAAC,GAAGF,QAAQ,CAAC;IAC3CG,WAAWb,EAAEc,GAAG,CAACC,IAAI,GAAGL,QAAQ,CAAC;IACjCM,UAAUhB,EAAEiB,GAAG,GAAGC,GAAG,CAAC,KAAKC,GAAG,CAAC,GAAGT,QAAQ,CAAC;IAC3CU,YAAYpB,EAAEiB,GAAG,GAAGE,GAAG,CAAC,GAAGD,GAAG,CAAC,IAAIR,QAAQ,CAAC;IAC5CW,KAAKnB,cAAcQ,QAAQ,CAAC;IAC5BY,KAAKtB,EAAEuB,MAAM,GAAGC,QAAQ;IACxBC,OAAOzB,EAAE0B,OAAO,GAAGF,QAAQ,GAAGd,QAAQ,CAAC;AACxC,GACCA,QAAQ,CAAC,eAAe;AAE1B,OAAO,SAASiB,yBAAyBC,IAAY;IACpD,MAAMC,MAAMzB;IACZ,MAAM0B,QAAQF,KAAKE,KAAK,CAACD;IACzB,IAAI,CAACC,SAAS,CAACA,MAAMC,MAAM,EAAE;QAC5B,OAAOC;IACR;IACA,MAAM,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,KAAK,EAAEC,GAAG,EAAEpB,QAAQ,EAAEI,UAAU,EAAE,GAAGU,MAAMC,MAAM;IACzE,IAAIM,MAAMC,SAAStB,UAAU;IAC7B,OAAO;QACNT,KAAKqB;QACLjB,aAAasB;QACbpB,WAAW,GAAGqB,KAAK,CAAC,EAAEC,MAAM,CAAC,EAAEC,KAAK;QACpCpB,UAAUqB;QACVjB,YAAYA,WAAWmB,WAAW,OAAO,MAAM,KAAKD,SAASlB,YAAY;QACzEC,KAAKgB,MAAM,MAAM,IAAIpC,QAAQuC,IAAI,GAAGvC,QAAQwC,MAAM;QAClDnB,KAAK,IAAIoB,OAAOC,WAAW,KAAKL,SAASJ,MAAM;QAC/CT,OAAOtB,MAAMyC,QAAQ,CAAChB;IACvB;AACD;AAEA,OAAO,SAASiB,0BAA0B,EACzClC,WAAW,EACXE,SAAS,EACTG,QAAQ,EACRI,UAAU,EAMV;IACA,MAAML,OACL,OAAOF,cAAc,WAClBA,UAAUiC,OAAO,CAAC,MAAM,MACxB,GAAGjC,UAAU8B,WAAW,KAAKI,OAAOlC,UAAUmC,QAAQ,KAAK,GAAGC,QAAQ,CAAC,GAAG,OAAOF,OAAOlC,UAAUqC,OAAO,IAAID,QAAQ,CAAC,GAAG,MAAM;IACnI,MAAMZ,MAAMU,OAAO/B,UAAUiC,QAAQ,CAAC,GAAG;IACzC,MAAME,QAAQ,GAAGxC,cAAcI,OAAOsB,KAAK;IAC3C,MAAMe,QACL,OAAOhC,eAAe,WACnBA,eAAe,KACd,MACA2B,OAAO3B,cACRA,YAAYmB,iBAAiBpC,MAAMkD,OAAO,CAACF;IAC/C,OAAO,GAAGA,QAAQC,OAAO;AAC1B;UAEiBE;wBACH7C,QAAQL;wBACRmD,QAAQ5B;wBACR6B,SAASX;wBAETY,eAAepD;AAC7B,GANiBiD,wBAAAA"}
@@ -1 +1,6 @@
1
- export { ChineseResidentIdNoRegex as regex, parseChineseResidentIdNo as parse, formatChineseResidentIdNo as format, ParsedChineseResidentIdNoSchema as ResultSchema } from "./ChineseResidentIdNo.js";
1
+ export {
2
+ ChineseResidentIdNoRegex as regex,
3
+ formatChineseResidentIdNo as format,
4
+ ParsedChineseResidentIdNoSchema as ResultSchema,
5
+ parseChineseResidentIdNo as parse,
6
+ } from './ChineseResidentIdNo.js';
@@ -1,22 +1,23 @@
1
- import { describe, expect, it } from "vitest";
2
- import { ChineseResidentIdNo } from "./index.js";
3
- describe("ChineseResidentIdNo", function () {
4
- it("should parse", function () {
5
- for (var _i = 0, _iter = [
6
- "11010519491231002X"
7
- ]; _i < _iter.length; _i++) {
8
- var a = _iter[_i];
9
- var out = ChineseResidentIdNo.parse(a);
10
- expect(out).toBeTruthy();
11
- expect(ChineseResidentIdNo.format(out)).toBe(a);
12
- expect(out).toMatchSnapshot();
13
- }
14
- });
15
- it("should format with partial", function () {
16
- expect(ChineseResidentIdNo.format({
17
- addressCode: "110105",
18
- birthDate: new Date("1949-12-31"),
19
- sequence: 2
20
- })).toBe("11010519491231002X");
21
- });
1
+ import { describe, expect, it } from 'vitest';
2
+ import { ChineseResidentIdNo } from './index.js';
3
+
4
+ describe('ChineseResidentIdNo', () => {
5
+ it('should parse', () => {
6
+ for (var _i = 0, _iter = ['11010519491231002X']; _i < _iter.length; _i++) {
7
+ var a = _iter[_i];
8
+ var out = ChineseResidentIdNo.parse(a);
9
+ expect(out).toBeTruthy();
10
+ expect(ChineseResidentIdNo.format(out)).toBe(a);
11
+ expect(out).toMatchSnapshot();
12
+ }
13
+ });
14
+ it('should format with partial', () => {
15
+ expect(
16
+ ChineseResidentIdNo.format({
17
+ addressCode: '110105',
18
+ birthDate: new Date('1949-12-31'),
19
+ sequence: 2,
20
+ }),
21
+ ).toBe('11010519491231002X');
22
+ });
22
23
  });