@wener/common 2.0.3 → 2.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 (168) hide show
  1. package/lib/ai/qwen3vl/utils.js.map +1 -1
  2. package/lib/cn/ChineseResidentIdNo.js +1 -1
  3. package/lib/cn/ChineseResidentIdNo.js.map +1 -1
  4. package/lib/cn/Mod11.js +1 -1
  5. package/lib/cn/Mod11.js.map +1 -1
  6. package/lib/consola/formatLogObject.js +5 -5
  7. package/lib/consola/formatLogObject.js.map +1 -1
  8. package/lib/data/maybeNumber.js +1 -1
  9. package/lib/data/maybeNumber.js.map +1 -1
  10. package/lib/data/types.d.js.map +1 -1
  11. package/lib/dayjs/formatDuration.js.map +1 -1
  12. package/lib/dayjs/resolveRelativeTime.js +9 -80
  13. package/lib/dayjs/resolveRelativeTime.js.map +1 -1
  14. package/lib/drain3/Drain.js +356 -0
  15. package/lib/drain3/Drain.js.map +1 -0
  16. package/lib/drain3/LogCluster.js +38 -0
  17. package/lib/drain3/LogCluster.js.map +1 -0
  18. package/lib/drain3/Node.js +39 -0
  19. package/lib/drain3/Node.js.map +1 -0
  20. package/lib/drain3/TemplateMiner.js +204 -0
  21. package/lib/drain3/TemplateMiner.js.map +1 -0
  22. package/lib/drain3/index.js +31 -0
  23. package/lib/drain3/index.js.map +1 -0
  24. package/lib/drain3/persistence/FilePersistence.js +24 -0
  25. package/lib/drain3/persistence/FilePersistence.js.map +1 -0
  26. package/lib/drain3/persistence/MemoryPersistence.js +18 -0
  27. package/lib/drain3/persistence/MemoryPersistence.js.map +1 -0
  28. package/lib/drain3/persistence/PersistenceHandler.js +5 -0
  29. package/lib/drain3/persistence/PersistenceHandler.js.map +1 -0
  30. package/lib/drain3/types.js +7 -0
  31. package/lib/drain3/types.js.map +1 -0
  32. package/lib/fs/IFileSystem.d.js.map +1 -1
  33. package/lib/fs/createBrowserFileSystem.js +4 -2
  34. package/lib/fs/createBrowserFileSystem.js.map +1 -1
  35. package/lib/fs/createMemoryFileSystem.js +7 -6
  36. package/lib/fs/createMemoryFileSystem.js.map +1 -1
  37. package/lib/fs/createSandboxFileSystem.js.map +1 -1
  38. package/lib/fs/createWebDavFileSystem.js +22 -5
  39. package/lib/fs/createWebDavFileSystem.js.map +1 -1
  40. package/lib/fs/createWebFileSystem.js +225 -0
  41. package/lib/fs/createWebFileSystem.js.map +1 -0
  42. package/lib/fs/findMimeType.js +1 -1
  43. package/lib/fs/findMimeType.js.map +1 -1
  44. package/lib/fs/index.js +1 -1
  45. package/lib/fs/index.js.map +1 -1
  46. package/lib/fs/minio/createMinioFileSystem.js +974 -0
  47. package/lib/fs/minio/createMinioFileSystem.js.map +1 -0
  48. package/lib/fs/minio/index.js +2 -0
  49. package/lib/fs/minio/index.js.map +1 -0
  50. package/lib/fs/orpc/createContractClientFileSystem.js +3 -3
  51. package/lib/fs/orpc/createContractClientFileSystem.js.map +1 -1
  52. package/lib/fs/orpc/server/createFileSystemContractImpl.js.map +1 -1
  53. package/lib/fs/s3/createS3MiniFileSystem.js +116 -68
  54. package/lib/fs/s3/createS3MiniFileSystem.js.map +1 -1
  55. package/lib/fs/server/createDatabaseFileSystem.js +7 -7
  56. package/lib/fs/server/createDatabaseFileSystem.js.map +1 -1
  57. package/lib/fs/server/createNodeFileSystem.js +30 -5
  58. package/lib/fs/server/createNodeFileSystem.js.map +1 -1
  59. package/lib/fs/tests/runFileSystemTest.js +27 -26
  60. package/lib/fs/tests/runFileSystemTest.js.map +1 -1
  61. package/lib/fs/utils.js.map +1 -1
  62. package/lib/fs/webdav/index.js +2 -0
  63. package/lib/fs/webdav/index.js.map +1 -0
  64. package/lib/jsonschema/JsonSchema.js +5 -5
  65. package/lib/jsonschema/JsonSchema.js.map +1 -1
  66. package/lib/jsonschema/forEachJsonSchema.js +1 -1
  67. package/lib/jsonschema/forEachJsonSchema.js.map +1 -1
  68. package/lib/jsonschema/types.d.js.map +1 -1
  69. package/lib/meta/defineMetadata.js.map +1 -1
  70. package/lib/orpc/createOpenApiContractClient.js.map +1 -1
  71. package/lib/password/PHC.js +2 -2
  72. package/lib/password/PHC.js.map +1 -1
  73. package/lib/password/createArgon2PasswordAlgorithm.js.map +1 -1
  74. package/lib/password/createBase64PasswordAlgorithm.js +1 -1
  75. package/lib/password/createBase64PasswordAlgorithm.js.map +1 -1
  76. package/lib/password/createBcryptPasswordAlgorithm.js.map +1 -1
  77. package/lib/password/createPBKDF2PasswordAlgorithm.js +1 -1
  78. package/lib/password/createPBKDF2PasswordAlgorithm.js.map +1 -1
  79. package/lib/password/createScryptPasswordAlgorithm.js +3 -3
  80. package/lib/password/createScryptPasswordAlgorithm.js.map +1 -1
  81. package/lib/resource/ListQuery.js.map +1 -1
  82. package/lib/resource/index.js.map +1 -1
  83. package/lib/s3/formatS3Url.js +2 -2
  84. package/lib/s3/formatS3Url.js.map +1 -1
  85. package/lib/s3/parseS3Url.js +1 -1
  86. package/lib/s3/parseS3Url.js.map +1 -1
  87. package/lib/schema/SchemaRegistry.js.map +1 -1
  88. package/lib/schema/TypeSchema.d.js.map +1 -1
  89. package/lib/schema/createSchemaData.js +4 -4
  90. package/lib/schema/createSchemaData.js.map +1 -1
  91. package/lib/schema/findJsonSchemaByPath.js.map +1 -1
  92. package/lib/schema/formatZodError.js +42 -44
  93. package/lib/schema/formatZodError.js.map +1 -1
  94. package/lib/schema/toJsonSchema.js +4 -4
  95. package/lib/schema/toJsonSchema.js.map +1 -1
  96. package/lib/schema/validate.js +1 -1
  97. package/lib/schema/validate.js.map +1 -1
  98. package/lib/utils/buildRedactorFormSchema.js +1 -1
  99. package/lib/utils/buildRedactorFormSchema.js.map +1 -1
  100. package/package.json +32 -13
  101. package/src/ai/qwen3vl/utils.ts +1 -1
  102. package/src/cn/ChineseResidentIdNo.ts +1 -1
  103. package/src/cn/Mod11.ts +1 -1
  104. package/src/cn/__snapshots__/ChineseResidentIdNo.test.ts.snap +1 -1
  105. package/src/cn/__snapshots__/UnifiedSocialCreditCode.test.ts.snap +0 -23
  106. package/src/cn/parseChineseNumber.test.ts +4 -4
  107. package/src/consola/formatLogObject.ts +6 -6
  108. package/src/data/maybeNumber.ts +1 -1
  109. package/src/data/parseSort.test.ts +0 -1
  110. package/src/data/types.d.ts +2 -2
  111. package/src/dayjs/formatDuration.ts +2 -2
  112. package/src/dayjs/resolveRelativeTime.ts +11 -14
  113. package/src/drain3/Drain.test.ts +378 -0
  114. package/src/drain3/Drain.ts +394 -0
  115. package/src/drain3/LogCluster.ts +46 -0
  116. package/src/drain3/Node.ts +53 -0
  117. package/src/drain3/TemplateMiner.ts +246 -0
  118. package/src/drain3/index.ts +36 -0
  119. package/src/drain3/persistence/FilePersistence.ts +24 -0
  120. package/src/drain3/persistence/MemoryPersistence.ts +23 -0
  121. package/src/drain3/persistence/PersistenceHandler.ts +19 -0
  122. package/src/drain3/types.ts +75 -0
  123. package/src/fs/IFileSystem.d.ts +1 -2
  124. package/src/fs/createBrowserFileSystem.ts +7 -5
  125. package/src/fs/createMemoryFileSystem.ts +9 -13
  126. package/src/fs/createSandboxFileSystem.ts +1 -1
  127. package/src/fs/createWebDavFileSystem.ts +28 -10
  128. package/src/fs/createWebFileSystem.ts +242 -0
  129. package/src/fs/findMimeType.ts +1 -4
  130. package/src/fs/index.ts +1 -1
  131. package/src/fs/minio/createMinioFileSystem.ts +1148 -0
  132. package/src/fs/minio/index.ts +1 -0
  133. package/src/fs/orpc/createContractClientFileSystem.ts +5 -5
  134. package/src/fs/orpc/server/createFileSystemContractImpl.ts +1 -1
  135. package/src/fs/s3/createS3MiniFileSystem.ts +119 -78
  136. package/src/fs/s3/s3fs.test.ts +441 -0
  137. package/src/fs/s3/s3mini.test.ts +2 -2
  138. package/src/fs/server/createDatabaseFileSystem.ts +7 -7
  139. package/src/fs/server/createNodeFileSystem.ts +32 -13
  140. package/src/fs/server/dbfs.test.ts +2 -1
  141. package/src/fs/tests/runFileSystemTest.ts +29 -28
  142. package/src/fs/utils.ts +1 -1
  143. package/src/fs/webdav/index.ts +1 -0
  144. package/src/jsonschema/JsonSchema.ts +5 -5
  145. package/src/jsonschema/forEachJsonSchema.ts +1 -1
  146. package/src/jsonschema/types.d.ts +1 -1
  147. package/src/meta/defineMetadata.ts +1 -1
  148. package/src/orpc/createOpenApiContractClient.ts +2 -2
  149. package/src/password/PHC.ts +3 -3
  150. package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
  151. package/src/password/createBase64PasswordAlgorithm.ts +2 -2
  152. package/src/password/createBcryptPasswordAlgorithm.ts +4 -2
  153. package/src/password/createPBKDF2PasswordAlgorithm.ts +2 -2
  154. package/src/password/createScryptPasswordAlgorithm.ts +4 -4
  155. package/src/resource/ListQuery.ts +4 -1
  156. package/src/resource/index.ts +2 -2
  157. package/src/s3/formatS3Url.test.ts +1 -1
  158. package/src/s3/formatS3Url.ts +2 -2
  159. package/src/s3/parseS3Url.ts +1 -1
  160. package/src/schema/SchemaRegistry.ts +1 -1
  161. package/src/schema/TypeSchema.d.ts +6 -6
  162. package/src/schema/createSchemaData.ts +4 -4
  163. package/src/schema/findJsonSchemaByPath.ts +4 -4
  164. package/src/schema/formatZodError.test.ts +2 -1
  165. package/src/schema/formatZodError.ts +50 -62
  166. package/src/schema/toJsonSchema.ts +6 -6
  167. package/src/schema/validate.ts +1 -1
  168. package/src/utils/buildRedactorFormSchema.ts +3 -3
@@ -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"}
@@ -25,7 +25,7 @@ export function parseChineseResidentIdNo(idNo) {
25
25
  addressCode: division,
26
26
  birthDate: `${year}-${month}-${day}`,
27
27
  sequence: seq,
28
- checkDigit: checkDigit.toUpperCase() === "X" ? 10 : parseInt(checkDigit),
28
+ checkDigit: checkDigit.toUpperCase() === "X" ? 10 : parseInt(checkDigit, 10),
29
29
  sex: seq % 2 === 0 ? SexType.Male : SexType.Female,
30
30
  age: new Date().getFullYear() - parseInt(year, 10),
31
31
  valid: Mod11.validate(idNo)
@@ -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,GAA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U,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","getMon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AM,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"}
package/lib/cn/Mod11.js CHANGED
@@ -28,7 +28,7 @@
28
28
  const { weights } = this;
29
29
  let sum = 0;
30
30
  for(let i = 0; i < s.length; i++){
31
- sum += parseInt(s[i]) * weights[i];
31
+ sum += parseInt(s[i], 10) * weights[i];
32
32
  }
33
33
  const num = (12 - sum % 11) % 11;
34
34
  if (num < 10) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cn/Mod11.ts"],"sourcesContent":["/**\n * ISO 7064:1983, MOD 11-2.\n */\nexport class Mod11Checksum {\n\tprotected weights = [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\nexport const Mod11 = new Mod11Checksum();\n"],"names":["Mod11Checksum","weights","validate","s","at","compute","slice","length","sum","i","parseInt","num","toString","Mod11"],"mappings":"AAAA;;CAEC,GACD,OAAO,MAAMA;IACFC,UAAU;QAAC;QAAG;QAAG;QAAI;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAI;QAAG;QAAG;QAAG;QAAG;KAAE,CAAC;IAE7EC,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;AAEA,OAAO,MAAMC,QAAQ,IAAIb,gBAAgB"}
1
+ {"version":3,"sources":["../../src/cn/Mod11.ts"],"sourcesContent":["/**\n * ISO 7064:1983, MOD 11-2.\n */\nexport class Mod11Checksum {\n\tprotected weights = [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], 10) * 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\nexport const Mod11 = new Mod11Checksum();\n"],"names":["Mod11Checksum","weights","validate","s","at","compute","slice","length","sum","i","parseInt","num","toString","Mod11"],"mappings":"AAAA;;CAEC,GACD,OAAO,MAAMA;IACFC,UAAU;QAAC;QAAG;QAAG;QAAI;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAG;QAAI;QAAG;QAAG;QAAG;QAAG;KAAE,CAAC;IAE7EC,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,EAAE,MAAMR,OAAO,CAACQ,EAAE;QACvC;QACA,MAAME,MAAM,AAAC,CAAA,KAAMH,MAAM,EAAE,IAAK;QAChC,IAAIG,MAAM,IAAI;YACb,OAAOA,IAAIC,QAAQ;QACpB,OAAO;YACN,OAAO;QACR;IACD;AACD;AAEA,OAAO,MAAMC,QAAQ,IAAIb,gBAAgB"}
@@ -74,7 +74,7 @@ export function formatLogObject(o, ctx) {
74
74
  line += characterFormat(additional.join('\n'));
75
75
  }
76
76
  if (type === 'trace') {
77
- const _err = new Error('Trace: ' + o.message);
77
+ const _err = new Error(`Trace: ${o.message}`);
78
78
  line += formatStack(_err.stack || '', _err.message);
79
79
  }
80
80
  }
@@ -104,7 +104,7 @@ function parseStack(stack, message) {
104
104
  }
105
105
  function formatStack(stack, message, opts) {
106
106
  const indent = ' '.repeat((opts?.errorLevel || 0) + 1);
107
- return `\n${indent}` + parseStack(stack, message).map((line)=>' ' + line.replace(/^at +/, (m)=>colors.gray(m)).replace(/\((.+)\)/, (_, m)=>`(${colors.cyan(m)})`)).join(`\n${indent}`);
107
+ return `\n${indent}` + parseStack(stack, message).map((line)=>` ${line.replace(/^at +/, (m)=>colors.gray(m)).replace(/\((.+)\)/, (_, m)=>`(${colors.cyan(m)})`)}`).join(`\n${indent}`);
108
108
  }
109
109
  function formatArgs(args, opts) {
110
110
  const _args = args.map((arg)=>{
@@ -148,11 +148,11 @@ function formatError(err, opts) {
148
148
  const stack = err.stack ? formatStack(err.stack, message, opts) : '';
149
149
  const level = opts?.errorLevel || 0;
150
150
  const causedPrefix = level > 0 ? `${' '.repeat(level)}[cause]: ` : '';
151
- const causedError = err.cause ? '\n\n' + formatError(err.cause, {
151
+ const causedError = err.cause ? `\n\n${formatError(err.cause, {
152
152
  ...opts,
153
153
  errorLevel: level + 1
154
- }) : '';
155
- return causedPrefix + message + '\n' + stack + causedError;
154
+ })}` : '';
155
+ return `${causedPrefix + message}\n${stack}${causedError}`;
156
156
  }
157
157
 
158
158
  //# sourceMappingURL=formatLogObject.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/consola/formatLogObject.ts"],"sourcesContent":["import colors, { Chalk, type ChalkInstance } from 'chalk';\nimport type { ConsolaOptions, FormatOptions, LogObject, LogType } from 'consola/core';\nimport dayjs from 'dayjs';\nimport { isDevelopment } from 'std-env';\n\nconst LevelColors: Record<LogType, (str: string) => string> = {\n\ttrace: colors.gray,\n\tdebug: colors.cyan,\n\tinfo: colors.blueBright,\n\twarn: colors.yellow,\n\terror: colors.red,\n\tfatal: colors.bgRed.white,\n\tsilent: colors.white,\n\tlog: colors.white,\n\tsuccess: colors.green,\n\tfail: colors.red,\n\tready: colors.green,\n\tstart: colors.cyan,\n\tbox: colors.white,\n\tverbose: colors.green,\n};\n\nconst levelShort: Record<LogType, string> = {\n\ttrace: 'TRAC',\n\tdebug: 'DEBG',\n\tinfo: 'INFO',\n\twarn: 'WARN',\n\terror: 'ERRO',\n\tfatal: 'FATL',\n\tsilent: 'SLNT',\n\tlog: 'LOG ', // Added space to make it 4 characters\n\tsuccess: 'SUCC',\n\tfail: 'FAIL',\n\tready: 'READ',\n\tstart: 'STRT',\n\tbox: 'BOX ', // Added space to make it 4 characters\n\tverbose: 'VERB',\n};\nconst start = Date.now();\n\nconst Colors: ChalkInstance = colors;\nconst NoColors = new Chalk({ level: 0 });\n\nexport function formatLogObject(\n\to: LogObject,\n\tctx: {\n\t\toptions: ConsolaOptions;\n\t},\n) {\n\tconst shouldColor = Boolean(ctx.options?.formatOptions?.colors);\n\n\tlet { date, type, tag } = o;\n\ttype = type === 'log' ? 'info' : type;\n\tconst colors = shouldColor ? Colors : NoColors;\n\tlet color = LevelColors[type] || colors.white;\n\tif (!shouldColor) {\n\t\tcolor = (v) => v;\n\t}\n\tconst levelText = levelShort[type] || type.toUpperCase().slice(0, 4); // Get first 4 chars, consistent uppercase\n\n\tlet line = '';\n\tlet out: string[] = [];\n\n\t// Timestamp\n\tif (isDevelopment) {\n\t\t// process.hrtime.bigint()\n\t\tlet diff = (date.getTime() - start) / 1000;\n\n\t\tout.push(colors.gray(diff.toFixed(3).padStart(7, ' ')));\n\t} else {\n\t\tout.push(colors.gray(dayjs(date).format('YYYY-MM-DD HH:mm:ss.SSS')));\n\t}\n\n\t// Log Level (colored)\n\t// Pad to 4 characters\n\tout.push(color(levelText.padEnd(4, ' ')));\n\n\tif (tag) {\n\t\tout.push(colors.yellow(`[${tag}]`)); // Added color for tag\n\t}\n\n\t{\n\t\tconst [message, ...additional] = formatArgs(o.args, { colors: shouldColor }).split('\\n');\n\n\t\tout.push(characterFormat(message));\n\n\t\tline = out.join(' ');\n\t\tif (additional.length > 0) {\n\t\t\tline += characterFormat(additional.join('\\n'));\n\t\t}\n\n\t\tif (type === 'trace') {\n\t\t\tconst _err = new Error('Trace: ' + o.message);\n\t\t\tline += formatStack(_err.stack || '', _err.message);\n\t\t}\n\t}\n\n\t// if (!message && typeof args[0] === 'string') {\n\t// message = args.shift();\n\t// }\n\t// if (message) {\n\t// out.push(message);\n\t// }\n\t// if (args.length) {\n\t// out.push(...args.map((a) => (typeof a === 'string' ? a : JSON.stringify(a)))); // Handle non-string args\n\t// }\n\n\t// todo format error\n\t// https://github.com/unjs/consola/blob/main/src/reporters/fancy.ts\n\n\t// return out.join(' '); // Increased spacing for better readability\n\treturn line;\n}\n\nfunction characterFormat(str: string) {\n\treturn (\n\t\tstr\n\t\t\t// highlight backticks\n\t\t\t.replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m))\n\t\t\t// underline underscores\n\t\t\t.replace(/\\s+_([^_]+)_\\s+/gm, (_, m) => ` ${colors.underline(m)} `)\n\t);\n}\n\nfunction parseStack(stack: string, message: string) {\n\t// const cwd = process.cwd() + sep;\n\n\tconst lines = stack\n\t\t.split('\\n')\n\t\t.splice(message.split('\\n').length)\n\t\t.map(\n\t\t\t(l) => l.trim().replace('file://', ''),\n\t\t\t// .replace(cwd, '')\n\t\t);\n\n\treturn lines;\n}\n\nfunction formatStack(stack: string, message: string, opts?: FormatOptions) {\n\tconst indent = ' '.repeat((opts?.errorLevel || 0) + 1);\n\treturn (\n\t\t`\\n${indent}`\n\t\t+ parseStack(stack, message)\n\t\t\t.map(\n\t\t\t\t(line) =>\n\t\t\t\t\t' ' + line.replace(/^at +/, (m) => colors.gray(m)).replace(/\\((.+)\\)/, (_, m) => `(${colors.cyan(m)})`),\n\t\t\t)\n\t\t\t.join(`\\n${indent}`)\n\t);\n}\n\nfunction formatArgs(args: any[], opts: FormatOptions) {\n\tconst _args = args.map((arg) => {\n\t\tif (arg && typeof arg.stack === 'string') {\n\t\t\treturn formatError(arg, opts);\n\t\t}\n\t\treturn arg;\n\t});\n\n\t// Only supported with Node >= 10\n\t// https://nodejs.org/api/util.html#util_util_inspect_object_options\n\treturn formatWithOptions(Boolean(opts.colors), ..._args);\n}\n\nfunction formatWithOptions(shouldColor: boolean, ...params: any[]) {\n\treturn params.map((value) => formatValue(value, shouldColor)).join(' ');\n}\n\nfunction formatValue(value: any, shouldColor: boolean = false): string {\n\tconst colors = shouldColor ? Colors : NoColors;\n\n\tif (value === null) return 'null';\n\tif (value === undefined) return 'undefined';\n\tif (typeof value === 'string') return value;\n\tif (typeof value === 'number' || typeof value === 'boolean') return String(value);\n\n\tif (typeof value === 'object' && value.constructor === Object) {\n\t\tconst entries = Object.entries(value);\n\t\tif (entries.length === 0) return '{}';\n\t\treturn entries\n\t\t\t.map(([key, val]) => {\n\t\t\t\tconst keyStr = shouldColor ? colors.blue(key) : key;\n\t\t\t\tconst valStr = shouldColor ? colors.green(JSON.stringify(val)) : JSON.stringify(val);\n\t\t\t\treturn `${keyStr}=${valStr}`;\n\t\t\t})\n\t\t\t.join(' ');\n\t}\n\n\t// For arrays and other objects, use JSON.stringify directly\n\ttry {\n\t\tconst result = JSON.stringify(value);\n\t\treturn shouldColor ? colors.green(result) : result;\n\t} catch {\n\t\treturn String(value);\n\t}\n}\n\nfunction formatError(err: any, opts: FormatOptions): string {\n\tconst message = err.message ?? formatWithOptions(Boolean(opts.colors), err);\n\tconst stack = err.stack ? formatStack(err.stack, message, opts) : '';\n\n\tconst level = opts?.errorLevel || 0;\n\tconst causedPrefix = level > 0 ? `${' '.repeat(level)}[cause]: ` : '';\n\tconst causedError = err.cause ? '\\n\\n' + formatError(err.cause, { ...opts, errorLevel: level + 1 }) : '';\n\n\treturn causedPrefix + message + '\\n' + stack + causedError;\n}\n"],"names":["colors","Chalk","dayjs","isDevelopment","LevelColors","trace","gray","debug","cyan","info","blueBright","warn","yellow","error","red","fatal","bgRed","white","silent","log","success","green","fail","ready","start","box","verbose","levelShort","Date","now","Colors","NoColors","level","formatLogObject","o","ctx","shouldColor","Boolean","options","formatOptions","date","type","tag","color","v","levelText","toUpperCase","slice","line","out","diff","getTime","push","toFixed","padStart","format","padEnd","message","additional","formatArgs","args","split","characterFormat","join","length","_err","Error","formatStack","stack","str","replace","_","m","underline","parseStack","lines","splice","map","l","trim","opts","indent","repeat","errorLevel","_args","arg","formatError","formatWithOptions","params","value","formatValue","undefined","String","Object","entries","key","val","keyStr","blue","valStr","JSON","stringify","result","err","causedPrefix","causedError","cause"],"mappings":"AAAA,OAAOA,UAAUC,KAAK,QAA4B,QAAQ;AAE1D,OAAOC,WAAW,QAAQ;AAC1B,SAASC,aAAa,QAAQ,UAAU;AAExC,MAAMC,cAAwD;IAC7DC,OAAOL,OAAOM,IAAI;IAClBC,OAAOP,OAAOQ,IAAI;IAClBC,MAAMT,OAAOU,UAAU;IACvBC,MAAMX,OAAOY,MAAM;IACnBC,OAAOb,OAAOc,GAAG;IACjBC,OAAOf,OAAOgB,KAAK,CAACC,KAAK;IACzBC,QAAQlB,OAAOiB,KAAK;IACpBE,KAAKnB,OAAOiB,KAAK;IACjBG,SAASpB,OAAOqB,KAAK;IACrBC,MAAMtB,OAAOc,GAAG;IAChBS,OAAOvB,OAAOqB,KAAK;IACnBG,OAAOxB,OAAOQ,IAAI;IAClBiB,KAAKzB,OAAOiB,KAAK;IACjBS,SAAS1B,OAAOqB,KAAK;AACtB;AAEA,MAAMM,aAAsC;IAC3CtB,OAAO;IACPE,OAAO;IACPE,MAAM;IACNE,MAAM;IACNE,OAAO;IACPE,OAAO;IACPG,QAAQ;IACRC,KAA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AAOkG,IAAI,CAACH,OAAOA;YAChD,MAAMI,SAAS/D,cAAcpC,OAAOqB,KAAK,CAAC+E,KAAKC,SAAS,CAACL,QAAQI,KAAKC,SAAS,CAACL;YAChF,OAAO,GAAGC,OAAO,CAAC,EAAEE,QAAQ;QAC7B,GACCpC,IAAI,CAAC;IACR;IAEA,4DAA4D;IAC5D,IAAI;QACH,MAAMuC,SAASF,KAAKC,SAAS,CAACZ;QAC9B,OAAOrD,cAAcpC,OAAOqB,KAAK,CAACiF,UAAUA;IAC7C,EAAE,OAAM;QACP,OAAOV,OAAOH;IACf;AACD;AAEA,SAASH,YAAYiB,GAAQ,EAAEvB,IAAmB;IACjD,MAAMvB,UAAU8C,IAAI9C,OAAO,IAAI8B,kBAAkBlD,QAAQ2C,KAAKhF,MAAM,GAAGuG;IACvE,MAAMnC,QAAQmC,IAAInC,KAAK,GAAGD,YAAYoC,IAAInC,KAAK,EAAEX,SAASuB,QAAQ;IAElE,MAAMhD,QAAQgD,MAAMG,cAAc;IAClC,MAAMqB,eAAexE,QAAQ,IAAI,GAAG,KAAKkD,MAAM,CAAClD,OAAO,SAAS,CAAC,GAAG;IACpE,MAAMyE,cAAcF,IAAIG,KAAK,GAAG,SAASpB,YAAYiB,IAAIG,KAAK,EAAE;QAAE,GAAG1B,IAAI;QAAEG,YAAYnD,QAAQ;IAAE,KAAK;IAEtG,OAAOwE,eAAe/C,UAAU,OAAOW,QAAQqC;AAChD"}
1
+ {"version":3,"sources":["../../src/consola/formatLogObject.ts"],"sourcesContent":["import colors, { Chalk, type ChalkInstance } from 'chalk';\nimport type { ConsolaOptions, FormatOptions, LogObject, LogType } from 'consola/core';\nimport dayjs from 'dayjs';\nimport { isDevelopment } from 'std-env';\n\nconst LevelColors: Record<LogType, (str: string) => string> = {\n\ttrace: colors.gray,\n\tdebug: colors.cyan,\n\tinfo: colors.blueBright,\n\twarn: colors.yellow,\n\terror: colors.red,\n\tfatal: colors.bgRed.white,\n\tsilent: colors.white,\n\tlog: colors.white,\n\tsuccess: colors.green,\n\tfail: colors.red,\n\tready: colors.green,\n\tstart: colors.cyan,\n\tbox: colors.white,\n\tverbose: colors.green,\n};\n\nconst levelShort: Record<LogType, string> = {\n\ttrace: 'TRAC',\n\tdebug: 'DEBG',\n\tinfo: 'INFO',\n\twarn: 'WARN',\n\terror: 'ERRO',\n\tfatal: 'FATL',\n\tsilent: 'SLNT',\n\tlog: 'LOG ', // Added space to make it 4 characters\n\tsuccess: 'SUCC',\n\tfail: 'FAIL',\n\tready: 'READ',\n\tstart: 'STRT',\n\tbox: 'BOX ', // Added space to make it 4 characters\n\tverbose: 'VERB',\n};\nconst start = Date.now();\n\nconst Colors: ChalkInstance = colors;\nconst NoColors = new Chalk({ level: 0 });\n\nexport function formatLogObject(\n\to: LogObject,\n\tctx: {\n\t\toptions: ConsolaOptions;\n\t},\n) {\n\tconst shouldColor = Boolean(ctx.options?.formatOptions?.colors);\n\n\tlet { date, type, tag } = o;\n\ttype = type === 'log' ? 'info' : type;\n\tconst colors = shouldColor ? Colors : NoColors;\n\tlet color = LevelColors[type] || colors.white;\n\tif (!shouldColor) {\n\t\tcolor = (v) => v;\n\t}\n\tconst levelText = levelShort[type] || type.toUpperCase().slice(0, 4); // Get first 4 chars, consistent uppercase\n\n\tlet line = '';\n\tlet out: string[] = [];\n\n\t// Timestamp\n\tif (isDevelopment) {\n\t\t// process.hrtime.bigint()\n\t\tlet diff = (date.getTime() - start) / 1000;\n\n\t\tout.push(colors.gray(diff.toFixed(3).padStart(7, ' ')));\n\t} else {\n\t\tout.push(colors.gray(dayjs(date).format('YYYY-MM-DD HH:mm:ss.SSS')));\n\t}\n\n\t// Log Level (colored)\n\t// Pad to 4 characters\n\tout.push(color(levelText.padEnd(4, ' ')));\n\n\tif (tag) {\n\t\tout.push(colors.yellow(`[${tag}]`)); // Added color for tag\n\t}\n\n\t{\n\t\tconst [message, ...additional] = formatArgs(o.args, { colors: shouldColor }).split('\\n');\n\n\t\tout.push(characterFormat(message));\n\n\t\tline = out.join(' ');\n\t\tif (additional.length > 0) {\n\t\t\tline += characterFormat(additional.join('\\n'));\n\t\t}\n\n\t\tif (type === 'trace') {\n\t\t\tconst _err = new Error(`Trace: ${o.message}`);\n\t\t\tline += formatStack(_err.stack || '', _err.message);\n\t\t}\n\t}\n\n\t// if (!message && typeof args[0] === 'string') {\n\t// message = args.shift();\n\t// }\n\t// if (message) {\n\t// out.push(message);\n\t// }\n\t// if (args.length) {\n\t// out.push(...args.map((a) => (typeof a === 'string' ? a : JSON.stringify(a)))); // Handle non-string args\n\t// }\n\n\t// todo format error\n\t// https://github.com/unjs/consola/blob/main/src/reporters/fancy.ts\n\n\t// return out.join(' '); // Increased spacing for better readability\n\treturn line;\n}\n\nfunction characterFormat(str: string) {\n\treturn (\n\t\tstr\n\t\t\t// highlight backticks\n\t\t\t.replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m))\n\t\t\t// underline underscores\n\t\t\t.replace(/\\s+_([^_]+)_\\s+/gm, (_, m) => ` ${colors.underline(m)} `)\n\t);\n}\n\nfunction parseStack(stack: string, message: string) {\n\t// const cwd = process.cwd() + sep;\n\n\tconst lines = stack\n\t\t.split('\\n')\n\t\t.splice(message.split('\\n').length)\n\t\t.map(\n\t\t\t(l) => l.trim().replace('file://', ''),\n\t\t\t// .replace(cwd, '')\n\t\t);\n\n\treturn lines;\n}\n\nfunction formatStack(stack: string, message: string, opts?: FormatOptions) {\n\tconst indent = ' '.repeat((opts?.errorLevel || 0) + 1);\n\treturn (\n\t\t`\\n${indent}` +\n\t\tparseStack(stack, message)\n\t\t\t.map(\n\t\t\t\t(line) =>\n\t\t\t\t\t` ${line.replace(/^at +/, (m) => colors.gray(m)).replace(/\\((.+)\\)/, (_, m) => `(${colors.cyan(m)})`)}`,\n\t\t\t)\n\t\t\t.join(`\\n${indent}`)\n\t);\n}\n\nfunction formatArgs(args: any[], opts: FormatOptions) {\n\tconst _args = args.map((arg) => {\n\t\tif (arg && typeof arg.stack === 'string') {\n\t\t\treturn formatError(arg, opts);\n\t\t}\n\t\treturn arg;\n\t});\n\n\t// Only supported with Node >= 10\n\t// https://nodejs.org/api/util.html#util_util_inspect_object_options\n\treturn formatWithOptions(Boolean(opts.colors), ..._args);\n}\n\nfunction formatWithOptions(shouldColor: boolean, ...params: any[]) {\n\treturn params.map((value) => formatValue(value, shouldColor)).join(' ');\n}\n\nfunction formatValue(value: any, shouldColor: boolean = false): string {\n\tconst colors = shouldColor ? Colors : NoColors;\n\n\tif (value === null) return 'null';\n\tif (value === undefined) return 'undefined';\n\tif (typeof value === 'string') return value;\n\tif (typeof value === 'number' || typeof value === 'boolean') return String(value);\n\n\tif (typeof value === 'object' && value.constructor === Object) {\n\t\tconst entries = Object.entries(value);\n\t\tif (entries.length === 0) return '{}';\n\t\treturn entries\n\t\t\t.map(([key, val]) => {\n\t\t\t\tconst keyStr = shouldColor ? colors.blue(key) : key;\n\t\t\t\tconst valStr = shouldColor ? colors.green(JSON.stringify(val)) : JSON.stringify(val);\n\t\t\t\treturn `${keyStr}=${valStr}`;\n\t\t\t})\n\t\t\t.join(' ');\n\t}\n\n\t// For arrays and other objects, use JSON.stringify directly\n\ttry {\n\t\tconst result = JSON.stringify(value);\n\t\treturn shouldColor ? colors.green(result) : result;\n\t} catch {\n\t\treturn String(value);\n\t}\n}\n\nfunction formatError(err: any, opts: FormatOptions): string {\n\tconst message = err.message ?? formatWithOptions(Boolean(opts.colors), err);\n\tconst stack = err.stack ? formatStack(err.stack, message, opts) : '';\n\n\tconst level = opts?.errorLevel || 0;\n\tconst causedPrefix = level > 0 ? `${' '.repeat(level)}[cause]: ` : '';\n\tconst causedError = err.cause ? `\\n\\n${formatError(err.cause, { ...opts, errorLevel: level + 1 })}` : '';\n\n\treturn `${causedPrefix + message}\\n${stack}${causedError}`;\n}\n"],"names":["colors","Chalk","dayjs","isDevelopment","LevelColors","trace","gray","debug","cyan","info","blueBright","warn","yellow","error","red","fatal","bgRed","white","silent","log","success","green","fail","ready","start","box","verbose","levelShort","Date","now","Colors","NoColors","level","formatLogObject","o","ctx","shouldColor","Boolean","options","formatOptions","date","type","tag","color","v","levelText","toUpperCase","slice","line","out","diff","getTime","push","toFixed","padStart","format","padEnd","message","additional","formatArgs","args","split","characterFormat","join","length","_err","Error","formatStack","stack","str","replace","_","m","underline","parseStack","lines","splice","map","l","trim","opts","indent","repeat","errorLevel","_args","arg","formatError","formatWithOptions","params","value","formatValue","undefined","String","Object","entries","key","val","keyStr","blue","valStr","JSON","stringify","result","err","causedPrefix","causedError","cause"],"mappings":"AAAA,OAAOA,UAAUC,KAAK,QAA4B,QAAQ;AAE1D,OAAOC,WAAW,QAAQ;AAC1B,SAASC,aAAa,QAAQ,UAAU;AAExC,MAAMC,cAAwD;IAC7DC,OAAOL,OAAOM,IAAI;IAClBC,OAAOP,OAAOQ,IAAI;IAClBC,MAAMT,OAAOU,UAAU;IACvBC,MAAMX,OAAOY,MAAM;IACnBC,OAAOb,OAAOc,GAAG;IACjBC,OAAOf,OAAOgB,KAAK,CAACC,KAAK;IACzBC,QAAQlB,OAAOiB,KAAK;IACpBE,KAAKnB,OAAOiB,KAAK;IACjBG,SAASpB,OAAOqB,KAAK;IACrBC,MAAMtB,OAAOc,GAAG;IAChBS,OAAOvB,OAAOqB,KAAK;IACnBG,OAAOxB,OAAOQ,IAAI;IAClBiB,KAAKzB,OAAOiB,KAAK;IACjBS,SAAS1B,OAAOqB,KAAK;AACtB;AAEA,MAAMM,aAAsC;IAC3CtB,OAAO;IACPE,OAAO;IACPE,MAAM;IACNE,MAAM;IACNE,OAAO;IACPE,OAAO;IACPG,QAAQ;IACRC,KAAK;IACLC,SAAS;IACTE,MAAM;IACNC,OAAO;IACPC,OAAO;IACPC,KAAK;IACLC,SAAS;AACV;AACA,MAAMF,QAAQI,KAAKC,GAAG;AAEtB,MAAMC,SAAwB9B;AAC9B,MAAM+B,WAAW,IAAI9B,MAAM;IAAE+B,OAAO;AAAE;AAEtC,OAAO,SAASC,gBACfC,CA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,IAAI,CAAC;IACR;IAEA,4DAA4D;IAC5D,IAAI;QACH,MAAMuC,SAASF,KAAKC,SAAS,CAACZ;QAC9B,OAAOrD,cAAcpC,OAAOqB,KAAK,CAACiF,UAAUA;IAC7C,EAAE,OAAM;QACP,OAAOV,OAAOH;IACf;AACD;AAEA,SAASH,YAAYiB,GAAQ,EAAEvB,IAAmB;IACjD,MAAMvB,UAAU8C,IAAI9C,OAAO,IAAI8B,kBAAkBlD,QAAQ2C,KAAKhF,MAAM,GAAGuG;IACvE,MAAMnC,QAAQmC,IAAInC,KAAK,GAAGD,YAAYoC,IAAInC,KAAK,EAAEX,SAASuB,QAAQ;IAElE,MAAMhD,QAAQgD,MAAMG,cAAc;IAClC,MAAMqB,eAAexE,QAAQ,IAAI,GAAG,KAAKkD,MAAM,CAAClD,OAAO,SAAS,CAAC,GAAG;IACpE,MAAMyE,cAAcF,IAAIG,KAAK,GAAG,CAAC,IAAI,EAAEpB,YAAYiB,IAAIG,KAAK,EAAE;QAAE,GAAG1B,IAAI;QAAEG,YAAYnD,QAAQ;IAAE,IAAI,GAAG;IAEtG,OAAO,GAAGwE,eAAe/C,QAAQ,EAAE,EAAEW,QAAQqC,aAAa;AAC3D"}
@@ -17,7 +17,7 @@ export function maybeNumber(v) {
17
17
  }
18
18
  }
19
19
  const n = Number(v);
20
- if (isNaN(n)) {
20
+ if (Number.isNaN(n)) {
21
21
  return undefined;
22
22
  }
23
23
  return n;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/data/maybeNumber.ts"],"sourcesContent":["export type MaybeNumber = number | null | string | undefined | bigint;\n\nexport function maybeNumber(v: MaybeNumber) {\n\tif (v === null || v === undefined) {\n\t\treturn undefined;\n\t}\n\n\tswitch (typeof v) {\n\t\tcase 'number':\n\t\t\treturn v;\n\t\tcase 'bigint':\n\t\t\tif (v > BigInt(Number.MAX_SAFE_INTEGER) || v < BigInt(Number.MIN_SAFE_INTEGER)) {\n\t\t\t\tthrow new Error(`bigint out of range`);\n\t\t\t}\n\t\t\treturn Number(v);\n\t\tcase 'string':\n\t\t\tv = v.trim();\n\t\t\tif (!v) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t}\n\tconst n = Number(v);\n\tif (isNaN(n)) {\n\t\treturn undefined;\n\t}\n\treturn n;\n}\n"],"names":["maybeNumber","v","undefined","BigInt","Number","MAX_SAFE_INTEGER","MIN_SAFE_INTEGER","Error","trim","n","isNaN"],"mappings":"AAEA,OAAO,SAASA,YAAYC,CAAc;IACzC,IAAIA,MAAM,QAAQA,MAAMC,WAAW;QAClC,OAAOA;IACR;IAEA,OAAQ,OAAOD;QACd,KAAK;YACJ,OAAOA;QACR,KAAK;YACJ,IAAIA,IAAIE,OAAOC,OAAOC,gBAAgB,KAAKJ,IAAIE,OAAOC,OAAOE,gBAAgB,GAAG;gBAC/E,MAAM,IAAIC,MAAM,CAAC,mBAAmB,CAAC;YACtC;YACA,OAAOH,OAAOH;QACf,KAAK;YACJA,IAAIA,EAAEO,IAAI;YACV,IAAI,CAACP,GAAG;gBACP,OAAOC;YACR;IACF;IACA,MAAMO,IAAIL,OAAOH;IACjB,IAAIS,MAAMD,IAAI;QACb,OAAOP;IACR;IACA,OAAOO;AACR"}
1
+ {"version":3,"sources":["../../src/data/maybeNumber.ts"],"sourcesContent":["export type MaybeNumber = number | null | string | undefined | bigint;\n\nexport function maybeNumber(v: MaybeNumber) {\n\tif (v === null || v === undefined) {\n\t\treturn undefined;\n\t}\n\n\tswitch (typeof v) {\n\t\tcase 'number':\n\t\t\treturn v;\n\t\tcase 'bigint':\n\t\t\tif (v > BigInt(Number.MAX_SAFE_INTEGER) || v < BigInt(Number.MIN_SAFE_INTEGER)) {\n\t\t\t\tthrow new Error(`bigint out of range`);\n\t\t\t}\n\t\t\treturn Number(v);\n\t\tcase 'string':\n\t\t\tv = v.trim();\n\t\t\tif (!v) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t}\n\tconst n = Number(v);\n\tif (Number.isNaN(n)) {\n\t\treturn undefined;\n\t}\n\treturn n;\n}\n"],"names":["maybeNumber","v","undefined","BigInt","Number","MAX_SAFE_INTEGER","MIN_SAFE_INTEGER","Error","trim","n","isNaN"],"mappings":"AAEA,OAAO,SAASA,YAAYC,CAAc;IACzC,IAAIA,MAAM,QAAQA,MAAMC,WAAW;QAClC,OAAOA;IACR;IAEA,OAAQ,OAAOD;QACd,KAAK;YACJ,OAAOA;QACR,KAAK;YACJ,IAAIA,IAAIE,OAAOC,OAAOC,gBAAgB,KAAKJ,IAAIE,OAAOC,OAAOE,gBAAgB,GAAG;gBAC/E,MAAM,IAAIC,MAAM,CAAC,mBAAmB,CAAC;YACtC;YACA,OAAOH,OAAOH;QACf,KAAK;YACJA,IAAIA,EAAEO,IAAI;YACV,IAAI,CAACP,GAAG;gBACP,OAAOC;YACR;IACF;IACA,MAAMO,IAAIL,OAAOH;IACjB,IAAIG,OAAOM,KAAK,CAACD,IAAI;QACpB,OAAOP;IACR;IACA,OAAOO;AACR"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/data/types.d.ts"],"sourcesContent":["export type ListQueryInput = {\n\t/** Filter string */\n\tfilter?: string;\n\t/** Filter array */\n\tfilters?: string[];\n\t/** Filter by IDs */\n\tids?: string[];\n\t/** Search query */\n\tsearch?: string;\n\t/** Items per page */\n\tlimit?: number;\n\t/** Offset for pagination */\n\toffset?: number;\n\t/** Ordering criteria */\n\torder?: string[];\n\t/** Page index (0-based) */\n\tpageIndex?: number;\n\t/** Page number (1-based) */\n\tpageNumber?: number;\n\t/** Items per page */\n\tpageSize?: number;\n\t/** Cursor for pagination */\n\tcursor?: string;\n\t/** Whether to include deleted items */\n\tdeleted?: boolean;\n};\n\ntype ListResult<T = any> = {\n\t/** List of items */\n\tdata: T[];\n\t/** Total number of items */\n\ttotal: number;\n};\n\ntype PageInfo = {\n\t/** Whether there are more items */\n\thasNextPage: boolean;\n\t/** Whether there are previous items */\n\thasPreviousPage: boolean;\n\n\t// /** Start cursor */\n\t// startCursor?: string;\n\t// /** End cursor */\n\t// endCursor?: string;\n};\n"],"names":[],"mappings":"AAAA,WAyBE"}
1
+ {"version":3,"sources":["../../src/data/types.d.ts"],"sourcesContent":["export type ListQueryInput = {\n\t/** Filter string */\n\tfilter?: string;\n\t/** Filter array */\n\tfilters?: string[];\n\t/** Filter by IDs */\n\tids?: string[];\n\t/** Search query */\n\tsearch?: string;\n\t/** Items per page */\n\tlimit?: number;\n\t/** Offset for pagination */\n\toffset?: number;\n\t/** Ordering criteria */\n\torder?: string[];\n\t/** Page index (0-based) */\n\tpageIndex?: number;\n\t/** Page number (1-based) */\n\tpageNumber?: number;\n\t/** Items per page */\n\tpageSize?: number;\n\t/** Cursor for pagination */\n\tcursor?: string;\n\t/** Whether to include deleted items */\n\tdeleted?: boolean;\n};\n\ntype _ListResult<T = any> = {\n\t/** List of items */\n\tdata: T[];\n\t/** Total number of items */\n\ttotal: number;\n};\n\ntype _PageInfo = {\n\t/** Whether there are more items */\n\thasNextPage: boolean;\n\t/** Whether there are previous items */\n\thasPreviousPage: boolean;\n\n\t// /** Start cursor */\n\t// startCursor?: string;\n\t// /** End cursor */\n\t// endCursor?: string;\n};\n"],"names":[],"mappings":"AAAA,WAyBE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/dayjs/formatDuration.ts"],"sourcesContent":["import { type OpUnitType, type UnitTypeLongPlural } from 'dayjs';\nimport { type Duration } from 'dayjs/plugin/duration';\nimport { parseDuration } from './parseDuration';\n\ntype FormatDurationOptions = {\n\thumanize?: boolean;\n\tformat?: string | 'human' | 'humanize' | 'iso' | 'auto';\n\tiso?: boolean;\n};\n\nexport type MaybeDuration =\n\t| number\n\t| string\n\t| Duration\n\t| Partial<{\n\t\t\t[unit in Exclude<UnitTypeLongPlural, 'dates'> | 'weeks']: number;\n\t }>\n\t| {\n\t\t\tvalue: number;\n\t\t\tunit?: Exclude<OpUnitType, 'date' | 'dates'>;\n\t }\n\t| undefined\n\t| null;\n\nexport function formatDuration(value: MaybeDuration, o?: FormatDurationOptions): string | undefined {\n\tconst v = parseDuration(value);\n\tif (v === undefined || v === null) {\n\t\treturn;\n\t}\n\n\tlet { format, humanize, iso } = o || {};\n\t// Use local variables instead of modifying o directly\n\tswitch (format) {\n\t\tcase 'human':\n\t\tcase 'humanize':\n\t\t\thumanize = true;\n\t\t\tformat = undefined;\n\t\t\tbreak;\n\t\tcase 'iso':\n\t\t\tiso = true;\n\t\t\tformat = undefined;\n\t\t\tbreak;\n\t\tcase 'auto':\n\t\t\tformat = undefined;\n\t\t\tbreak;\n\t}\n\n\tif (humanize) {\n\t\treturn v.humanize();\n\t}\n\tif (iso) {\n\t\treturn v.toISOString();\n\t}\n\tif (format) {\n\t\treturn v.format(format);\n\t}\n\n\t// auto format\n\t// 1h2m3s\n\tif (v.asDays() > 1) {\n\t\tlet s = v.toISOString();\n\t\treturn s.replace('P', '').replace('T', '').toLowerCase();\n\t}\n\n\t{\n\t\tlet parts: string[] = [];\n\t\tlet h = v.hours();\n\t\tlet m = v.minutes();\n\t\tlet s = v.seconds();\n\t\tlet ms = v.milliseconds();\n\n\t\tif (h > 0) {\n\t\t\tparts.push(`${h}h`);\n\t\t}\n\t\tif (m > 0) {\n\t\t\tparts.push(`${m}m`);\n\t\t}\n\t\tif (s > 0) {\n\t\t\tparts.push(`${s}s`);\n\t\t}\n\t\tif (ms > 0 || (h === 0 && m === 0 && s === 0)) {\n\t\t\tparts.push(`${ms}ms`);\n\t\t}\n\t\treturn parts.join('');\n\t}\n}\n"],"names":["parseDuration","formatDuration","value","o","v","undefined","format","humanize","iso","toISOString","asDays","s","replace","toLowerCase","parts","h","hours","m","minutes","seconds","ms","milliseconds","push","join"],"mappings":"AAEA,SAASA,aAAa,QAAQ,kBAAkB;AAsBhD,OAAO,SAASC,eAAeC,KAAoB,EAAEC,CAAyB;IAC7E,MAAMC,IAAIJ,cAAcE;IACxB,IAAIE,MAAMC,aAAaD,MAAM,MAAM;QAClC;IACD;IAEA,IAAI,EAAEE,MAAM,EAAEC,QAAQ,EAAEC,GAAG,EAAE,GAAGL,KAAK,CAAC;IACtC,sDAAsD;IACtD,OAAQG;QACP,KAAK;QACL,KAAK;YACJC,WAAW;YACXD,SAASD;YACT;QACD,KAAK;YACJG,MAAM;YACNF,SAASD;YACT;QACD,KAAK;YACJC,SAASD;YACT;IACF;IAEA,IAAIE,UAAU;QACb,OAAOH,EAAEG,QAAQ;IAClB;IACA,IAAIC,KAAK;QACR,OAAOJ,EAAEK,WAAW;IACrB;IACA,IAAIH,QAAQ;QACX,OAAOF,EAAEE,MAAM,CAACA;IACjB;IAEA,cAAc;IACd,SAAS;IACT,IAAIF,EAAEM,MAAM,KAAK,GAAG;QACnB,IAAIC,IAAIP,EAAEK,WAAW;QACrB,OAAOE,EAAEC,OAAO,CAAC,KAAK,IAAIA,OAAO,CAAC,KAAK,IAAIC,WAAW;IACvD;IAEA;QACC,IAAIC,QAAkB,EAAE;QACxB,IAAIC,IAAIX,EAAEY,KAAK;QACf,IAAIC,IAAIb,EAAEc,OAAO;QACjB,IAAIP,IAAIP,EAAEe,OAAO;QACjB,IAAIC,KAAKhB,EAAEiB,YAAY;QAEvB,IAAIN,IAAI,GAAG;YACVD,MAAMQ,IAAI,CAAC,GAAGP,EAAE,CAAC,CAAC;QACnB;QACA,IAAIE,IAAI,GAAG;YACVH,MAAMQ,IAAI,CAAC,GAAGL,EAAE,CAAC,CAAC;QACnB;QACA,IAAIN,IAAI,GAAG;YACVG,MAAMQ,IAAI,CAAC,GAAGX,EAAE,CAAC,CAAC;QACnB;QACA,IAAIS,KAAK,KAAML,MAAM,KAAKE,MAAM,KAAKN,MAAM,GAAI;YAC9CG,MAAMQ,IAAI,CAAC,GAAGF,GAAG,EAAE,CAAC;QACrB;QACA,OAAON,MAAMS,IAAI,CAAC;IACnB;AACD"}
1
+ {"version":3,"sources":["../../src/dayjs/formatDuration.ts"],"sourcesContent":["import type { OpUnitType, UnitTypeLongPlural } from 'dayjs';\nimport type { Duration } from 'dayjs/plugin/duration';\nimport { parseDuration } from './parseDuration';\n\ntype FormatDurationOptions = {\n\thumanize?: boolean;\n\tformat?: string | 'human' | 'humanize' | 'iso' | 'auto';\n\tiso?: boolean;\n};\n\nexport type MaybeDuration =\n\t| number\n\t| string\n\t| Duration\n\t| Partial<{\n\t\t\t[unit in Exclude<UnitTypeLongPlural, 'dates'> | 'weeks']: number;\n\t }>\n\t| {\n\t\t\tvalue: number;\n\t\t\tunit?: Exclude<OpUnitType, 'date' | 'dates'>;\n\t }\n\t| undefined\n\t| null;\n\nexport function formatDuration(value: MaybeDuration, o?: FormatDurationOptions): string | undefined {\n\tconst v = parseDuration(value);\n\tif (v === undefined || v === null) {\n\t\treturn;\n\t}\n\n\tlet { format, humanize, iso } = o || {};\n\t// Use local variables instead of modifying o directly\n\tswitch (format) {\n\t\tcase 'human':\n\t\tcase 'humanize':\n\t\t\thumanize = true;\n\t\t\tformat = undefined;\n\t\t\tbreak;\n\t\tcase 'iso':\n\t\t\tiso = true;\n\t\t\tformat = undefined;\n\t\t\tbreak;\n\t\tcase 'auto':\n\t\t\tformat = undefined;\n\t\t\tbreak;\n\t}\n\n\tif (humanize) {\n\t\treturn v.humanize();\n\t}\n\tif (iso) {\n\t\treturn v.toISOString();\n\t}\n\tif (format) {\n\t\treturn v.format(format);\n\t}\n\n\t// auto format\n\t// 1h2m3s\n\tif (v.asDays() > 1) {\n\t\tlet s = v.toISOString();\n\t\treturn s.replace('P', '').replace('T', '').toLowerCase();\n\t}\n\n\t{\n\t\tlet parts: string[] = [];\n\t\tlet h = v.hours();\n\t\tlet m = v.minutes();\n\t\tlet s = v.seconds();\n\t\tlet ms = v.milliseconds();\n\n\t\tif (h > 0) {\n\t\t\tparts.push(`${h}h`);\n\t\t}\n\t\tif (m > 0) {\n\t\t\tparts.push(`${m}m`);\n\t\t}\n\t\tif (s > 0) {\n\t\t\tparts.push(`${s}s`);\n\t\t}\n\t\tif (ms > 0 || (h === 0 && m === 0 && s === 0)) {\n\t\t\tparts.push(`${ms}ms`);\n\t\t}\n\t\treturn parts.join('');\n\t}\n}\n"],"names":["parseDuration","formatDuration","value","o","v","undefined","format","humanize","iso","toISOString","asDays","s","replace","toLowerCase","parts","h","hours","m","minutes","seconds","ms","milliseconds","push","join"],"mappings":"AAEA,SAASA,aAAa,QAAQ,kBAAkB;AAsBhD,OAAO,SAASC,eAAeC,KAAoB,EAAEC,CAAyB;IAC7E,MAAMC,IAAIJ,cAAcE;IACxB,IAAIE,MAAMC,aAAaD,MAAM,MAAM;QAClC;IACD;IAEA,IAAI,EAAEE,MAAM,EAAEC,QAAQ,EAAEC,GAAG,EAAE,GAAGL,KAAK,CAAC;IACtC,sDAAsD;IACtD,OAAQG;QACP,KAAK;QACL,KAAK;YACJC,WAAW;YACXD,SAASD;YACT;QACD,KAAK;YACJG,MAAM;YACNF,SAASD;YACT;QACD,KAAK;YACJC,SAASD;YACT;IACF;IAEA,IAAIE,UAAU;QACb,OAAOH,EAAEG,QAAQ;IAClB;IACA,IAAIC,KAAK;QACR,OAAOJ,EAAEK,WAAW;IACrB;IACA,IAAIH,QAAQ;QACX,OAAOF,EAAEE,MAAM,CAACA;IACjB;IAEA,cAAc;IACd,SAAS;IACT,IAAIF,EAAEM,MAAM,KAAK,GAAG;QACnB,IAAIC,IAAIP,EAAEK,WAAW;QACrB,OAAOE,EAAEC,OAAO,CAAC,KAAK,IAAIA,OAAO,CAAC,KAAK,IAAIC,WAAW;IACvD;IAEA;QACC,IAAIC,QAAkB,EAAE;QACxB,IAAIC,IAAIX,EAAEY,KAAK;QACf,IAAIC,IAAIb,EAAEc,OAAO;QACjB,IAAIP,IAAIP,EAAEe,OAAO;QACjB,IAAIC,KAAKhB,EAAEiB,YAAY;QAEvB,IAAIN,IAAI,GAAG;YACVD,MAAMQ,IAAI,CAAC,GAAGP,EAAE,CAAC,CAAC;QACnB;QACA,IAAIE,IAAI,GAAG;YACVH,MAAMQ,IAAI,CAAC,GAAGL,EAAE,CAAC,CAAC;QACnB;QACA,IAAIN,IAAI,GAAG;YACVG,MAAMQ,IAAI,CAAC,GAAGX,EAAE,CAAC,CAAC;QACnB;QACA,IAAIS,KAAK,KAAML,MAAM,KAAKE,MAAM,KAAKN,MAAM,GAAI;YAC9CG,MAAMQ,IAAI,CAAC,GAAGF,GAAG,EAAE,CAAC;QACrB;QACA,OAAON,MAAMS,IAAI,CAAC;IACnB;AACD"}
@@ -1,3 +1,4 @@
1
+ import { parseDate } from "@wener/utils";
1
2
  import dayjs from "dayjs";
2
3
  import duration from "dayjs/plugin/duration";
3
4
  import quarterOfYear from "dayjs/plugin/quarterOfYear";
@@ -5,91 +6,19 @@ import weekOfYear from "dayjs/plugin/weekOfYear";
5
6
  dayjs.extend(duration);
6
7
  dayjs.extend(quarterOfYear);
7
8
  dayjs.extend(weekOfYear);
8
- /**
9
- * Resolves a Grafana-style relative time string and returns the corresponding Date.
10
- *
11
- * @param s - The relative time string to parse (must start with "now")
12
- * @param now - Optional reference date. If undefined, uses current time
13
- * @returns The calculated Date based on the relative time expression
14
- *
15
- * @throws {Error} When the format is invalid or contains unsupported operators/units
16
- *
17
- * ## Syntax
18
- *
19
- * All expressions must start with `now` followed by optional operations:
20
- *
21
- * ### Operators
22
- * - `-` - Subtraction (e.g., `now-1h` for one hour ago)
23
- * - `+` - Addition (e.g., `now+1d` for one day from now)
24
- * - `/` - Truncation to beginning of time unit (e.g., `now/d` for start of current day)
25
- * - `\` - Truncation to end of time unit (e.g., `now\d` for end of current day)
26
- *
27
- * ### Time Units
28
- * - `s` - seconds
29
- * - `m` - minutes
30
- * - `h` - hours
31
- * - `d` - days
32
- * - `w` - weeks
33
- * - `M` - months
34
- * - `Q` - quarters
35
- * - `y` - years
36
- *
37
- * ### Operations
38
- * Operations are processed sequentially from left to right:
39
- * - **Addition/Subtraction**: `now±{count}{unit}` (e.g., `now-24h`, `now+1d`)
40
- * - **Truncation to start**: `now/{unit}` (e.g., `now/d`, `now/M`)
41
- * - **Truncation to end**: `now\{unit}` (e.g., `now\d`, `now\M`)
42
- * - **Complex**: Multiple operations can be chained (e.g., `now-1M/M`, `now\d`, `now-1y\y`)
43
- *
44
- * @example
45
- * ```typescript
46
- * // Basic usage
47
- * resolveRelativeTime('now') // Current time
48
- * resolveRelativeTime('now-1h') // One hour ago
49
- * resolveRelativeTime('now+1d') // One day from now
50
- * resolveRelativeTime('now/d') // Start of current day
51
- * resolveRelativeTime('now\\d') // End of current day
52
- *
53
- * // Common patterns
54
- * resolveRelativeTime('now-24h') // Last 24 hours
55
- * resolveRelativeTime('now-7d') // Last 7 days
56
- * resolveRelativeTime('now/M') // Start of current month
57
- * resolveRelativeTime('now\\M') // End of current month
58
- * resolveRelativeTime('now-1M/M') // Start of previous month
59
- * resolveRelativeTime('now-1M\\M') // End of previous month
60
- * resolveRelativeTime('now/w') // Start of current week
61
- * resolveRelativeTime('now\\w') // End of current week
62
- * resolveRelativeTime('now/y') // Start of current year
63
- * resolveRelativeTime('now\\y') // End of current year
64
- *
65
- * // Complex expressions
66
- * resolveRelativeTime('now/d+1d-1s') // End of current day (alternative method)
67
- * resolveRelativeTime('now\\d') // End of current day (direct method)
68
- * resolveRelativeTime('now-1w+2d-3h') // 1 week ago, plus 2 days, minus 3 hours
69
- *
70
- * // With reference date
71
- * const refDate = new Date('2024-03-15T14:30:45.123Z');
72
- * resolveRelativeTime('now-1h', refDate); // One hour before reference date
73
- * resolveRelativeTime('now\\d', refDate); // End of reference day
74
- * ```
75
- */ export function resolveRelativeTime(s, now) {
9
+ export function resolveRelativeTime(s, now) {
76
10
  {
77
- let out;
78
- if (!s) {} else if (s instanceof Date) {
79
- out = s;
80
- } else if (typeof s === 'number') {
81
- out = new Date(s);
82
- } else if (!s.startsWith('now')) {
83
- out = new Date(s);
84
- }
11
+ let out = parseDate(s);
85
12
  if (out) {
86
- if (isNaN(out.getTime())) {
87
- throw new Error(`Invalid date: ${s}`);
88
- }
89
13
  return out;
90
14
  }
15
+ if (s == null) {
16
+ return;
17
+ }
91
18
  }
92
- if (typeof s !== 'string' || !s.startsWith('now')) {
19
+ if (typeof s === 'string' && s.startsWith('now')) {
20
+ // valid
21
+ } else {
93
22
  throw new Error(`Invalid relative time format: ${s}`);
94
23
  }
95
24
  let current = dayjs(now);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/dayjs/resolveRelativeTime.ts"],"sourcesContent":["import dayjs from 'dayjs';\nimport duration from 'dayjs/plugin/duration';\nimport quarterOfYear from 'dayjs/plugin/quarterOfYear';\nimport weekOfYear from 'dayjs/plugin/weekOfYear';\n\ndayjs.extend(duration);\ndayjs.extend(quarterOfYear);\ndayjs.extend(weekOfYear);\n\n/**\n * Resolves a Grafana-style relative time string and returns the corresponding Date.\n *\n * @param s - The relative time string to parse (must start with \"now\")\n * @param now - Optional reference date. If undefined, uses current time\n * @returns The calculated Date based on the relative time expression\n *\n * @throws {Error} When the format is invalid or contains unsupported operators/units\n *\n * ## Syntax\n *\n * All expressions must start with `now` followed by optional operations:\n *\n * ### Operators\n * - `-` - Subtraction (e.g., `now-1h` for one hour ago)\n * - `+` - Addition (e.g., `now+1d` for one day from now)\n * - `/` - Truncation to beginning of time unit (e.g., `now/d` for start of current day)\n * - `\\` - Truncation to end of time unit (e.g., `now\\d` for end of current day)\n *\n * ### Time Units\n * - `s` - seconds\n * - `m` - minutes\n * - `h` - hours\n * - `d` - days\n * - `w` - weeks\n * - `M` - months\n * - `Q` - quarters\n * - `y` - years\n *\n * ### Operations\n * Operations are processed sequentially from left to right:\n * - **Addition/Subtraction**: `now±{count}{unit}` (e.g., `now-24h`, `now+1d`)\n * - **Truncation to start**: `now/{unit}` (e.g., `now/d`, `now/M`)\n * - **Truncation to end**: `now\\{unit}` (e.g., `now\\d`, `now\\M`)\n * - **Complex**: Multiple operations can be chained (e.g., `now-1M/M`, `now\\d`, `now-1y\\y`)\n *\n * @example\n * ```typescript\n * // Basic usage\n * resolveRelativeTime('now') // Current time\n * resolveRelativeTime('now-1h') // One hour ago\n * resolveRelativeTime('now+1d') // One day from now\n * resolveRelativeTime('now/d') // Start of current day\n * resolveRelativeTime('now\\\\d') // End of current day\n *\n * // Common patterns\n * resolveRelativeTime('now-24h') // Last 24 hours\n * resolveRelativeTime('now-7d') // Last 7 days\n * resolveRelativeTime('now/M') // Start of current month\n * resolveRelativeTime('now\\\\M') // End of current month\n * resolveRelativeTime('now-1M/M') // Start of previous month\n * resolveRelativeTime('now-1M\\\\M') // End of previous month\n * resolveRelativeTime('now/w') // Start of current week\n * resolveRelativeTime('now\\\\w') // End of current week\n * resolveRelativeTime('now/y') // Start of current year\n * resolveRelativeTime('now\\\\y') // End of current year\n *\n * // Complex expressions\n * resolveRelativeTime('now/d+1d-1s') // End of current day (alternative method)\n * resolveRelativeTime('now\\\\d') // End of current day (direct method)\n * resolveRelativeTime('now-1w+2d-3h') // 1 week ago, plus 2 days, minus 3 hours\n *\n * // With reference date\n * const refDate = new Date('2024-03-15T14:30:45.123Z');\n * resolveRelativeTime('now-1h', refDate); // One hour before reference date\n * resolveRelativeTime('now\\\\d', refDate); // End of reference day\n * ```\n */\nexport function resolveRelativeTime(s: string | Date | number, now?: Date | undefined): Date {\n\t{\n\t\tlet out: Date | undefined;\n\t\tif (!s) {\n\t\t} else if (s instanceof Date) {\n\t\t\tout = s;\n\t\t} else if (typeof s === 'number') {\n\t\t\tout = new Date(s);\n\t\t} else if (!s.startsWith('now')) {\n\t\t\tout = new Date(s);\n\t\t}\n\t\tif (out) {\n\t\t\tif (isNaN(out.getTime())) {\n\t\t\t\tthrow new Error(`Invalid date: ${s}`);\n\t\t\t}\n\t\t\treturn out;\n\t\t}\n\t}\n\n\tif (typeof s !== 'string' || !s.startsWith('now')) {\n\t\tthrow new Error(`Invalid relative time format: ${s}`);\n\t}\n\n\tlet current = dayjs(now);\n\tconst remaining = s.slice(3); // Remove 'now'\n\n\tif (!remaining) {\n\t\treturn current.toDate();\n\t}\n\n\t// Split by operators while keeping them in the result\n\tconst parts = remaining.split(/([+\\-/\\\\])/).filter((part) => part !== '');\n\n\tfor (let i = 0; i < parts.length; i += 2) {\n\t\tconst operator = parts[i];\n\t\tconst operand = parts[i + 1];\n\n\t\tif (!operator || !operand) {\n\t\t\tthrow new Error(`Invalid relative time format: ${s}`);\n\t\t}\n\n\t\tif (operator === '/') {\n\t\t\t// Truncation to start operation\n\t\t\tcheckDurationUnit(operand);\n\t\t\tcurrent = current.startOf(operand);\n\t\t} else if (operator === '\\\\') {\n\t\t\t// Truncation to end operation\n\t\t\tcheckDurationUnit(operand);\n\t\t\tcurrent = current.endOf(operand);\n\t\t} else {\n\t\t\t// Addition or subtraction operation\n\t\t\tconst match = operand.match(/^(\\d+)([smhdwMQy])$/);\n\t\t\tif (!match) {\n\t\t\t\tthrow new Error(`Invalid time operand: ${operand}`);\n\t\t\t}\n\n\t\t\tconst [, amountStr, unit] = match;\n\t\t\tcheckDurationUnit(unit);\n\t\t\tconst amount = parseInt(amountStr, 10);\n\n\t\t\tif (operator === '+') {\n\t\t\t\tcurrent = current.add(amount, unit as 'w');\n\t\t\t} else if (operator === '-') {\n\t\t\t\tcurrent = current.subtract(amount, unit as 'Q');\n\t\t\t} else {\n\t\t\t\tthrow new Error(`Invalid operator: ${operator}`);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn current.toDate();\n}\n\n/** Array of all valid time units */\nexport const RelativeDurationUnits = ['ms', 's', 'm', 'h', 'd', 'w', 'M', 'Q', 'y'] as const;\n\n/** Valid time units for relative time expressions */\nexport type RelativeDurationUnit = (typeof RelativeDurationUnits)[number];\n\n/**\n * Type guard to validate and assert that a string is a valid time unit.\n *\n * @param u - The string to check\n * @throws {Error} When the unit is not supported\n */\nexport function checkDurationUnit(u: string): asserts u is RelativeDurationUnit {\n\tif (!RelativeDurationUnits.includes(u as RelativeDurationUnit)) {\n\t\tthrow new Error(`Invalid unit: ${u}`);\n\t}\n}\n"],"names":["dayjs","duration","quarterOfYear","weekOfYear","extend","resolveRelativeTime","s","now","out","Date","startsWith","isNaN","getTime","Error","current","remaining","slice","toDate","parts","split","filter","part","i","length","operator","operand","checkDurationUnit","startOf","endOf","match","amountStr","unit","amount","parseInt","add","subtract","RelativeDurationUnits","u","includes"],"mappings":"AAAA,OAAOA,WAAW,QAAQ;AAC1B,OAAOC,cAAc,wBAAwB;AAC7C,OAAOC,mBAAmB,6BAA6B;AACvD,OAAOC,gBAAgB,0BAA0B;AAEjDH,MAAMI,MAAM,CAACH;AACbD,MAAMI,MAAM,CAACF;AACbF,MAAMI,MAAM,CAACD;AAEb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmEC,GACD,OAAO,SAASE,oBAAoBC,CAAyB,EAAEC,GAAsB;IACpF;QACC,IAAIC;QACJ,IAAI,CAACF,GAAG,CACR,OAAO,IAAIA,aAAaG,MAAM;YAC7BD,MAAMF;QACP,OAAO,IAAI,OAAOA,MAAM,UAAU;YACjCE,MAAM,IAAIC,KAAKH;QAChB,OAAO,IAAI,CAACA,EAAEI,UAAU,CAAC,QAAQ;YAChCF,MAAM,IAAIC,KAAKH;QAChB;QACA,IAAIE,KAAK;YACR,IAAIG,MAAMH,IAAII,OAAO,KAAK;gBACzB,MAAM,IAAIC,MAAM,CAAC,cAAc,EAAEP,GAAG;YACrC;YACA,OAAOE;QACR;IACD;IAEA,IAAI,OAAOF,MAAM,YAAY,CAACA,EAAEI,UAAU,CAAC,QAAQ;QAClD,MAAM,IAAIG,MAAM,CAAC,8BAA8B,EAAEP,GAAG;IACrD;IAEA,IAAIQ,UAAUd,MAAMO;IACpB,MAAMQ,YAAYT,EAAEU,KAAK,CAAC,IAAI,eAAe;IAE7C,IAAI,CAACD,WAAW;QACf,OAAOD,QAAQG,MAAM;IACtB;IAEA,sDAAsD;IACtD,MAAMC,QAAQH,UAAUI,KAAK,CAAC,cAAcC,MAAM,CAAC,CAACC,OAASA,SAAS;IAEtE,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,MAAMK,MAAM,EAAED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ybeDate } from '@wener/utils';\nimport dayjs from 'dayjs';\nimport duration from 'dayjs/plugin/duration';\nimport quarterOfYear from 'dayjs/plugin/quarterOfYear';\nimport weekOfYear from 'dayjs/plugin/weekOfYear';\n\ndayjs.extend(duration);\ndayjs.extend(quarterOfYear);\ndayjs.extend(weekOfYear);\n\n/**\n * Resolves a Grafana-style relative time string and returns the corresponding Date.\n *\n * @param s - The relative time string to parse (must start with \"now\")\n * @param now - Optional reference date. If undefined, uses current time\n * @returns The calculated Date based on the relative time expression\n *\n * @throws {Error} When the format is invalid or contains unsupported operators/units\n *\n * ## Syntax\n *\n * All expressions must start with `now` followed by optional operations:\n *\n * ### Operators\n * - `-` - Subtraction (e.g., `now-1h` for one hour ago)\n * - `+` - Addition (e.g., `now+1d` for one day from now)\n * - `/` - Truncation to beginning of time unit (e.g., `now/d` for start of current day)\n * - `\\` - Truncation to end of time unit (e.g., `now\\d` for end of current day)\n *\n * ### Time Units\n * - `s` - seconds\n * - `m` - minutes\n * - `h` - hours\n * - `d` - days\n * - `w` - weeks\n * - `M` - months\n * - `Q` - quarters\n * - `y` - years\n *\n * ### Operations\n * Operations are processed sequentially from left to right:\n * - **Addition/Subtraction**: `now±{count}{unit}` (e.g., `now-24h`, `now+1d`)\n * - **Truncation to start**: `now/{unit}` (e.g., `now/d`, `now/M`)\n * - **Truncation to end**: `now\\{unit}` (e.g., `now\\d`, `now\\M`)\n * - **Complex**: Multiple operations can be chained (e.g., `now-1M/M`, `now\\d`, `now-1y\\y`)\n *\n * @example\n * ```typescript\n * // Basic usage\n * resolveRelativeTime('now') // Current time\n * resolveRelativeTime('now-1h') // One hour ago\n * resolveRelativeTime('now+1d') // One day from now\n * resolveRelativeTime('now/d') // Start of current day\n * resolveRelativeTime('now\\\\d') // End of current day\n *\n * // Common patterns\n * resolveRelativeTime('now-24h') // Last 24 hours\n * resolveRelativeTime('now-7d') // Last 7 days\n * resolveRelativeTime('now/M') // Start of current month\n * resolveRelativeTime('now\\\\M') // End of current month\n * resolveRelativeTime('now-1M/M') // Start of previous month\n * resolveRelativeTime('now-1M\\\\M') // End of previous month\n * resolveRelativeTime('now/w') // Start of current week\n * resolveRelativeTime('now\\\\w') // End of current week\n * resolveRelativeTime('now/y') // Start of current year\n * resolveRelativeTime('now\\\\y') // End of current year\n *\n * // Complex expressions\n * resolveRelativeTime('now/d+1d-1s') // End of current day (alternative method)\n * resolveRelativeTime('now\\\\d') // End of current day (direct method)\n * resolveRelativeTime('now-1w+2d-3h') // 1 week ago, plus 2 days, minus 3 hours\n *\n * // With reference date\n * const refDate = new Date('2024-03-15T14:30:45.123Z');\n * resolveRelativeTime('now-1h', refDate); // One hour before reference date\n * resolveRelativeTime('now\\\\d', refDate); // End of reference day\n * ```\n */\nexport function resolveRelativeTime(s: string | Date | number, now?: Date | undefined): Date;\nexport function resolveRelativeTime(s: MaybeDate, now?: Date | undefined): Date | undefined;\nexport function resolveRelativeTime(s: MaybeDate, now?: Date | undefined): Date | undefined {\n\t{\n\t\tlet out = parseDate(s);\n\t\tif (out) {\n\t\t\treturn out;\n\t\t}\n\t\tif (s == null) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tif (typeof s === 'string' && s.startsWith('now')) {\n\t\t// valid\n\t} else {\n\t\tthrow new Error(`Invalid relative time format: ${s}`);\n\t}\n\n\tlet current = dayjs(now);\n\tconst remaining = s.slice(3); // Remove 'now'\n\n\tif (!remaining) {\n\t\treturn current.toDate();\n\t}\n\n\t// Split by operators while keeping them in the result\n\tconst parts = remaining.split(/([+\\-/\\\\])/).filter((part) => part !== '');\n\n\tfor (let i = 0; i < parts.length; i += 2) {\n\t\tconst operator = parts[i];\n\t\tconst operand = parts[i + 1];\n\n\t\tif (!operator || !operand) {\n\t\t\tthrow new Error(`Invalid relative time format: ${s}`);\n\t\t}\n\n\t\tif (operator === '/') {\n\t\t\t// Truncation to start operation\n\t\t\tcheckDurationUnit(operand);\n\t\t\tcurrent = current.startOf(operand);\n\t\t} else if (operator === '\\\\') {\n\t\t\t// Truncation to end operation\n\t\t\tcheckDurationUnit(operand);\n\t\t\tcurrent = current.endOf(operand);\n\t\t} else {\n\t\t\t// Addition or subtraction operation\n\t\t\tconst match = operand.match(/^(\\d+)([smhdwMQy])$/);\n\t\t\tif (!match) {\n\t\t\t\tthrow new Error(`Invalid time operand: ${operand}`);\n\t\t\t}\n\n\t\t\tconst [, amountStr, unit] = match;\n\t\t\tcheckDurationUnit(unit);\n\t\t\tconst amount = parseInt(amountStr, 10);\n\n\t\t\tif (operator === '+') {\n\t\t\t\tcurrent = current.add(amount, unit as 'w');\n\t\t\t} else if (operator === '-') {\n\t\t\t\tcurrent = current.subtract(amount, unit as 'Q');\n\t\t\t} else {\n\t\t\t\tthrow new Error(`Invalid operator: ${operator}`);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn current.toDate();\n}\n\n/** Array of all valid time units */\nexport const RelativeDurationUnits = ['ms', 's', 'm', 'h', 'd', 'w', 'M', 'Q', 'y'] as const;\n\n/** Valid time units for relative time expressions */\nexport type RelativeDurationUnit = (typeof RelativeDurationUnits)[number];\n\n/**\n * Type guard to validate and assert that a string is a valid time unit.\n *\n * @param u - The string to check\n * @throws {Error} When the unit is not supported\n */\nexport function checkDurationUnit(u: string): asserts u is RelativeDurationUnit {\n\tif (!RelativeDurationUnits.includes(u as RelativeDurationUnit)) {\n\t\tthrow new Error(`Invalid unit: ${u}`);\n\t}\n}\n"],"names":["parseDate","dayjs","duration","quarterOfYear","weekOfYear","extend","resolveRelativeTime","s","now","out","startsWith","Error","current","remaining","slice","toDate","parts","split","filter","part","i","length","operator","operand","checkDurationUnit","startOf","endOf","match","amountStr","unit","amount","parseInt","add","subtract","RelativeDurationUnits","u","includes"],"mappings":"AAAA,SAASA,SAAS,QAAwB,eAAe;AACzD,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,cAAc,wBAAwB;AAC7C,OAAOC,mBAAmB,6BAA6B;AACvD,OAAOC,gBAAgB,0BAA0B;AAEjDH,MAAMI,MAA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