@wener/utils 1.1.47 → 1.1.49

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 (194) hide show
  1. package/README.md +9 -1
  2. package/lib/asyncs/Promises.js +54 -0
  3. package/lib/asyncs/Promises.js.map +1 -0
  4. package/lib/asyncs/createLazyPromise.js +52 -51
  5. package/lib/asyncs/createLazyPromise.js.map +1 -1
  6. package/lib/asyncs/firstOfAsyncIterator.js.map +1 -1
  7. package/lib/asyncs/isPromise.js +2 -3
  8. package/lib/asyncs/isPromise.js.map +1 -1
  9. package/lib/asyncs/nextOfAsyncIterator.js.map +1 -1
  10. package/lib/asyncs/timeout.js +4 -4
  11. package/lib/asyncs/timeout.js.map +1 -1
  12. package/lib/cn/division/DivisionCode.js +30 -17
  13. package/lib/cn/division/DivisionCode.js.map +1 -1
  14. package/lib/cn/id/{Mod11Checksum.js → Mod11.js} +3 -6
  15. package/lib/cn/id/Mod11.js.map +1 -0
  16. package/lib/cn/id/ResidentIdNumber.js +10 -12
  17. package/lib/cn/id/ResidentIdNumber.js.map +1 -1
  18. package/lib/cn/types.js +3 -0
  19. package/lib/cn/types.js.map +1 -0
  20. package/lib/cn/uscc/{Mod31Checksum.js → Mod31.js} +3 -6
  21. package/lib/cn/uscc/Mod31.js.map +1 -0
  22. package/lib/cn/uscc/USCC.js +6 -9
  23. package/lib/cn/uscc/USCC.js.map +1 -1
  24. package/lib/cn/uscc/isUSCC.js +1 -1
  25. package/lib/cn/uscc/isUSCC.js.map +1 -1
  26. package/lib/crypto/getNodeCrypto.js +14 -10
  27. package/lib/crypto/getNodeCrypto.js.map +1 -1
  28. package/lib/crypto/getRandomValues.js +5 -1
  29. package/lib/crypto/getRandomValues.js.map +1 -1
  30. package/lib/emitter/types.js +3 -0
  31. package/lib/emitter/types.js.map +1 -0
  32. package/lib/fetch/createFetchWith.js.map +1 -1
  33. package/lib/fetch/createFetchWithRetry.js.map +1 -1
  34. package/lib/fetch/http.types.js +4 -0
  35. package/lib/fetch/http.types.js.map +1 -0
  36. package/lib/index.js +6 -3
  37. package/lib/index.js.map +1 -1
  38. package/lib/io/ArrayBuffers.js.map +1 -1
  39. package/lib/io/ByteBuffer.js +235 -36
  40. package/lib/io/ByteBuffer.js.map +1 -1
  41. package/lib/langs/getGlobalStates.js +17 -0
  42. package/lib/langs/getGlobalStates.js.map +1 -0
  43. package/lib/langs/getObjectId.js +18 -0
  44. package/lib/langs/getObjectId.js.map +1 -0
  45. package/lib/langs/isNullish.js +5 -0
  46. package/lib/langs/isNullish.js.map +1 -0
  47. package/lib/logging/slog.js.map +1 -1
  48. package/lib/maths/clamp.js +7 -6
  49. package/lib/maths/clamp.js.map +1 -1
  50. package/lib/maths/random.js.map +1 -1
  51. package/lib/mitt/index.js +77 -0
  52. package/lib/mitt/index.js.map +1 -0
  53. package/lib/objects/computeIfAbsent.js +1 -1
  54. package/lib/objects/computeIfAbsent.js.map +1 -1
  55. package/lib/schema/typebox/typebox.js.map +1 -1
  56. package/lib/server/fetch/createFetchWithProxyByUndici.js.map +1 -1
  57. package/package.json +6 -14
  58. package/src/asyncs/Promises.ts +62 -0
  59. package/src/asyncs/createLazyPromise.test.ts +52 -13
  60. package/src/asyncs/createLazyPromise.ts +66 -61
  61. package/src/asyncs/firstOfAsyncIterator.ts +1 -1
  62. package/src/asyncs/isPromise.ts +3 -3
  63. package/src/asyncs/nextOfAsyncIterator.ts +1 -1
  64. package/src/asyncs/timeout.ts +4 -4
  65. package/src/cn/division/DivisionCode.ts +61 -8
  66. package/src/cn/division/division.test.ts +6 -0
  67. package/src/cn/id/{Mod11Checksum.ts → Mod11.ts} +3 -6
  68. package/src/cn/id/ResidentIdNumber.ts +11 -13
  69. package/src/cn/id/id.test.ts +5 -5
  70. package/src/cn/scripts/gen.test.ts +2 -1
  71. package/src/cn/types.ts +11 -0
  72. package/src/cn/uscc/{Mod31Checksum.ts → Mod31.ts} +3 -7
  73. package/src/cn/uscc/USCC.ts +7 -11
  74. package/src/cn/uscc/isUSCC.ts +1 -1
  75. package/src/cn/uscc/uscc.test.ts +4 -4
  76. package/src/crypto/getNodeCrypto.ts +16 -11
  77. package/src/crypto/getRandomValues.ts +6 -1
  78. package/src/emitter/types.ts +18 -0
  79. package/src/fetch/createFetchWith.ts +1 -1
  80. package/src/fetch/createFetchWithRetry.ts +1 -1
  81. package/src/fetch/http.types.ts +46 -0
  82. package/src/index.ts +7 -3
  83. package/src/io/ArrayBuffers.ts +7 -3
  84. package/src/io/ByteBuffer.test.ts +33 -6
  85. package/src/io/ByteBuffer.ts +272 -41
  86. package/src/langs/getGlobalStates.ts +21 -0
  87. package/src/langs/getObjectId.ts +20 -0
  88. package/src/langs/isNullish.ts +3 -0
  89. package/src/langs/mixin.test.ts +43 -0
  90. package/src/logging/slog.ts +1 -1
  91. package/src/maths/clamp.test.ts +5 -1
  92. package/src/maths/clamp.ts +7 -7
  93. package/src/maths/random.ts +1 -1
  94. package/src/mitt/README.md +1 -0
  95. package/src/mitt/index.ts +114 -0
  96. package/src/objects/computeIfAbsent.ts +3 -2
  97. package/src/objects/merge/merge.test.ts +1 -1
  98. package/src/schema/typebox/typebox.ts +1 -1
  99. package/src/server/fetch/createFetchWithProxyByUndici.ts +2 -2
  100. package/tsconfig.json +4 -1
  101. package/lib/asyncs/sleep.js +0 -3
  102. package/lib/asyncs/sleep.js.map +0 -1
  103. package/lib/cn/id/Mod11Checksum.js.map +0 -1
  104. package/lib/cn/uscc/Mod31Checksum.js.map +0 -1
  105. package/lib/schema/typebox/gen/codegen/common/encoder.js +0 -94
  106. package/lib/schema/typebox/gen/codegen/common/encoder.js.map +0 -1
  107. package/lib/schema/typebox/gen/codegen/common/formatter.js +0 -33
  108. package/lib/schema/typebox/gen/codegen/common/formatter.js.map +0 -1
  109. package/lib/schema/typebox/gen/codegen/common/index.js +0 -29
  110. package/lib/schema/typebox/gen/codegen/common/index.js.map +0 -1
  111. package/lib/schema/typebox/gen/codegen/common/jsdoc.js +0 -117
  112. package/lib/schema/typebox/gen/codegen/common/jsdoc.js.map +0 -1
  113. package/lib/schema/typebox/gen/codegen/expression/compiler.js +0 -364
  114. package/lib/schema/typebox/gen/codegen/expression/compiler.js.map +0 -1
  115. package/lib/schema/typebox/gen/codegen/expression/errors.js +0 -259
  116. package/lib/schema/typebox/gen/codegen/expression/errors.js.map +0 -1
  117. package/lib/schema/typebox/gen/codegen/expression/evaluator.js +0 -254
  118. package/lib/schema/typebox/gen/codegen/expression/evaluator.js.map +0 -1
  119. package/lib/schema/typebox/gen/codegen/expression/expression.js +0 -381
  120. package/lib/schema/typebox/gen/codegen/expression/expression.js.map +0 -1
  121. package/lib/schema/typebox/gen/codegen/expression/index.js +0 -32
  122. package/lib/schema/typebox/gen/codegen/expression/index.js.map +0 -1
  123. package/lib/schema/typebox/gen/codegen/index.js +0 -29
  124. package/lib/schema/typebox/gen/codegen/index.js.map +0 -1
  125. package/lib/schema/typebox/gen/codegen/model/index.js +0 -40
  126. package/lib/schema/typebox/gen/codegen/model/index.js.map +0 -1
  127. package/lib/schema/typebox/gen/codegen/model/model-to-arktype.js +0 -260
  128. package/lib/schema/typebox/gen/codegen/model/model-to-arktype.js.map +0 -1
  129. package/lib/schema/typebox/gen/codegen/model/model-to-expression.js +0 -383
  130. package/lib/schema/typebox/gen/codegen/model/model-to-expression.js.map +0 -1
  131. package/lib/schema/typebox/gen/codegen/model/model-to-grpc.js +0 -238
  132. package/lib/schema/typebox/gen/codegen/model/model-to-grpc.js.map +0 -1
  133. package/lib/schema/typebox/gen/codegen/model/model-to-io-ts.js +0 -274
  134. package/lib/schema/typebox/gen/codegen/model/model-to-io-ts.js.map +0 -1
  135. package/lib/schema/typebox/gen/codegen/model/model-to-javascript.js +0 -47
  136. package/lib/schema/typebox/gen/codegen/model/model-to-javascript.js.map +0 -1
  137. package/lib/schema/typebox/gen/codegen/model/model-to-json-schema.js +0 -192
  138. package/lib/schema/typebox/gen/codegen/model/model-to-json-schema.js.map +0 -1
  139. package/lib/schema/typebox/gen/codegen/model/model-to-typebox.js +0 -33
  140. package/lib/schema/typebox/gen/codegen/model/model-to-typebox.js.map +0 -1
  141. package/lib/schema/typebox/gen/codegen/model/model-to-typescript.js +0 -188
  142. package/lib/schema/typebox/gen/codegen/model/model-to-typescript.js.map +0 -1
  143. package/lib/schema/typebox/gen/codegen/model/model-to-valibot.js +0 -239
  144. package/lib/schema/typebox/gen/codegen/model/model-to-valibot.js.map +0 -1
  145. package/lib/schema/typebox/gen/codegen/model/model-to-value.js +0 -43
  146. package/lib/schema/typebox/gen/codegen/model/model-to-value.js.map +0 -1
  147. package/lib/schema/typebox/gen/codegen/model/model-to-yrel.js +0 -227
  148. package/lib/schema/typebox/gen/codegen/model/model-to-yrel.js.map +0 -1
  149. package/lib/schema/typebox/gen/codegen/model/model-to-yup.js +0 -225
  150. package/lib/schema/typebox/gen/codegen/model/model-to-yup.js.map +0 -1
  151. package/lib/schema/typebox/gen/codegen/model/model-to-zod.js +0 -248
  152. package/lib/schema/typebox/gen/codegen/model/model-to-zod.js.map +0 -1
  153. package/lib/schema/typebox/gen/codegen/model/model.js +0 -27
  154. package/lib/schema/typebox/gen/codegen/model/model.js.map +0 -1
  155. package/lib/schema/typebox/gen/codegen/typescript/index.js +0 -28
  156. package/lib/schema/typebox/gen/codegen/typescript/index.js.map +0 -1
  157. package/lib/schema/typebox/gen/codegen/typescript/typescript-to-model.js +0 -72
  158. package/lib/schema/typebox/gen/codegen/typescript/typescript-to-model.js.map +0 -1
  159. package/lib/schema/typebox/gen/codegen/typescript/typescript-to-typebox.js +0 -620
  160. package/lib/schema/typebox/gen/codegen/typescript/typescript-to-typebox.js.map +0 -1
  161. package/lib/schema/typebox/gen/index.js +0 -3
  162. package/lib/schema/typebox/gen/index.js.map +0 -1
  163. package/src/asyncs/sleep.ts +0 -1
  164. package/src/schema/typebox/gen/codegen/common/encoder.ts +0 -99
  165. package/src/schema/typebox/gen/codegen/common/formatter.ts +0 -31
  166. package/src/schema/typebox/gen/codegen/common/index.ts +0 -29
  167. package/src/schema/typebox/gen/codegen/common/jsdoc.ts +0 -93
  168. package/src/schema/typebox/gen/codegen/expression/compiler.ts +0 -377
  169. package/src/schema/typebox/gen/codegen/expression/errors.ts +0 -302
  170. package/src/schema/typebox/gen/codegen/expression/evaluator.ts +0 -268
  171. package/src/schema/typebox/gen/codegen/expression/expression.ts +0 -538
  172. package/src/schema/typebox/gen/codegen/expression/index.ts +0 -32
  173. package/src/schema/typebox/gen/codegen/index.ts +0 -29
  174. package/src/schema/typebox/gen/codegen/model/index.ts +0 -40
  175. package/src/schema/typebox/gen/codegen/model/model-to-arktype.ts +0 -266
  176. package/src/schema/typebox/gen/codegen/model/model-to-expression.ts +0 -378
  177. package/src/schema/typebox/gen/codegen/model/model-to-grpc.ts +0 -244
  178. package/src/schema/typebox/gen/codegen/model/model-to-io-ts.ts +0 -294
  179. package/src/schema/typebox/gen/codegen/model/model-to-javascript.ts +0 -42
  180. package/src/schema/typebox/gen/codegen/model/model-to-json-schema.ts +0 -166
  181. package/src/schema/typebox/gen/codegen/model/model-to-typebox.ts +0 -32
  182. package/src/schema/typebox/gen/codegen/model/model-to-typescript.ts +0 -189
  183. package/src/schema/typebox/gen/codegen/model/model-to-valibot.ts +0 -236
  184. package/src/schema/typebox/gen/codegen/model/model-to-value.ts +0 -42
  185. package/src/schema/typebox/gen/codegen/model/model-to-yrel.ts +0 -232
  186. package/src/schema/typebox/gen/codegen/model/model-to-yup.ts +0 -226
  187. package/src/schema/typebox/gen/codegen/model/model-to-zod.ts +0 -251
  188. package/src/schema/typebox/gen/codegen/model/model.ts +0 -33
  189. package/src/schema/typebox/gen/codegen/typescript/index.ts +0 -28
  190. package/src/schema/typebox/gen/codegen/typescript/typescript-to-model.ts +0 -61
  191. package/src/schema/typebox/gen/codegen/typescript/typescript-to-typebox.ts +0 -647
  192. package/src/schema/typebox/gen/gen.test.ts +0 -12
  193. package/src/schema/typebox/gen/index.ts +0 -1
  194. /package/src/schema/{typebox/gen/README.md → README.md} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/cn/uscc/USCC.ts"],"sourcesContent":["import { Mod31Checksum } from './Mod31Checksum';\n\n/**\n * - GB 32100-2015 法人和其他组织统一社会信用代码编码规则\n * - USCI -> UnifiedSocialCreditIdentifier\n * - USCC -> Unified Social Credit Code - 官方叫法\n * - Business License\n *\n * @see https://en.wikipedia.org/wiki/Unified_Social_Credit_Identifier\n */\nexport class USCC {\n registryCodeLabels: Record<string, Code> = {\n 1: {\n label: '机构编制',\n children: {\n 1: { label: '机关' },\n 2: { label: '事业单位' },\n 3: { label: '中央编办直接管理机构编制的群众团体' },\n 9: { label: '其他' },\n },\n },\n 5: {\n label: '民政',\n children: {\n 1: { label: '社会团体' },\n 2: { label: '民办非企业单位' },\n 3: { label: '基金会' },\n 9: { label: '其他' },\n },\n },\n 9: {\n label: '工商',\n children: {\n 1: { label: '企业' },\n 2: { label: '个体工商户' },\n 3: { label: '农民专业合作社' },\n 9: { label: '其他' },\n },\n },\n Y: {\n label: '其他',\n children: {\n 1: { label: '其他' },\n },\n },\n };\n\n /* 16 位 */\n regex = /^([159][1239]|Y1)[0-9]{6}[0-9A-HJ-NP-RTUWXY]{10}$/; // 无 I O Z S V\n checksum = Mod31Checksum.get();\n\n static instance: USCC;\n\n static get() {\n return (this.instance ||= new USCC());\n }\n\n parse(s: string): ParsedUSCC {\n let registryCode = s[0];\n let l1 = this.registryCodeLabels[registryCode];\n let organizationTypeCode = s[1];\n return {\n registryAuthorityCode: registryCode,\n registryAuthorityCodeLabel: l1?.label,\n organizationTypeCode,\n organizationTypeLabel: l1?.children?.[organizationTypeCode]?.label,\n registryDivisionCode: s.slice(3, 6),\n // GB 11714-1997 全国组织机构代码编制规则\n subject: s.slice(6, 15),\n checksum: s.slice(17, 18),\n };\n }\n\n verify(s: string) {\n return this.regex.test(s) && this.checksum.verify(s);\n }\n}\n\ninterface Code {\n label: string;\n children?: Record<string, Code>;\n}\n\ninterface ParsedUSCC {\n // 登记管理部门码\n registryAuthorityCode: string;\n registryAuthorityCodeLabel?: string;\n // 机构类别代码\n organizationTypeCode: string;\n organizationTypeLabel?: string;\n // 登记管理机关行政区划代码\n registryDivisionCode: string;\n registryDivisionLabel?: string;\n // 主体标识码\n subject: string;\n // 校验码\n checksum: string;\n}\n"],"names":["Mod31Checksum","USCC","registryCodeLabels","label","children","Y","regex","checksum","get","instance","parse","s","registryCode","l1","organizationTypeCode","registryAuthorityCode","registryAuthorityCodeLabel","organizationTypeLabel","registryDivisionCode","slice","subject","verify","test"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,aAAa,QAAQ,kBAAkB;AAEhD;;;;;;;CAOC,GACD,OAAO,MAAMC;IACXC,qBAA2C;QACzC,GAAG;YACDC,OAAO;YACPC,UAAU;gBACR,GAAG;oBAAED,OAAO;gBAAK;gBACjB,GAAG;oBAAEA,OAAO;gBAAO;gBACnB,GAAG;oBAAEA,OAAO;gBAAoB;gBAChC,GAAG;oBAAEA,OAAO;gBAAK;YACnB;QACF;QACA,GAAG;YACDA,OAAO;YACPC,UAAU;gBACR,GAAG;oBAAED,OAAO;gBAAO;gBACnB,GAAG;oBAAEA,OAAO;gBAAU;gBACtB,GAAG;oBAAEA,OAAO;gBAAM;gBAClB,GAAG;oBAAEA,OAAO;gBAAK;YACnB;QACF;QACA,GAAG;YACDA,OAAO;YACPC,UAAU;gBACR,GAAG;oBAAED,OAAO;gBAAK;gBACjB,GAAG;oBAAEA,OAAO;gBAAQ;gBACpB,GAAG;oBAAEA,OAAO;gBAAU;gBACtB,GAAG;oBAAEA,OAAO;gBAAK;YACnB;QACF;QACAE,GAAG;YACDF,OAAO;YACPC,UAAU;gBACR,GAAG;oBAAED,OAAO;gBAAK;YACnB;QACF;IACF,EAAE;IAEF,QAAQ,GACRG,QAAQ,oDAAoD;IAC5DC,WAAWP,cAAcQ,GAAG,GAAG;IAE/B,OAAOC,SAAe;IAEtB,OAAOD,MAAM;QACX,OAAQ,IAAI,CAACC,QAAQ,KAAK,IAAIR;IAChC;IAEAS,MAAMC,CAAS,EAAc;QAC3B,IAAIC,eAAeD,CAAC,CAAC,EAAE;QACvB,IAAIE,KAAK,IAAI,CAACX,kBAAkB,CAACU,aAAa;QAC9C,IAAIE,uBAAuBH,CAAC,CAAC,EAAE;QAC/B,OAAO;YACLI,uBAAuBH;YACvBI,4BAA4BH,IAAIV;YAChCW;YACAG,uBAAuBJ,IAAIT,UAAU,CAACU,qBAAqB,EAAEX;YAC7De,sBAAsBP,EAAEQ,KAAK,CAAC,GAAG;YACjC,6BAA6B;YAC7BC,SAAST,EAAEQ,KAAK,CAAC,GAAG;YACpBZ,UAAUI,EAAEQ,KAAK,CAAC,IAAI;QACxB;IACF;IAEAE,OAAOV,CAAS,EAAE;QAChB,OAAO,IAAI,CAACL,KAAK,CAACgB,IAAI,CAACX,MAAM,IAAI,CAACJ,QAAQ,CAACc,MAAM,CAACV;IACpD;AACF"}
1
+ {"version":3,"sources":["../../../src/cn/uscc/USCC.ts"],"sourcesContent":["import { Mod31 } from './Mod31';\n\n/**\n * - GB 32100-2015 法人和其他组织统一社会信用代码编码规则\n * - USCI -> UnifiedSocialCreditIdentifier\n * - USCC -> Unified Social Credit Code - 官方叫法\n * - Business License\n *\n * @see https://en.wikipedia.org/wiki/Unified_Social_Credit_Identifier\n */\nexport class UnifiedSocialCreditCodeFormat {\n registryCodeLabels: Record<string, Code> = {\n 1: {\n label: '机构编制',\n children: {\n 1: { label: '机关' },\n 2: { label: '事业单位' },\n 3: { label: '中央编办直接管理机构编制的群众团体' },\n 9: { label: '其他' },\n },\n },\n 5: {\n label: '民政',\n children: {\n 1: { label: '社会团体' },\n 2: { label: '民办非企业单位' },\n 3: { label: '基金会' },\n 9: { label: '其他' },\n },\n },\n 9: {\n label: '工商',\n children: {\n 1: { label: '企业' },\n 2: { label: '个体工商户' },\n 3: { label: '农民专业合作社' },\n 9: { label: '其他' },\n },\n },\n Y: {\n label: '其他',\n children: {\n 1: { label: '其他' },\n },\n },\n };\n\n /* 16 位 */\n regex = /^([159][1239]|Y1)[0-9]{6}[0-9A-HJ-NP-RTUWXY]{10}$/; // 无 I O Z S V\n checksum = Mod31;\n\n parse(s: string): ParsedUSCC {\n let registryCode = s[0];\n let l1 = this.registryCodeLabels[registryCode];\n let organizationTypeCode = s[1];\n return {\n registryAuthorityCode: registryCode,\n registryAuthorityCodeLabel: l1?.label,\n organizationTypeCode,\n organizationTypeLabel: l1?.children?.[organizationTypeCode]?.label,\n registryDivisionCode: s.slice(3, 6),\n // GB 11714-1997 全国组织机构代码编制规则\n subject: s.slice(6, 15),\n checksum: s.slice(17, 18),\n };\n }\n\n validate(s: string) {\n return this.regex.test(s) && this.checksum.validate(s);\n }\n}\n\ninterface Code {\n label: string;\n children?: Record<string, Code>;\n}\n\ninterface ParsedUSCC {\n // 登记管理部门码\n registryAuthorityCode: string;\n registryAuthorityCodeLabel?: string;\n // 机构类别代码\n organizationTypeCode: string;\n organizationTypeLabel?: string;\n // 登记管理机关行政区划代码\n registryDivisionCode: string;\n registryDivisionLabel?: string;\n // 主体标识码\n subject: string;\n // 校验码\n checksum: string;\n}\n\nexport const USCC = new UnifiedSocialCreditCodeFormat();\n"],"names":["Mod31","UnifiedSocialCreditCodeFormat","registryCodeLabels","label","children","Y","regex","checksum","parse","s","registryCode","l1","organizationTypeCode","registryAuthorityCode","registryAuthorityCodeLabel","organizationTypeLabel","registryDivisionCode","slice","subject","validate","test","USCC"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,KAAK,QAAQ,UAAU;AAEhC;;;;;;;CAOC,GACD,OAAO,MAAMC;IACXC,qBAA2C;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AAQ,CAACV;IACtD;AACF;AAuBA,OAAO,MAAMY,OAAO,IAAIpB,gCAAgC"}
@@ -2,7 +2,7 @@ import { USCC } from './USCC.js';
2
2
  /**
3
3
  * USCC - 统一社会信用代码
4
4
  */ export function isUSCC(s) {
5
- return USCC.get().verify(s);
5
+ return USCC.validate(s);
6
6
  }
7
7
 
8
8
  //# sourceMappingURL=isUSCC.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/cn/uscc/isUSCC.ts"],"sourcesContent":["import { USCC } from './USCC';\n\n/**\n * USCC - 统一社会信用代码\n */\nexport function isUSCC(s: string) {\n return USCC.get().verify(s);\n}\n"],"names":["USCC","isUSCC","s","get","verify"],"rangeMappings":";;;;;","mappings":"AAAA,SAASA,IAAI,QAAQ,SAAS;AAE9B;;CAEC,GACD,OAAO,SAASC,OAAOC,CAAS;IAC9B,OAAOF,KAAKG,GAAG,GAAGC,MAAM,CAACF;AAC3B"}
1
+ {"version":3,"sources":["../../../src/cn/uscc/isUSCC.ts"],"sourcesContent":["import { USCC } from './USCC';\n\n/**\n * USCC - 统一社会信用代码\n */\nexport function isUSCC(s: string) {\n return USCC.validate(s);\n}\n"],"names":["USCC","isUSCC","s","validate"],"rangeMappings":";;;;;","mappings":"AAAA,SAASA,IAAI,QAAQ,SAAS;AAE9B;;CAEC,GACD,OAAO,SAASC,OAAOC,CAAS;IAC9B,OAAOF,KAAKG,QAAQ,CAACD;AACvB"}
@@ -1,17 +1,21 @@
1
+ // import type * as NodeCrypto from 'node:crypto';
2
+ import { getGlobalThis } from '../runtime/getGlobalThis.js';
1
3
  let nodeCrypto;
2
4
  // globalThis.process?.release?.name
5
+ // avoid import node
3
6
  // avoid process.browser
4
- if (typeof window === 'undefined') {
5
- try {
6
- // avoid `node:` UnhandledSchemeError https://github.com/vercel/next.js/issues/28774
7
- if (typeof require === 'undefined') {
8
- void import('crypto').then((v)=>nodeCrypto = v.default);
9
- } else {
10
- nodeCrypto = require('crypto');
11
- }
12
- } catch (e) {}
13
- }
7
+ // if (typeof window === 'undefined') {
8
+ // try {
9
+ // // avoid `node:` UnhandledSchemeError https://github.com/vercel/next.js/issues/28774
10
+ // if (typeof require === 'undefined') {
11
+ // void import('crypto').then((v) => (nodeCrypto = v.default));
12
+ // } else {
13
+ // nodeCrypto = require('crypto');
14
+ // }
15
+ // } catch (e) {}
16
+ // }
14
17
  export function getNodeCrypto() {
18
+ nodeCrypto ||= getGlobalThis().crypto;
15
19
  return nodeCrypto;
16
20
  }
17
21
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/crypto/getNodeCrypto.ts"],"sourcesContent":["let nodeCrypto: Awaited<typeof import('node:crypto')>;\n// globalThis.process?.release?.name\n\n// avoid process.browser\nif (typeof window === 'undefined') {\n try {\n // avoid `node:` UnhandledSchemeError https://github.com/vercel/next.js/issues/28774\n if (typeof require === 'undefined') {\n void import('crypto').then((v) => (nodeCrypto = v.default));\n } else {\n nodeCrypto = require('crypto');\n }\n } catch (e) {}\n}\nexport function getNodeCrypto() {\n return nodeCrypto;\n}\n"],"names":["nodeCrypto","window","require","then","v","default","e","getNodeCrypto"],"rangeMappings":";;;;;;;;;;;;;;;","mappings":"AAAA,IAAIA;AACJ,oCAAoC;AAEpC,wBAAwB;AACxB,IAAI,OAAOC,WAAW,aAAa;IACjC,IAAI;QACF,oFAAoF;QACpF,IAAI,OAAOC,YAAY,aAAa;YAClC,KAAK,MAAM,CAAC,UAAUC,IAAI,CAAC,CAACC,IAAOJ,aAAaI,EAAEC,OAAO;QAC3D,OAAO;YACLL,aAAaE,QAAQ;QACvB;IACF,EAAE,OAAOI,GAAG,CAAC;AACf;AACA,OAAO,SAASC;IACd,OAAOP;AACT"}
1
+ {"version":3,"sources":["../../src/crypto/getNodeCrypto.ts"],"sourcesContent":["// import type * as NodeCrypto from 'node:crypto';\nimport { getGlobalThis } from '../runtime/getGlobalThis';\n\nlet nodeCrypto;\n// globalThis.process?.release?.name\n\n// avoid import node\n// avoid process.browser\n// if (typeof window === 'undefined') {\n// try {\n// // avoid `node:` UnhandledSchemeError https://github.com/vercel/next.js/issues/28774\n// if (typeof require === 'undefined') {\n// void import('crypto').then((v) => (nodeCrypto = v.default));\n// } else {\n// nodeCrypto = require('crypto');\n// }\n// } catch (e) {}\n// }\nexport function getNodeCrypto() {\n nodeCrypto ||= getGlobalThis().crypto;\n return nodeCrypto;\n}\n"],"names":["getGlobalThis","nodeCrypto","getNodeCrypto","crypto"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":"AAAA,kDAAkD;AAClD,SAASA,aAAa,QAAQ,2BAA2B;AAEzD,IAAIC;AACJ,oCAAoC;AAEpC,oBAAoB;AACpB,wBAAwB;AACxB,uCAAuC;AACvC,UAAU;AACV,2FAA2F;AAC3F,4CAA4C;AAC5C,qEAAqE;AACrE,eAAe;AACf,wCAAwC;AACxC,QAAQ;AACR,mBAAmB;AACnB,IAAI;AACJ,OAAO,SAASC;IACdD,eAAeD,gBAAgBG,MAAM;IACrC,OAAOF;AACT"}
@@ -2,7 +2,11 @@
2
2
  import { getGlobalThis } from '../runtime/getGlobalThis.js';
3
3
  import { getNodeCrypto } from './getNodeCrypto.js';
4
4
  const globalThis = getGlobalThis();
5
- export let getRandomValues = globalThis.crypto?.getRandomValues?.bind(globalThis.crypto) || globalThis.msCrypto?.getRandomValues?.bind(globalThis.msCrypto) || _getRandomValues;
5
+ // chrome 11+, safari 5+, nodejs 17.4+
6
+ // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
7
+ export let getRandomValues = globalThis.crypto?.getRandomValues?.bind(globalThis.crypto) || globalThis.msCrypto?.getRandomValues?.bind(globalThis.msCrypto) || (()=>{
8
+ throw new Error('[getRandomValues]: No secure random number generator available.');
9
+ });
6
10
  function _getRandomValues(buf) {
7
11
  const nodeCrypto = getNodeCrypto();
8
12
  // avoid type error
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/crypto/getRandomValues.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport type { TypedArray } from '../io/ArrayBuffers';\nimport { getGlobalThis } from '../runtime/getGlobalThis';\nimport { getNodeCrypto } from './getNodeCrypto';\n\nconst globalThis = getGlobalThis();\nexport let getRandomValues: <T extends Exclude<TypedArray, Float32Array | Float64Array>>(typedArray: T) => T =\n globalThis.crypto?.getRandomValues?.bind(globalThis.crypto) ||\n (globalThis as any).msCrypto?.getRandomValues?.bind((globalThis as any).msCrypto) ||\n _getRandomValues;\n\nfunction _getRandomValues<T extends Exclude<TypedArray, Float32Array | Float64Array>>(buf: T) {\n const nodeCrypto = getNodeCrypto();\n // avoid type error\n let wc = nodeCrypto?.webcrypto as any;\n if (wc?.getRandomValues) {\n getRandomValues = wc.getRandomValues?.bind(nodeCrypto?.webcrypto);\n return wc.getRandomValues(buf);\n }\n if (nodeCrypto?.randomBytes) {\n if (!(buf instanceof Uint8Array)) {\n throw new TypeError('expected Uint8Array');\n }\n if (buf.length > 65536) {\n const e: any = new Error();\n e.code = 22;\n e.message = `Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (${buf.length}) exceeds the number of bytes of entropy available via this API (65536).`;\n e.name = 'QuotaExceededError';\n throw e;\n }\n const bytes = nodeCrypto.randomBytes(buf.length);\n buf.set(bytes);\n return buf;\n }\n throw new Error('[getRandomValues]: No secure random number generator available.');\n}\n"],"names":["getGlobalThis","getNodeCrypto","globalThis","getRandomValues","crypto","bind","msCrypto","_getRandomValues","buf","nodeCrypto","wc","webcrypto","randomBytes","Uint8Array","TypeError","length","e","Error","code","message","name","bytes","set"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,sEAAsE;AAEtE,SAASA,aAAa,QAAQ,2BAA2B;AACzD,SAASC,aAAa,QAAQ,kBAAkB;AAEhD,MAAMC,aAAaF;AACnB,OAAO,IAAIG,kBACTD,WAAWE,MAAM,EAAED,iBAAiBE,KAAKH,WAAWE,MAAM,KAC1D,AAACF,WAAmBI,QAAQ,EAAEH,iBAAiBE,KAAK,AAACH,WAAmBI,QAAQ,KAChFC,iBAAiB;AAEnB,SAASA,iBAA6EC,GAAM;IAC1F,MAAMC,aAAaR;IACnB,mBAAmB;IACnB,IAAIS,KAAKD,YAAYE;IACrB,IAAID,IAAIP,iBAAiB;QACvBA,kBAAkBO,GAAGP,eAAe,EAAEE,KAAKI,YAAYE;QACvD,OAAOD,GAAGP,eAAe,CAACK;IAC5B;IACA,IAAIC,YAAYG,aAAa;QAC3B,IAAI,CAAEJ,CAAAA,eAAeK,UAAS,GAAI;YAChC,MAAM,IAAIC,UAAU;QACtB;QACA,IAAIN,IAAIO,MAAM,GAAG,OAAO;YACtB,MAAMC,IAAS,IAAIC;YACnBD,EAAEE,IAAI,GAAG;YACTF,EAAEG,OAAO,GAAG,CAAC,oFAAoF,EAAEX,IAAIO,MAAM,CAAC,wEAAwE,CAAC;YACvLC,EAAEI,IAAI,GAAG;YACT,MAAMJ;QACR;QACA,MAAMK,QAAQZ,WAAWG,WAAW,CAACJ,IAAIO,MAAM;QAC/CP,IAAIc,GAAG,CAACD;QACR,OAAOb;IACT;IACA,MAAM,IAAIS,MAAM;AAClB"}
1
+ {"version":3,"sources":["../../src/crypto/getRandomValues.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport type { TypedArray } from '../io/ArrayBuffers';\nimport { getGlobalThis } from '../runtime/getGlobalThis';\nimport { getNodeCrypto } from './getNodeCrypto';\n\nconst globalThis = getGlobalThis();\n\n// chrome 11+, safari 5+, nodejs 17.4+\n// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues\nexport let getRandomValues: <T extends Exclude<TypedArray, Float32Array | Float64Array>>(typedArray: T) => T =\n globalThis.crypto?.getRandomValues?.bind(globalThis.crypto) ||\n (globalThis as any).msCrypto?.getRandomValues?.bind((globalThis as any).msCrypto) ||\n (() => {\n throw new Error('[getRandomValues]: No secure random number generator available.');\n });\n\nfunction _getRandomValues<T extends Exclude<TypedArray, Float32Array | Float64Array>>(buf: T) {\n const nodeCrypto = getNodeCrypto();\n // avoid type error\n let wc = nodeCrypto?.webcrypto as any;\n if (wc?.getRandomValues) {\n getRandomValues = wc.getRandomValues?.bind(nodeCrypto?.webcrypto);\n return wc.getRandomValues(buf);\n }\n if (nodeCrypto?.randomBytes) {\n if (!(buf instanceof Uint8Array)) {\n throw new TypeError('expected Uint8Array');\n }\n if (buf.length > 65536) {\n const e: any = new Error();\n e.code = 22;\n e.message = `Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (${buf.length}) exceeds the number of bytes of entropy available via this API (65536).`;\n e.name = 'QuotaExceededError';\n throw e;\n }\n const bytes = nodeCrypto.randomBytes(buf.length);\n buf.set(bytes);\n return buf;\n }\n throw new Error('[getRandomValues]: No secure random number generator available.');\n}\n"],"names":["getGlobalThis","getNodeCrypto","globalThis","getRandomValues","crypto","bind","msCrypto","Error","_getRandomValues","buf","nodeCrypto","wc","webcrypto","randomBytes","Uint8Array","TypeError","length","e","code","message","name","bytes","set"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,sEAAsE;AAEtE,SAASA,aAAa,QAAQ,2BAA2B;AACzD,SAASC,aAAa,QAAQ,kBAAkB;AAEhD,MAAMC,aAAaF;AAEnB,sCAAsC;AACtC,0EAA0E;AAC1E,OAAO,IAAIG,kBACTD,WAAWE,MAAM,EAAED,iBAAiBE,KAAKH,WAAWE,MAAM,KAC1D,AAACF,WAAmBI,QAAQ,EAAEH,iBAAiBE,KAAK,AAACH,WAAmBI,QAAQ,KAC/E,CAAA;IACC,MAAM,IAAIC,MAAM;AAClB,CAAA,EAAG;AAEL,SAASC,iBAA6EC,GAAM;IAC1F,MAAMC,aAAaT;IACnB,mBAAmB;IACnB,IAAIU,KAAKD,YAAYE;IACrB,IAAID,IAAIR,iBAAiB;QACvBA,kBAAkBQ,GAAGR,eAAe,EAAEE,KAAKK,YAAYE;QACvD,OAAOD,GAAGR,eAAe,CAACM;IAC5B;IACA,IAAIC,YAAYG,aAAa;QAC3B,IAAI,CAAEJ,CAAAA,eAAeK,UAAS,GAAI;YAChC,MAAM,IAAIC,UAAU;QACtB;QACA,IAAIN,IAAIO,MAAM,GAAG,OAAO;YACtB,MAAMC,IAAS,IAAIV;YACnBU,EAAEC,IAAI,GAAG;YACTD,EAAEE,OAAO,GAAG,CAAC,oFAAoF,EAAEV,IAAIO,MAAM,CAAC,wEAAwE,CAAC;YACvLC,EAAEG,IAAI,GAAG;YACT,MAAMH;QACR;QACA,MAAMI,QAAQX,WAAWG,WAAW,CAACJ,IAAIO,MAAM;QAC/CP,IAAIa,GAAG,CAACD;QACR,OAAOZ;IACT;IACA,MAAM,IAAIF,MAAM;AAClB"}
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/emitter/types.ts"],"sourcesContent":["export type EventType = string | symbol;\n\nexport type Handler<E extends keyof T, T = Record<string, unknown>> = (evt: { type: E; payload: T[E] }) => void;\nexport type WildcardHandler<T = Record<string, unknown>> = <E extends keyof T>(evt: { type: E; payload: T[E] }) => void;\n\nexport interface Emitter<Events extends Record<EventType, unknown>> {\n on<Key extends keyof Events>(type: Key, handler: Handler<Key, Events>): void;\n\n on(type: '*', handler: WildcardHandler<Events>): void;\n\n off<Key extends keyof Events>(type: Key, handler?: Handler<Key, Events>): void;\n\n off(type: '*', handler: WildcardHandler<Events>): void;\n\n emit<Key extends keyof Events>(type: Key, event: Events[Key]): void;\n\n emit<Key extends keyof Events>(type: undefined extends Events[Key] ? Key : never): void;\n}\n"],"names":[],"rangeMappings":"","mappings":"AAKA,WAYC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fetch/createFetchWith.ts"],"sourcesContent":["import { MaybePromise } from '../asyncs/MaybePromise';\nimport { getGlobalThis } from '../runtime/getGlobalThis';\nimport { type FetchLike } from './types';\n\nexport function createFetchWith({\n fetch = getGlobalThis().fetch,\n onRequest = (ctx) => ctx.next(ctx.url, ctx.req),\n onResponse = (ctx) => ctx.res,\n}: {\n fetch?: FetchLike;\n onRequest?: (ctx: {\n url: string;\n req: RequestInit;\n next: (url: string, req: RequestInit) => Promise<Response>;\n }) => MaybePromise<Response | void>;\n onResponse?: (ctx: { url: string; req: RequestInit; res: Response }) => MaybePromise<Response>;\n}) {\n return async (urlOrRequest: string | URL | Request, init?: RequestInit & { fetch?: FetchLike }) => {\n const url = String(urlOrRequest);\n let req = init || {};\n const nextFetch = req.fetch || fetch;\n const res =\n (await onRequest({\n url,\n req,\n next: (url, init) => {\n req = init;\n return nextFetch(url, init);\n },\n })) ?? (await nextFetch(url, init));\n return onResponse({ url, req, res });\n };\n}\n"],"names":["getGlobalThis","createFetchWith","fetch","onRequest","ctx","next","url","req","onResponse","res","urlOrRequest","init","String","nextFetch"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,aAAa,QAAQ,2BAA2B;AAGzD,OAAO,SAASC,gBAAgB,EAC9BC,QAAQF,gBAAgBE,KAAK,EAC7BC,YAAY,CAACC,MAAQA,IAAIC,IAAI,CAACD,IAAIE,GAAG,EAAEF,IAAIG,GAAG,CAAC,EAC/CC,aAAa,CAACJ,MAAQA,IAAIK,GAAG,EAS9B;IACC,OAAO,OAAOC,cAAsCC;QAClD,MAAML,MAAMM,OAAOF;QACnB,IAAIH,MAAMI,QAAQ,CAAC;QACnB,MAAME,YAAYN,IAAIL,KAAK,IAAIA;QAC/B,MAAMO,MACJ,AAAC,MAAMN,UAAU;YACfG;YACAC;YACAF,MAAM,CAACC,KAAKK;gBACVJ,MAAMI;gBACN,OAAOE,UAAUP,KAAKK;YACxB;QACF,MAAQ,MAAME,UAAUP,KAAKK;QAC/B,OAAOH,WAAW;YAAEF;YAAKC;YAAKE;QAAI;IACpC;AACF"}
1
+ {"version":3,"sources":["../../src/fetch/createFetchWith.ts"],"sourcesContent":["import type { MaybePromise } from '../asyncs/MaybePromise';\nimport { getGlobalThis } from '../runtime/getGlobalThis';\nimport { type FetchLike } from './types';\n\nexport function createFetchWith({\n fetch = getGlobalThis().fetch,\n onRequest = (ctx) => ctx.next(ctx.url, ctx.req),\n onResponse = (ctx) => ctx.res,\n}: {\n fetch?: FetchLike;\n onRequest?: (ctx: {\n url: string;\n req: RequestInit;\n next: (url: string, req: RequestInit) => Promise<Response>;\n }) => MaybePromise<Response | void>;\n onResponse?: (ctx: { url: string; req: RequestInit; res: Response }) => MaybePromise<Response>;\n}) {\n return async (urlOrRequest: string | URL | Request, init?: RequestInit & { fetch?: FetchLike }) => {\n const url = String(urlOrRequest);\n let req = init || {};\n const nextFetch = req.fetch || fetch;\n const res =\n (await onRequest({\n url,\n req,\n next: (url, init) => {\n req = init;\n return nextFetch(url, init);\n },\n })) ?? (await nextFetch(url, init));\n return onResponse({ url, req, res });\n };\n}\n"],"names":["getGlobalThis","createFetchWith","fetch","onRequest","ctx","next","url","req","onResponse","res","urlOrRequest","init","String","nextFetch"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,aAAa,QAAQ,2BAA2B;AAGzD,OAAO,SAASC,gBAAgB,EAC9BC,QAAQF,gBAAgBE,KAAK,EAC7BC,YAAY,CAACC,MAAQA,IAAIC,IAAI,CAACD,IAAIE,GAAG,EAAEF,IAAIG,GAAG,CAAC,EAC/CC,aAAa,CAACJ,MAAQA,IAAIK,GAAG,EAS9B;IACC,OAAO,OAAOC,cAAsCC;QAClD,MAAML,MAAMM,OAAOF;QACnB,IAAIH,MAAMI,QAAQ,CAAC;QACnB,MAAME,YAAYN,IAAIL,KAAK,IAAIA;QAC/B,MAAMO,MACJ,AAAC,MAAMN,UAAU;YACfG;YACAC;YACAF,MAAM,CAACC,KAAKK;gBACVJ,MAAMI;gBACN,OAAOE,UAAUP,KAAKK;YACxB;QACF,MAAQ,MAAME,UAAUP,KAAKK;QAC/B,OAAOH,WAAW;YAAEF;YAAKC;YAAKE;QAAI;IACpC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fetch/createFetchWithRetry.ts"],"sourcesContent":["import { getGlobalThis } from '../runtime/getGlobalThis';\nimport { FetchLike } from './types';\n\ntype RequestDelayFunction = (attempt: number, error: Error | null, response: Response | null) => number;\ntype RequestRetryOnFunction = (\n attempt: number,\n error: Error | null,\n response: Response | null,\n) => boolean | Promise<boolean>;\n\nexport interface FetchWithRetryOptions {\n fetch?: FetchLike;\n retries?: number;\n retryDelay?: number | RequestDelayFunction;\n retryOn?: number[] | RequestRetryOnFunction;\n}\n\nexport function createFetchWithRetry({\n fetch = getGlobalThis().fetch,\n retries = 3,\n retryDelay = 1000,\n retryOn = [],\n}: FetchWithRetryOptions = {}): FetchLike {\n // https://github.com/jonbern/fetch-retry/blob/master/index.js\n\n return function fetchRetry(input: string | URL | Request, init?: RequestInit) {\n return new Promise(function (resolve, reject) {\n var wrappedFetch = function (attempt: number) {\n // As of node 18, this is no longer needed since node comes with native support for fetch:\n /* istanbul ignore next */\n var _input = typeof Request !== 'undefined' && input instanceof Request ? input.clone() : input;\n fetch(_input, init)\n .then(function (response) {\n if (Array.isArray(retryOn) && retryOn.indexOf(response.status) === -1) {\n resolve(response);\n } else if (typeof retryOn === 'function') {\n try {\n return Promise.resolve(retryOn(attempt, null, response))\n .then(function (retryOnResponse) {\n if (retryOnResponse) {\n retry(attempt, null, response);\n } else {\n resolve(response);\n }\n })\n .catch(reject);\n } catch (error) {\n reject(error);\n }\n } else {\n if (attempt < retries) {\n retry(attempt, null, response);\n } else {\n resolve(response);\n }\n }\n return;\n })\n .catch(function (error) {\n if (typeof retryOn === 'function') {\n try {\n // eslint-disable-next-line no-undef\n Promise.resolve(retryOn(attempt, error, null))\n .then(function (retryOnResponse) {\n if (retryOnResponse) {\n retry(attempt, error, null);\n } else {\n reject(error);\n }\n })\n .catch(function (error) {\n reject(error);\n });\n } catch (error) {\n reject(error);\n }\n } else if (attempt < retries) {\n retry(attempt, error, null);\n } else {\n reject(error);\n }\n });\n };\n\n function retry(attempt: number, error: any, response: Response | null) {\n let delay = typeof retryDelay === 'function' ? retryDelay(attempt, error, response) : retryDelay;\n setTimeout(function () {\n wrappedFetch(++attempt);\n }, delay);\n }\n\n wrappedFetch(0);\n });\n };\n}\n"],"names":["getGlobalThis","createFetchWithRetry","fetch","retries","retryDelay","retryOn","fetchRetry","input","init","Promise","resolve","reject","wrappedFetch","attempt","_input","Request","clone","then","response","Array","isArray","indexOf","status","retryOnResponse","retry","catch","error","delay","setTimeout"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,aAAa,QAAQ,2BAA2B;AAiBzD,OAAO,SAASC,qBAAqB,EACnCC,QAAQF,gBAAgBE,KAAK,EAC7BC,UAAU,CAAC,EACXC,aAAa,IAAI,EACjBC,UAAU,EAAE,EACU,GAAG,CAAC,CAAC;IAC3B,8DAA8D;IAE9D,OAAO,SAASC,WAAWC,KAA6B,EAAEC,IAAkB;QAC1E,OAAO,IAAIC,QAAQ,SAAUC,OAAO,EAAEC,MAAM;YAC1C,IAAIC,eAAe,SAAUC,OAAe;gBAC1C,0FAA0F;gBAC1F,wBAAwB,GACxB,IAAIC,SAAS,OAAOC,YAAY,eAAeR,iBAAiBQ,UAAUR,MAAMS,KAAK,KAAKT;gBAC1FL,MAAMY,QAAQN,MACXS,IAAI,CAAC,SAAUC,QAAQ;oBACtB,IAAIC,MAAMC,OAAO,CAACf,YAAYA,QAAQgB,OAAO,CAACH,SAASI,MAAM,MAAM,CAAC,GAAG;wBACrEZ,QAAQQ;oBACV,OAAO,IAAI,OAAOb,YAAY,YAAY;wBACxC,IAAI;4BACF,OAAOI,QAAQC,OAAO,CAACL,QAAQQ,SAAS,MAAMK,WAC3CD,IAAI,CAAC,SAAUM,eAAe;gCAC7B,IAAIA,iBAAiB;oCACnBC,MAAMX,SAAS,MAAMK;gCACvB,OAAO;oCACLR,QAAQQ;gCACV;4BACF,GACCO,KAAK,CAACd;wBACX,EAAE,OAAOe,OAAO;4BACdf,OAAOe;wBACT;oBACF,OAAO;wBACL,IAAIb,UAAUV,SAAS;4BACrBqB,MAAMX,SAAS,MAAMK;wBACvB,OAAO;4BACLR,QAAQQ;wBACV;oBACF;oBACA;gBACF,GACCO,KAAK,CAAC,SAAUC,KAAK;oBACpB,IAAI,OAAOrB,YAAY,YAAY;wBACjC,IAAI;4BACF,oCAAoC;4BACpCI,QAAQC,OAAO,CAACL,QAAQQ,SAASa,OAAO,OACrCT,IAAI,CAAC,SAAUM,eAAe;gCAC7B,IAAIA,iBAAiB;oCACnBC,MAAMX,SAASa,OAAO;gCACxB,OAAO;oCACLf,OAAOe;gCACT;4BACF,GACCD,KAAK,CAAC,SAAUC,KAAK;gCACpBf,OAAOe;4BACT;wBACJ,EAAE,OAAOA,OAAO;4BACdf,OAAOe;wBACT;oBACF,OAAO,IAAIb,UAAUV,SAAS;wBAC5BqB,MAAMX,SAASa,OAAO;oBACxB,OAAO;wBACLf,OAAOe;oBACT;gBACF;YACJ;YAEA,SAASF,MAAMX,OAAe,EAAEa,KAAU,EAAER,QAAyB;gBACnE,IAAIS,QAAQ,OAAOvB,eAAe,aAAaA,WAAWS,SAASa,OAAOR,YAAYd;gBACtFwB,WAAW;oBACThB,aAAa,EAAEC;gBACjB,GAAGc;YACL;YAEAf,aAAa;QACf;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/fetch/createFetchWithRetry.ts"],"sourcesContent":["import { getGlobalThis } from '../runtime/getGlobalThis';\nimport type { FetchLike } from './types';\n\ntype RequestDelayFunction = (attempt: number, error: Error | null, response: Response | null) => number;\ntype RequestRetryOnFunction = (\n attempt: number,\n error: Error | null,\n response: Response | null,\n) => boolean | Promise<boolean>;\n\nexport interface FetchWithRetryOptions {\n fetch?: FetchLike;\n retries?: number;\n retryDelay?: number | RequestDelayFunction;\n retryOn?: number[] | RequestRetryOnFunction;\n}\n\nexport function createFetchWithRetry({\n fetch = getGlobalThis().fetch,\n retries = 3,\n retryDelay = 1000,\n retryOn = [],\n}: FetchWithRetryOptions = {}): FetchLike {\n // https://github.com/jonbern/fetch-retry/blob/master/index.js\n\n return function fetchRetry(input: string | URL | Request, init?: RequestInit) {\n return new Promise(function (resolve, reject) {\n var wrappedFetch = function (attempt: number) {\n // As of node 18, this is no longer needed since node comes with native support for fetch:\n /* istanbul ignore next */\n var _input = typeof Request !== 'undefined' && input instanceof Request ? input.clone() : input;\n fetch(_input, init)\n .then(function (response) {\n if (Array.isArray(retryOn) && retryOn.indexOf(response.status) === -1) {\n resolve(response);\n } else if (typeof retryOn === 'function') {\n try {\n return Promise.resolve(retryOn(attempt, null, response))\n .then(function (retryOnResponse) {\n if (retryOnResponse) {\n retry(attempt, null, response);\n } else {\n resolve(response);\n }\n })\n .catch(reject);\n } catch (error) {\n reject(error);\n }\n } else {\n if (attempt < retries) {\n retry(attempt, null, response);\n } else {\n resolve(response);\n }\n }\n return;\n })\n .catch(function (error) {\n if (typeof retryOn === 'function') {\n try {\n // eslint-disable-next-line no-undef\n Promise.resolve(retryOn(attempt, error, null))\n .then(function (retryOnResponse) {\n if (retryOnResponse) {\n retry(attempt, error, null);\n } else {\n reject(error);\n }\n })\n .catch(function (error) {\n reject(error);\n });\n } catch (error) {\n reject(error);\n }\n } else if (attempt < retries) {\n retry(attempt, error, null);\n } else {\n reject(error);\n }\n });\n };\n\n function retry(attempt: number, error: any, response: Response | null) {\n let delay = typeof retryDelay === 'function' ? retryDelay(attempt, error, response) : retryDelay;\n setTimeout(function () {\n wrappedFetch(++attempt);\n }, delay);\n }\n\n wrappedFetch(0);\n });\n };\n}\n"],"names":["getGlobalThis","createFetchWithRetry","fetch","retries","retryDelay","retryOn","fetchRetry","input","init","Promise","resolve","reject","wrappedFetch","attempt","_input","Request","clone","then","response","Array","isArray","indexOf","status","retryOnResponse","retry","catch","error","delay","setTimeout"],"rangeMappings":";;;;;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OAAO,OACrCT,IAAI,CAAC,SAAUM,eAAe;gCAC7B,IAAIA,iBAAiB;oCACnBC,MAAMX,SAASa,OAAO;gCACxB,OAAO;oCACLf,OAAOe;gCACT;4BACF,GACCD,KAAK,CAAC,SAAUC,KAAK;gCACpBf,OAAOe;4BACT;wBACJ,EAAE,OAAOA,OAAO;4BACdf,OAAOe;wBACT;oBACF,OAAO,IAAIb,UAAUV,SAAS;wBAC5BqB,MAAMX,SAASa,OAAO;oBACxB,OAAO;wBACLf,OAAOe;oBACT;gBACF;YACJ;YAEA,SAASF,MAAMX,OAAe,EAAEa,KAAU,EAAER,QAAyB;gBACnE,IAAIS,QAAQ,OAAOvB,eAAe,aAAaA,WAAWS,SAASa,OAAOR,YAAYd;gBACtFwB,WAAW;oBACThB,aAAa,EAAEC;gBACjB,GAAGc;YACL;YAEAf,aAAa;QACf;IACF;AACF"}
@@ -0,0 +1,4 @@
1
+ // from hono
2
+ export { };
3
+
4
+ //# sourceMappingURL=http.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/fetch/http.types.ts"],"sourcesContent":["// from hono\n\nexport type InfoStatusCode = 100 | 101 | 102 | 103;\nexport type SuccessStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;\nexport type DeprecatedStatusCode = 305 | 306;\nexport type RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | DeprecatedStatusCode | 307 | 308;\nexport type ClientErrorStatusCode =\n | 400\n | 401\n | 402\n | 403\n | 404\n | 405\n | 406\n | 407\n | 408\n | 409\n | 410\n | 411\n | 412\n | 413\n | 414\n | 415\n | 416\n | 417\n | 418\n | 421\n | 422\n | 423\n | 424\n | 425\n | 426\n | 428\n | 429\n | 431\n | 451;\nexport type ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;\n\nexport type UnofficialStatusCode = -1;\nexport type StatusCode =\n | InfoStatusCode\n | SuccessStatusCode\n | RedirectStatusCode\n | ClientErrorStatusCode\n | ServerErrorStatusCode\n | UnofficialStatusCode;\n"],"names":[],"rangeMappings":";","mappings":"AAAA,YAAY;AAuCZ,WAMyB"}
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { Promises } from './asyncs/Promises.js';
1
2
  // arrays
2
3
  export { firstOfMaybeArray, lastOfMaybeArray, arrayOfMaybeArray, objectOfMaybeArray } from './arrays/MaybeArray.js';
3
4
  export { arrayFromAsync } from './arrays/arrayFromAsync.js';
@@ -15,10 +16,10 @@ export { createAsyncIterator } from './asyncs/createAsyncIterator.js';
15
16
  export { firstOfAsyncIterator } from './asyncs/firstOfAsyncIterator.js';
16
17
  export { nextOfAsyncIterator } from './asyncs/nextOfAsyncIterator.js';
17
18
  export { isIterator } from './asyncs/isIterator.js';
18
- export { sleep } from './asyncs/sleep.js';
19
+ export { Promises } from './asyncs/Promises.js';
20
+ export const sleep = Promises.sleep;
21
+ export const isPromise = Promises.isPromise;
19
22
  export { timeout, TimeoutError } from './asyncs/timeout.js';
20
- export { isPromise } from './asyncs/isPromise.js';
21
- // export * from './async/promiseOfCallback';
22
23
  // langs
23
24
  export { shallowEqual } from './langs/shallowEqual.js';
24
25
  export { deepEqual } from './langs/deepEqual.js';
@@ -33,6 +34,8 @@ export { parseBoolean } from './langs/parseBoolean.js';
33
34
  export { maybeFunction } from './langs/MaybeFunction.js';
34
35
  export { memoize } from './langs/memoize.js';
35
36
  export { mixin } from './langs/mixin.js';
37
+ export { getObjectId } from './langs/getObjectId.js';
38
+ export { getGlobalStates, setGlobalStates } from './langs/getGlobalStates.js';
36
39
  export { AsyncCloser } from './runtime/AsyncCloser.js';
37
40
  export { Closer } from './runtime/Closer.js';
38
41
  export { isUUID } from './validations/isUUID.js';
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// arrays\nexport {\n firstOfMaybeArray,\n lastOfMaybeArray,\n arrayOfMaybeArray,\n objectOfMaybeArray,\n type MaybeArray,\n} from './arrays/MaybeArray';\nexport { arrayFromAsync } from './arrays/arrayFromAsync';\n\n// object\nexport { get } from './objects/get';\nexport { set } from './objects/set';\nexport { parseObjectPath } from './objects/parseObjectPath';\nexport { computeIfAbsent } from './objects/computeIfAbsent';\nexport { merge, type MergeOptions } from './objects/merge';\n\n// async\nexport { createLazyPromise, type LazyPromise } from './asyncs/createLazyPromise';\nexport { setAsyncInterval, clearAsyncInterval } from './asyncs/AsyncInterval';\nexport { type MaybePromise } from './asyncs/MaybePromise';\n// async - iterator\nexport { createAsyncIterator } from './asyncs/createAsyncIterator';\nexport { firstOfAsyncIterator } from './asyncs/firstOfAsyncIterator';\nexport { nextOfAsyncIterator } from './asyncs/nextOfAsyncIterator';\nexport { isIterator } from './asyncs/isIterator';\n\nexport { sleep } from './asyncs/sleep';\nexport { timeout, TimeoutError } from './asyncs/timeout';\nexport { isPromise } from './asyncs/isPromise';\n// export * from './async/promiseOfCallback';\n\n// langs\nexport { shallowEqual } from './langs/shallowEqual';\nexport { deepEqual } from './langs/deepEqual';\nexport { deepFreeze } from './langs/deepFreeze';\nexport { classOf } from './langs/classOf';\nexport { shallowClone } from './langs/shallowClone';\nexport { isClass } from './langs/isClass';\nexport { isDefined } from './langs/isDefined';\nexport { isEmptyObject } from './langs/isEmptyObject';\nexport { isPlainObject } from './langs/isPlainObject';\nexport { parseBoolean } from './langs/parseBoolean';\nexport { maybeFunction, type MaybeFunction } from './langs/MaybeFunction';\nexport { memoize } from './langs/memoize';\nexport { mixin } from './langs/mixin';\nexport type { MixinFunction, MixinInstance, MixinReturnValue } from './langs/mixin';\n\nexport { AsyncCloser } from './runtime/AsyncCloser';\nexport { Closer } from './runtime/Closer';\n\nexport { isUUID } from './validations/isUUID';\nexport { parseTimestamp } from './validations/parseTimestamp';\n\n// modules\nexport { parseModuleId, type ParsedModuleId } from './modules/parseModuleId';\nexport { isModule, type Module } from './modules/isModule';\n\n// logging\nexport { type Logger, type LogLevel } from './logging/Logger';\nexport { createLogger } from './logging/createLogger';\nexport { createNoopLogger } from './logging/createNoopLogger';\nexport { createChildLogger } from './logging/createChildLogger';\n\n// strings\nexport { pascalCase, camelCase } from './strings/camelCase';\nexport { renderTemplate } from './strings/renderTemplate';\nexport { formatBytes } from './strings/formatBytes';\n\n// i18n\nexport { createTranslate } from './i18n/createTranslate';\n\n// io\nexport { isBuffer } from './io/isBuffer';\nexport { isTransferable } from './io/isTransferable';\nexport { ArrayBuffers } from './io/ArrayBuffers';\nexport { ByteBuffer } from './io/ByteBuffer';\nexport { fromHexDump, toHexDump } from './io/dump';\nexport { Buffer } from './io/Buffer';\nexport { parseDataUri, type ParsedDataUri } from './io/parseDataUri';\nexport type { AbstractEncoding } from './io/AbstractEncoding';\n\n// browser\nexport { copy } from './browsers/copy';\nexport { download } from './browsers/download';\nexport { loadScripts, loadStyles } from './browsers/loaders';\nexport { getFileFromDataTransfer } from './browsers/getFileFromDataTransfer';\n\n// polyfills\nexport { getGlobalThis } from './runtime/getGlobalThis';\nexport { structuredClone } from './runtime/structuredClone';\n\n// crypto\nexport { randomUUID } from './crypto/randomUUID';\nexport { getRandomValues } from './crypto/getRandomValues';\nexport { sha1, sha256, sha384, sha512, hmac, type DigestOptions } from './crypto/hashing';\nexport { md5 } from './crypto/md5';\nexport { hex } from './crypto/base';\nexport { isULID, createULID, ulid, parseULID } from './crypto/ulid';\nexport { PEM } from './crypto/pem/pem';\n\n// math\nexport { createRandom } from './maths/random';\nexport { clamp } from './maths/clamp';\n\n// network\nexport {\n type FetchLike,\n createFetchWith,\n createFetchWithLogging,\n dumpResponse,\n dumpRequest,\n createFetchWithRetry,\n type FetchWithRetryOptions,\n} from './fetch';\n\n// bundled\nexport { default as ms } from './libs/ms';\n\n// error\nexport { Errors, DetailError, type ErrorDetail, type ErrorDetailInit } from './errors/Errors';\n// http\nexport { getHttpStatusText, isRetryableHttpStatus } from './fetch/HttpStatus';\n\nexport type * from './types';\n"],"names":["firstOfMaybeArray","lastOfMaybeArray","arrayOfMaybeArray","objectOfMaybeArray","arrayFromAsync","get","set","parseObjectPath","computeIfAbsent","merge","createLazyPromise","setAsyncInterval","clearAsyncInterval","createAsyncIterator","firstOfAsyncIterator","nextOfAsyncIterator","isIterator","sleep","timeout","TimeoutError","isPromise","shallowEqual","deepEqual","deepFreeze","classOf","shallowClone","isClass","isDefined","isEmptyObject","isPlainObject","parseBoolean","maybeFunction","memoize","mixin","AsyncCloser","Closer","isUUID","parseTimestamp","parseModuleId","isModule","createLogger","createNoopLogger","createChildLogger","pascalCase","camelCase","renderTemplate","formatBytes","createTranslate","isBuffer","isTransferable","ArrayBuffers","ByteBuffer","fromHexDump","toHexDump","Buffer","parseDataUri","copy","download","loadScripts","loadStyles","getFileFromDataTransfer","getGlobalThis","structuredClone","randomUUID","getRandomValues","sha1","sha256","sha384","sha512","hmac","md5","hex","isULID","createULID","ulid","parseULID","PEM","createRandom","clamp","createFetchWith","createFetchWithLogging","dumpResponse","dumpRequest","createFetchWithRetry","default","ms","Errors","DetailError","getHttpStatusText","isRetryableHttpStatus"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAAS;AACT,SACEA,iBAAiB,EACjBC,gBAAgB,EAChBC,iBAAiB,EACjBC,kBAAkB,QAEb,sBAAsB;AAC7B,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,SAAS;AACT,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,KAAK,QAA2B,kBAAkB;AAE3D,QAAQ;AACR,SAASC,iBAAiB,QAA0B,6BAA6B;AACjF,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,yBAAyB;AAE9E,mBAAmB;AACnB,SAASC,mBAAmB,QA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ncs/Promises';\n\n// arrays\nexport {\n firstOfMaybeArray,\n lastOfMaybeArray,\n arrayOfMaybeArray,\n objectOfMaybeArray,\n type MaybeArray,\n} from './arrays/MaybeArray';\nexport { arrayFromAsync } from './arrays/arrayFromAsync';\n\n// object\nexport { get } from './objects/get';\nexport { set } from './objects/set';\nexport { parseObjectPath } from './objects/parseObjectPath';\nexport { computeIfAbsent } from './objects/computeIfAbsent';\nexport { merge, type MergeOptions } from './objects/merge';\n\n// async\nexport { createLazyPromise, type LazyPromise } from './asyncs/createLazyPromise';\nexport { setAsyncInterval, clearAsyncInterval } from './asyncs/AsyncInterval';\nexport { type MaybePromise } from './asyncs/MaybePromise';\n// async - iterator\nexport { createAsyncIterator } from './asyncs/createAsyncIterator';\nexport { firstOfAsyncIterator } from './asyncs/firstOfAsyncIterator';\nexport { nextOfAsyncIterator } from './asyncs/nextOfAsyncIterator';\nexport { isIterator } from './asyncs/isIterator';\n\nexport { Promises } from './asyncs/Promises';\nexport const sleep = Promises.sleep;\nexport const isPromise = Promises.isPromise;\nexport { timeout, TimeoutError } from './asyncs/timeout';\n\n// langs\nexport { shallowEqual } from './langs/shallowEqual';\nexport { deepEqual } from './langs/deepEqual';\nexport { deepFreeze } from './langs/deepFreeze';\nexport { classOf } from './langs/classOf';\nexport { shallowClone } from './langs/shallowClone';\nexport { isClass } from './langs/isClass';\nexport { isDefined } from './langs/isDefined';\nexport { isEmptyObject } from './langs/isEmptyObject';\nexport { isPlainObject } from './langs/isPlainObject';\nexport { parseBoolean } from './langs/parseBoolean';\nexport { maybeFunction, type MaybeFunction } from './langs/MaybeFunction';\nexport { memoize } from './langs/memoize';\nexport { mixin } from './langs/mixin';\nexport type { MixinFunction, MixinInstance, MixinReturnValue } from './langs/mixin';\nexport { getObjectId } from './langs/getObjectId';\nexport { getGlobalStates, setGlobalStates } from './langs/getGlobalStates';\n\nexport { AsyncCloser } from './runtime/AsyncCloser';\nexport { Closer } from './runtime/Closer';\n\nexport { isUUID } from './validations/isUUID';\nexport { parseTimestamp } from './validations/parseTimestamp';\n\n// modules\nexport { parseModuleId, type ParsedModuleId } from './modules/parseModuleId';\nexport { isModule, type Module } from './modules/isModule';\n\n// logging\nexport { type Logger, type LogLevel } from './logging/Logger';\nexport { createLogger } from './logging/createLogger';\nexport { createNoopLogger } from './logging/createNoopLogger';\nexport { createChildLogger } from './logging/createChildLogger';\n\n// strings\nexport { pascalCase, camelCase } from './strings/camelCase';\nexport { renderTemplate } from './strings/renderTemplate';\nexport { formatBytes } from './strings/formatBytes';\n\n// i18n\nexport { createTranslate } from './i18n/createTranslate';\n\n// io\nexport { isBuffer } from './io/isBuffer';\nexport { isTransferable } from './io/isTransferable';\nexport { ArrayBuffers } from './io/ArrayBuffers';\nexport { ByteBuffer } from './io/ByteBuffer';\nexport { fromHexDump, toHexDump } from './io/dump';\nexport { Buffer } from './io/Buffer';\nexport { parseDataUri, type ParsedDataUri } from './io/parseDataUri';\nexport type { AbstractEncoding } from './io/AbstractEncoding';\n\n// browser\nexport { copy } from './browsers/copy';\nexport { download } from './browsers/download';\nexport { loadScripts, loadStyles } from './browsers/loaders';\nexport { getFileFromDataTransfer } from './browsers/getFileFromDataTransfer';\n\n// polyfills\nexport { getGlobalThis } from './runtime/getGlobalThis';\nexport { structuredClone } from './runtime/structuredClone';\n\n// crypto\nexport { randomUUID } from './crypto/randomUUID';\nexport { getRandomValues } from './crypto/getRandomValues';\nexport { sha1, sha256, sha384, sha512, hmac, type DigestOptions } from './crypto/hashing';\nexport { md5 } from './crypto/md5';\nexport { hex } from './crypto/base';\nexport { isULID, createULID, ulid, parseULID } from './crypto/ulid';\nexport { PEM } from './crypto/pem/pem';\n\n// math\nexport { createRandom } from './maths/random';\nexport { clamp } from './maths/clamp';\n\n// network\nexport {\n type FetchLike,\n createFetchWith,\n createFetchWithLogging,\n dumpResponse,\n dumpRequest,\n createFetchWithRetry,\n type FetchWithRetryOptions,\n} from './fetch';\n\n// bundled\nexport { default as ms } from './libs/ms';\n\n// error\nexport { Errors, DetailError, type ErrorDetail, type ErrorDetailInit } from './errors/Errors';\n// http\nexport { getHttpStatusText, isRetryableHttpStatus } from './fetch/HttpStatus';\n\nexport type * from './types';\n"],"names":["Promises","firstOfMaybeArray","lastOfMaybeArray","arrayOfMaybeArray","objectOfMaybeArray","arrayFromAsync","get","set","parseObjectPath","computeIfAbsent","merge","createLazyPromise","setAsyncInterval","clearAsyncInterval","createAsyncIterator","firstOfAsyncIterator","nextOfAsyncIterator","isIterator","sleep","isPromise","timeout","TimeoutError","shallowEqual","deepEqual","deepFreeze","classOf","shallowClone","isClass","isDefined","isEmptyObject","isPlainObject","parseBoolean","maybeFunction","memoize","mixin","getObjectId","getGlobalStates","setGlobalStates","AsyncCloser","Closer","isUUID","parseTimestamp","parseModuleId","isModule","createLogger","createNoopLogger","createChildLogger","pascalCase","camelCase","renderTemplate","formatBytes","createTranslate","isBuffer","isTransferable","ArrayBuffers","ByteBuffer","fromHexDump","toHexDump","Buffer","parseDataUri","copy","download","loadScripts","loadStyles","getFileFromDataTransfer","getGlobalThis","structuredClone","randomUUID","getRandomValues","sha1","sha256","sha384","sha512","hmac","md5","hex","isULID","createULID","ulid","parseULID","PEM","createRandom","clamp","createFetchWith","createFetchWithLogging","dumpResponse","dumpRequest","createFetchWithRetry","default","ms","Errors","DetailError","getHttpStatusText","isRetryableHttpStatus"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,QAAQ,QAAQ,oBAAoB;AAE7C,SAAS;AACT,SACEC,iBAAiB,EACjBC,gBAAgB,EAChBC,iBAAiB,EACjBC,kBAAkB,QAEb,sBAAsB;AAC7B,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,SAAS;AACT,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,eAAe,QAAQ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AASC,KAAK,QAAQ,gBAAgB;AAEtC,UAAU;AACV,SAEEC,eAAe,EACfC,sBAAsB,EACtBC,YAAY,EACZC,WAAW,EACXC,oBAAoB,QAEf,UAAU;AAEjB,UAAU;AACV,SAASC,WAAWC,EAAE,QAAQ,YAAY;AAE1C,QAAQ;AACR,SAASC,MAAM,EAAEC,WAAW,QAAgD,kBAAkB;AAC9F,OAAO;AACP,SAASC,iBAAiB,EAAEC,qBAAqB,QAAQ,qBAAqB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/io/ArrayBuffers.ts"],"sourcesContent":["import { classOf } from '../langs/classOf';\nimport { getGlobalThis } from '../runtime/getGlobalThis';\nimport { decodeBase64ToArrayBuffer, encodeArrayBufferToBase64 } from './base64';\nimport { isBuffer } from './isBuffer';\n\n/**\n * Various utils to work with {@link ArrayBuffer}\n *\n * @see https://github.com/tc39/proposal-arraybuffer-base64\n * @see https://github.com/tc39/proposal-resizablearraybuffer\n */\nexport interface ArrayBuffers {\n /**\n * isArrayBuffer check if the given value is an {@link ArrayBuffer}\n */\n isArrayBuffer(v: any): v is ArrayBuffer;\n\n /**\n * slice the given view with the given offset and length, will handle the {@link Buffer} as well\n *\n * @see {@link https://nodejs.org/api/buffer.html#bufslicestart-end Buffer.slice}\n */\n slice<T extends ArrayBufferView>(o: T, start?: number, end?: number): T;\n\n /**\n * asView convert the given value to given {@link TypedArray} view\n *\n * TypedArray can be {@link Buffer}, will avoid copy\n */\n asView<C extends ArrayBufferViewConstructor<unknown>>(\n TypedArray: C,\n v: BufferSource,\n byteOffset?: number,\n byteLength?: number,\n ): InstanceType<C>;\n\n /**\n * toString convert the given {@link BufferSource} to string\n */\n toString(v: BufferSource | string, encoding?: ToStringEncoding): string;\n\n /**\n * Returns true if encoding is the name of a supported character encoding, or false otherwise.\n */\n isEncoding(v?: string): v is ToStringEncoding;\n\n toJSON<T = any>(v: BufferSource | string, reviver?: (this: any, key: string, value: any) => any): T;\n\n /**\n * from convert the given value to {@link ArrayBuffer}\n */\n from(v: string | BufferSource, encoding?: ToStringEncoding): ArrayBuffer;\n\n from<C extends ArrayBufferViewConstructor<unknown>>(\n v: string | BufferSource,\n encoding: ToStringEncoding,\n TypedArray: C,\n ): C;\n\n /**\n * concat the given {@link BufferSource} to a new {@link ArrayBuffer}\n */\n concat(buffers: Array<BufferSource>, result?: ArrayBuffer, offset?: number): ArrayBuffer;\n\n fromBase64(v: string): Uint8Array;\n\n fromHex(v: string): Uint8Array;\n\n toBase64(v: BufferSource): string;\n\n toHex(v: BufferSource): string;\n\n resize(v: ArrayBuffer, newByteLength: number): ArrayBuffer;\n\n // truncate(v: ArrayBufferLike, len?: number): ArrayBufferLike;\n}\n\ntype ToStringEncoding =\n | 'ascii'\n | 'utf16le'\n // | 'utf-16le'\n | 'ucs2'\n | 'ucs-2'\n | 'base64'\n | 'base64url'\n | 'latin1'\n | 'binary'\n | 'utf8'\n | 'utf-8'\n | 'hex';\n\nexport class ArrayBuffers {\n static #nativeBufferAllowed: boolean = true;\n static #isBufferAvailable: undefined | boolean;\n\n static isNativeBufferAvailable() {\n // eslint-disable-next-line no-return-assign\n return (this.#isBufferAvailable ??= !(getGlobalThis().Buffer as any)?.isPollyfill?.());\n }\n\n static isNativeBufferAllowed() {\n return this.#nativeBufferAllowed && this.#isBufferAvailable;\n }\n\n static setNativeBufferAllowed(v: boolean) {\n this.#nativeBufferAllowed = v;\n }\n\n static isArrayBuffer = (v: any): v is ArrayBuffer => {\n return v instanceof ArrayBuffer;\n };\n\n static toArrayBuffer(v: BufferSource): ArrayBuffer {\n return v instanceof ArrayBuffer ? v : (v.buffer as ArrayBuffer);\n }\n\n static toUint8Array(v: BufferSource) {\n return ArrayBuffers.asView(Uint8Array, v);\n }\n\n static toBase64 = (v: BufferSource) => {\n if ('toBase64' in Uint8Array.prototype) {\n return this.toUint8Array(v).toBase64();\n }\n\n if (ArrayBuffers.isNativeBufferAllowed()) {\n return Buffer.from(ArrayBuffers.asView(Uint8Array, v)).toString('base64');\n }\n\n return encodeArrayBufferToBase64(this.toArrayBuffer(v));\n };\n\n static toHex = (v: BufferSource) => {\n if ('toHex' in Uint8Array.prototype) {\n return this.toUint8Array(v).toHex();\n }\n if (ArrayBuffers.isNativeBufferAllowed()) {\n return Buffer.from(ArrayBuffers.asView(Uint8Array, v)).toString('hex');\n }\n return ArrayBuffers.toString(v, 'hex');\n };\n\n static fromBase64 = (v: string) => {\n if ('fromBase64' in Uint8Array) {\n return Uint8Array.fromBase64(v);\n }\n if (ArrayBuffers.isNativeBufferAllowed()) {\n return Buffer.from(v, 'base64');\n }\n return this.toUint8Array(decodeBase64ToArrayBuffer(v));\n };\n\n static fromHex = (v: string) => {\n if ('fromHex' in Uint8Array) {\n return Uint8Array.fromHex(v);\n }\n return this.toUint8Array(ArrayBuffers.from(v, 'hex'));\n };\n\n static resize = (v: ArrayBufferLike, newByteLength?: number, maxByteLength?: number): ArrayBuffer => {\n if (newByteLength === undefined || newByteLength === null) {\n return v;\n }\n\n // Chrome 111, Nodejs 20\n if ('resize' in v && typeof v.resize === 'function') {\n if ('resizable' in v && v.resizable) {\n if ('maxByteLength' in v && typeof v.maxByteLength === 'number' && v.maxByteLength >= newByteLength) {\n v.resize(newByteLength);\n return v;\n }\n }\n }\n\n const old = v;\n const newBuf = new ArrayBuffer(newByteLength, { maxByteLength: maxByteLength });\n const oldView = new Uint8Array(old);\n const newView = new Uint8Array(newBuf);\n newView.set(oldView);\n return newBuf;\n };\n\n static slice = (o: TypedArray, start?: number, end?: number) => {\n // NodeJS Buffer slice is not the same as UInt8Array slice\n // https://nodejs.org/api/buffer.html#bufslicestart-end\n if (isBuffer(o)) {\n return Uint8Array.prototype.slice.call(o, start, end);\n }\n return o.slice(start, end);\n };\n\n static asView = <C extends ArrayBufferViewConstructor<unknown>, I extends InstanceType<C>>(\n TypedArray: C,\n v: BufferSource,\n byteOffset?: number,\n byteLength?: number,\n ): I => {\n if (v instanceof TypedArray && (byteOffset ?? 0) === 0 && byteLength === undefined) {\n return v as I;\n }\n if (ArrayBuffer.isView(v) || isBuffer(v)) {\n if (ArrayBuffers.isNativeBufferAllowed() && (TypedArray as any) === Buffer) {\n // new Buffer() is deprecated\n return Buffer.from(v.buffer, byteOffset, byteLength) as I;\n }\n return new TypedArray(v.buffer, v.byteOffset + (byteOffset ?? 0), byteLength ?? v.byteLength) as I;\n }\n return new TypedArray(v, byteOffset, byteLength) as I;\n };\n\n static toString = (buf: BufferSource | string, encoding: ToStringEncoding = 'utf8') => {\n // 'ascii' 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex'\n if (typeof buf === 'string') {\n switch (encoding) {\n case 'base64':\n return btoa(buf);\n case 'utf-8':\n case 'utf8':\n return buf;\n default:\n throw new Error(`[ArrayBuffers.toString] Unsupported encoding for string: ${encoding}`);\n }\n }\n if (ArrayBuffers.isNativeBufferAllowed()) {\n return Buffer.from(ArrayBuffers.asView(Uint8Array, buf)).toString(encoding);\n }\n // reference\n // https://github.com/feross/buffer/blob/master/index.js\n switch (encoding) {\n case 'hex': {\n const view: Uint8Array = ArrayBuffers.asView(Uint8Array, buf);\n return [...view].map((b) => hexLookupTable[b]).join('');\n }\n case 'base64': {\n return encodeArrayBufferToBase64(ArrayBuffers.asView(Uint8Array, buf));\n }\n case 'utf8':\n // falls through\n case 'utf-8':\n return new TextDecoder().decode(buf as any);\n case 'ascii': {\n const view: Uint8Array = ArrayBuffers.asView(Uint8Array, buf);\n return String.fromCharCode(...view.map((v) => v & 0x7f));\n }\n case 'latin1':\n // falls through\n case 'binary': {\n const view: Uint8Array = ArrayBuffers.asView(Uint8Array, buf);\n return String.fromCharCode(...view);\n }\n case 'ucs2':\n // falls through\n case 'ucs-2':\n // case 'utf-16le':\n // falls through\n case 'utf16le': {\n const view: Uint8Array = ArrayBuffers.asView(Uint8Array, buf);\n let res = '';\n // If length is odd, the last 8 bits must be ignored (same as node.js)\n for (let i = 0; i < view.length - 1; i += 2) {\n res += String.fromCharCode(view[i] + view[i + 1] * 256);\n }\n return res;\n }\n default:\n throw new Error(`[ArrayBuffers.toString] Unknown encoding: ${encoding}`);\n }\n };\n\n static toJSON = (v: BufferSource | string, reviver?: (this: any, key: string, value: any) => any) => {\n return JSON.parse(ArrayBuffers.toString(v), reviver);\n };\n\n static alloc = (size: number, fill?: string | number, encoding?: ToStringEncoding) => {\n if (fill !== undefined) {\n if (typeof fill === 'number') {\n return new Uint8Array(size).fill(fill);\n }\n // as cast\n // https://stackoverflow.com/questions/73994091\n return ArrayBuffers.asView(Uint8Array, ArrayBuffers.from(fill, encoding)).slice(0, size);\n }\n return new ArrayBuffer(size);\n };\n\n static from = (\n v: string | BufferSource | ArrayLike<number> | Iterable<number>,\n encoding: ToStringEncoding = 'utf8',\n view?: any,\n ): any => {\n if (view) {\n return this.asView(view, this.from(v, encoding));\n }\n if (!v) {\n return new ArrayBuffer(0);\n }\n if (typeof v === 'string') {\n if (ArrayBuffers.isNativeBufferAllowed()) {\n return Buffer.from(v, encoding);\n }\n\n switch (encoding) {\n case 'utf-8':\n // falls through\n case 'utf8':\n return new TextEncoder().encode(v).buffer;\n case 'base64':\n // replaceAll need higher version of nodejs\n return decodeBase64ToArrayBuffer(v.replace(/[^0-9a-zA-Z=+/_]/g, ''));\n case 'hex':\n return new Uint8Array(v.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16))).buffer;\n default:\n throw new Error(`[ArrayBuffers.from] Unknown encoding: ${encoding}`);\n }\n }\n if (v instanceof ArrayBuffer) {\n return v;\n }\n // lost length\n if (ArrayBuffer.isView(v) || isBuffer(v)) {\n if (v.byteOffset !== 0) {\n // return v.buffer.slice(v.byteOffset, v.byteOffset + v.byteLength)\n throw new Error('ArrayBuffers.from do not support view with offset');\n }\n return v.buffer;\n }\n if (Array.isArray(v)) {\n return new Uint8Array(v);\n }\n const type = classOf(v);\n throw new TypeError(`ArrayBuffers.from unsupported type ${type}`);\n };\n\n static isEncoding = (encoding?: string) => {\n switch (String(encoding).toLowerCase()) {\n case 'hex':\n case 'utf8':\n case 'utf-8':\n case 'ascii':\n case 'latin1':\n case 'binary':\n case 'base64':\n case 'ucs2':\n case 'ucs-2':\n case 'utf16le':\n // case 'utf-16le':\n return true;\n default:\n return false;\n }\n };\n\n // static truncate = (a: ArrayBufferLike, len?: number) => {\n // if (len === 0) {\n // return new ArrayBuffer(0);\n // }\n // if (!len) {\n // return a;\n // }\n // if (a.byteLength > len) {\n // return a.slice(0, len);\n // } else if (a.byteLength < len) {\n // let b = new Uint8Array(len);\n // b.set(new Uint8Array(a));\n // return b;\n // }\n // return a;\n // };\n\n static concat = (buffers: Array<BufferSource>, result?: ArrayBuffer, offset = 0) => {\n // https://stackoverflow.com/questions/10786128/appending-arraybuffers\n\n const length = buffers.reduce((a, b) => a + b.byteLength, 0);\n const r = result ? new Uint8Array(result) : new Uint8Array(length);\n for (const buffer of buffers) {\n if (!buffer?.byteLength) continue;\n let n: Uint8Array;\n if (buffer instanceof ArrayBuffer) {\n n = new Uint8Array(buffer);\n } else if (ArrayBuffer.isView(buffer)) {\n n = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n } else {\n throw new Error(`ArrayBuffers.concat unsupported type ${classOf(buffer)}`);\n }\n r.set(n, offset);\n offset += buffer.byteLength;\n }\n return r.buffer;\n };\n}\n\nexport type TypedArray =\n | Uint8Array\n | Uint8ClampedArray\n | Uint16Array\n | Uint32Array\n | Int8Array\n | Int16Array\n | Int32Array\n | BigUint64Array\n | BigInt64Array\n | Float32Array\n | Float64Array;\n\ntype ArrayBufferViewConstructor<T> = new (buffer: ArrayBufferLike, byteOffset?: number, byteLength?: number) => T;\n\nconst hexLookupTable = (function () {\n const alphabet = '0123456789abcdef';\n const table = new Array(256);\n for (let i = 0; i < 16; ++i) {\n const i16 = i * 16;\n for (let j = 0; j < 16; ++j) {\n table[i16 + j] = alphabet[i] + alphabet[j];\n }\n }\n return table;\n})();\n\ndeclare global {\n interface ArrayBuffer {\n resize?: (newByteLength: number) => void;\n resizable?: boolean;\n }\n\n interface SharedArrayBuffer {\n resize?: (newByteLength: number) => void;\n resizable?: boolean;\n }\n\n interface Uint8Array {\n toBase64(): string;\n\n toHex(): string;\n }\n\n interface Uint8ArrayConstructor {\n fromBase64(v: string): Uint8Array;\n\n fromHex(v: string): Uint8Array;\n }\n}\n"],"names":["classOf","getGlobalThis","decodeBase64ToArrayBuffer","encodeArrayBufferToBase64","isBuffer","ArrayBuffers","nativeBufferAllowed","isBufferAvailable","isNativeBufferAvailable","Buffer","isPollyfill","isNativeBufferAllowed","setNativeBufferAllowed","v","isArrayBuffer","ArrayBuffer","toArrayBuffer","buffer","toUint8Array","asView","Uint8Array","toBase64","prototype","from","toString","toHex","fromBase64","fromHex","resize","newByteLength","maxByteLength","undefined","resizable","old","newBuf","oldView","newView","set","slice","o","start","end","call","TypedArray","byteOffset","byteLength","isView","buf","encoding","btoa","Error","view","map","b","hexLookupTable","join","TextDecoder","decode","String","fromCharCode","res","i","length","toJSON","reviver","JSON","parse","alloc","size","fill","TextEncoder","encode","replace","match","byte","parseInt","Array","isArray","type","TypeError","isEncoding","toLowerCase","concat","buffers","result","offset","reduce","a","r","n","alphabet","table","i16","j"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,OAAO,QAAQ,mBAAmB;AAC3C,SAASC,aAAa,QAAQ,2BAA2B;AACzD,SAASC,yBAAyB,EAAEC,yBAAyB,QAAQ,WAAW;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GA,IAAI,IAAI,EAAEA,EAAG;YAC3BF,KAAK,CAACC,MAAMC,EAAE,GAAGH,QAAQ,CAAC7B,EAAE,GAAG6B,QAAQ,CAACG,EAAE;QAC5C;IACF;IACA,OAAOF;AACT"}
1
+ {"version":3,"sources":["../../src/io/ArrayBuffers.ts"],"sourcesContent":["import { classOf } from '../langs/classOf';\nimport { getGlobalThis } from '../runtime/getGlobalThis';\nimport { decodeBase64ToArrayBuffer, encodeArrayBufferToBase64 } from './base64';\nimport { isBuffer } from './isBuffer';\n\n/**\n * Various utils to work with {@link ArrayBuffer}\n *\n * @see https://github.com/tc39/proposal-arraybuffer-base64\n * @see https://github.com/tc39/proposal-resizablearraybuffer\n */\nexport interface ArrayBuffers {\n /**\n * isArrayBuffer check if the given value is an {@link ArrayBuffer}\n */\n isArrayBuffer(v: any): v is ArrayBuffer;\n\n /**\n * slice the given view with the given offset and length, will handle the {@link Buffer} as well\n *\n * @see {@link https://nodejs.org/api/buffer.html#bufslicestart-end Buffer.slice}\n */\n slice<T extends ArrayBufferView>(o: T, start?: number, end?: number): T;\n\n /**\n * asView convert the given value to given {@link TypedArray} view\n *\n * TypedArray can be {@link Buffer}, will avoid copy\n */\n asView<C extends ArrayBufferViewConstructor<unknown>>(\n TypedArray: C,\n v: BufferSource,\n byteOffset?: number,\n byteLength?: number,\n ): InstanceType<C>;\n\n /**\n * toString convert the given {@link BufferSource} to string\n */\n toString(v: BufferSource | string, encoding?: ToStringEncoding): string;\n\n /**\n * Returns true if encoding is the name of a supported character encoding, or false otherwise.\n */\n isEncoding(v?: string): v is ToStringEncoding;\n\n toJSON<T = any>(v: BufferSource | string, reviver?: (this: any, key: string, value: any) => any): T;\n\n /**\n * from convert the given value to {@link ArrayBuffer}\n */\n from(v: string | BufferSource, encoding?: ToStringEncoding): ArrayBuffer;\n\n from<C extends ArrayBufferViewConstructor<unknown>>(\n v: string | BufferSource,\n encoding: ToStringEncoding,\n TypedArray: C,\n ): C;\n\n /**\n * concat the given {@link BufferSource} to a new {@link ArrayBuffer}\n */\n concat(buffers: Array<BufferSource>, result?: ArrayBuffer, offset?: number): ArrayBuffer;\n\n fromBase64(v: string): Uint8Array;\n\n fromHex(v: string): Uint8Array;\n\n toBase64(v: BufferSource): string;\n\n toHex(v: BufferSource): string;\n\n resize(v: ArrayBuffer, newByteLength: number): ArrayBuffer;\n\n // truncate(v: ArrayBufferLike, len?: number): ArrayBufferLike;\n}\n\ntype ToStringEncoding =\n | 'ascii'\n | 'utf16le'\n // | 'utf-16le'\n | 'ucs2'\n | 'ucs-2'\n | 'base64'\n | 'base64url'\n | 'latin1'\n | 'binary'\n | 'utf8'\n | 'utf-8'\n | 'hex';\n\nexport class ArrayBuffers {\n static #nativeBufferAllowed: boolean = true;\n static #isBufferAvailable: undefined | boolean;\n\n static isNativeBufferAvailable() {\n // eslint-disable-next-line no-return-assign\n return (this.#isBufferAvailable ??= !(getGlobalThis().Buffer as any)?.isPollyfill?.());\n }\n\n static isNativeBufferAllowed() {\n return this.#nativeBufferAllowed && this.#isBufferAvailable;\n }\n\n static setNativeBufferAllowed(v: boolean) {\n this.#nativeBufferAllowed = v;\n }\n\n static isArrayBuffer = (v: any): v is ArrayBuffer => {\n return v instanceof ArrayBuffer;\n };\n\n static toArrayBuffer(v: BufferSource): ArrayBuffer {\n return v instanceof ArrayBuffer ? v : (v.buffer as ArrayBuffer);\n }\n\n static toUint8Array(v: BufferSource) {\n return ArrayBuffers.asView(Uint8Array, v);\n }\n\n static toBase64 = (v: BufferSource) => {\n if ('toBase64' in Uint8Array.prototype) {\n return this.toUint8Array(v).toBase64();\n }\n\n if (ArrayBuffers.isNativeBufferAllowed()) {\n return Buffer.from(ArrayBuffers.asView(Uint8Array, v)).toString('base64');\n }\n\n return encodeArrayBufferToBase64(this.toArrayBuffer(v));\n };\n\n static toHex = (v: BufferSource) => {\n if ('toHex' in Uint8Array.prototype) {\n return this.toUint8Array(v).toHex();\n }\n if (ArrayBuffers.isNativeBufferAllowed()) {\n return Buffer.from(ArrayBuffers.asView(Uint8Array, v)).toString('hex');\n }\n return ArrayBuffers.toString(v, 'hex');\n };\n\n static fromBase64 = (v: string) => {\n if ('fromBase64' in Uint8Array) {\n return Uint8Array.fromBase64(v);\n }\n if (ArrayBuffers.isNativeBufferAllowed()) {\n return Buffer.from(v, 'base64');\n }\n return this.toUint8Array(decodeBase64ToArrayBuffer(v));\n };\n\n static fromHex = (v: string) => {\n if ('fromHex' in Uint8Array) {\n return Uint8Array.fromHex(v);\n }\n return this.toUint8Array(ArrayBuffers.from(v, 'hex'));\n };\n\n static resize = (v: ArrayBuffer, newByteLength?: number, maxByteLength?: number): ArrayBuffer => {\n if (newByteLength === undefined || newByteLength === null) {\n return v;\n }\n\n // Chrome 111, Nodejs 20\n if ('resize' in v && typeof v.resize === 'function') {\n if ('resizable' in v && v.resizable) {\n if ('maxByteLength' in v && typeof v.maxByteLength === 'number' && v.maxByteLength >= newByteLength) {\n v.resize(newByteLength);\n return v as ArrayBuffer;\n }\n }\n }\n\n const old = v;\n const newBuf = new ArrayBuffer(newByteLength, { maxByteLength: maxByteLength });\n const oldView = new Uint8Array(old);\n const newView = new Uint8Array(newBuf);\n newView.set(oldView);\n return newBuf;\n };\n\n static slice = (o: TypedArray, start?: number, end?: number) => {\n // NodeJS Buffer slice is not the same as UInt8Array slice\n // https://nodejs.org/api/buffer.html#bufslicestart-end\n if (isBuffer(o)) {\n return Uint8Array.prototype.slice.call(o, start, end);\n }\n return o.slice(start, end);\n };\n\n static asView = <C extends ArrayBufferViewConstructor<unknown>, I extends InstanceType<C>>(\n TypedArray: C,\n v: BufferSource,\n byteOffset?: number,\n byteLength?: number,\n ): I => {\n if (v instanceof TypedArray && (byteOffset ?? 0) === 0 && byteLength === undefined) {\n return v as I;\n }\n if (ArrayBuffer.isView(v) || isBuffer(v)) {\n if (ArrayBuffers.isNativeBufferAllowed() && (TypedArray as any) === Buffer) {\n // new Buffer() is deprecated\n return Buffer.from(v.buffer, byteOffset, byteLength) as I;\n }\n return new TypedArray(v.buffer, v.byteOffset + (byteOffset ?? 0), byteLength ?? v.byteLength) as I;\n }\n return new TypedArray(v, byteOffset, byteLength) as I;\n };\n\n static toString = (buf: BufferSource | string, encoding: ToStringEncoding = 'utf8') => {\n // 'ascii' 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex'\n if (typeof buf === 'string') {\n switch (encoding) {\n case 'base64':\n return btoa(buf);\n case 'utf-8':\n case 'utf8':\n return buf;\n default:\n throw new Error(`[ArrayBuffers.toString] Unsupported encoding for string: ${encoding}`);\n }\n }\n if (ArrayBuffers.isNativeBufferAllowed()) {\n return Buffer.from(ArrayBuffers.asView(Uint8Array, buf)).toString(encoding);\n }\n // reference\n // https://github.com/feross/buffer/blob/master/index.js\n switch (encoding) {\n case 'hex': {\n const view: Uint8Array = ArrayBuffers.asView(Uint8Array, buf);\n return [...view].map((b) => hexLookupTable[b]).join('');\n }\n case 'base64': {\n return encodeArrayBufferToBase64(ArrayBuffers.asView(Uint8Array, buf));\n }\n case 'utf8':\n // falls through\n case 'utf-8':\n return new TextDecoder().decode(buf as any);\n case 'ascii': {\n const view: Uint8Array = ArrayBuffers.asView(Uint8Array, buf);\n return String.fromCharCode(...view.map((v) => v & 0x7f));\n }\n case 'latin1':\n // falls through\n case 'binary': {\n const view: Uint8Array = ArrayBuffers.asView(Uint8Array, buf);\n return String.fromCharCode(...view);\n }\n case 'ucs2':\n // falls through\n case 'ucs-2':\n // case 'utf-16le':\n // falls through\n case 'utf16le': {\n const view: Uint8Array = ArrayBuffers.asView(Uint8Array, buf);\n let res = '';\n // If length is odd, the last 8 bits must be ignored (same as node.js)\n for (let i = 0; i < view.length - 1; i += 2) {\n res += String.fromCharCode(view[i] + view[i + 1] * 256);\n }\n return res;\n }\n default:\n throw new Error(`[ArrayBuffers.toString] Unknown encoding: ${encoding}`);\n }\n };\n\n static toJSON = (v: BufferSource | string, reviver?: (this: any, key: string, value: any) => any) => {\n return JSON.parse(ArrayBuffers.toString(v), reviver);\n };\n\n static alloc = (size: number, fill?: string | number, encoding?: ToStringEncoding) => {\n if (fill !== undefined) {\n if (typeof fill === 'number') {\n return new Uint8Array(size).fill(fill);\n }\n // as cast\n // https://stackoverflow.com/questions/73994091\n return ArrayBuffers.asView(Uint8Array, ArrayBuffers.from(fill, encoding)).slice(0, size);\n }\n return new ArrayBuffer(size);\n };\n\n static from = (\n v: string | BufferSource | ArrayLike<number> | Iterable<number>,\n encoding: ToStringEncoding = 'utf8',\n view?: any,\n ): any => {\n if (view) {\n return this.asView(view, this.from(v, encoding));\n }\n if (!v) {\n return new ArrayBuffer(0);\n }\n if (typeof v === 'string') {\n if (ArrayBuffers.isNativeBufferAllowed()) {\n return Buffer.from(v, encoding);\n }\n\n switch (encoding) {\n case 'utf-8':\n // falls through\n case 'utf8':\n return new TextEncoder().encode(v).buffer;\n case 'base64':\n // replaceAll need higher version of nodejs\n return decodeBase64ToArrayBuffer(v.replace(/[^0-9a-zA-Z=+/_]/g, ''));\n case 'hex':\n return new Uint8Array(v.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16))).buffer;\n default:\n throw new Error(`[ArrayBuffers.from] Unknown encoding: ${encoding}`);\n }\n }\n if (v instanceof ArrayBuffer) {\n return v;\n }\n // lost length\n if (ArrayBuffer.isView(v) || isBuffer(v)) {\n if (v.byteOffset !== 0) {\n // return v.buffer.slice(v.byteOffset, v.byteOffset + v.byteLength)\n throw new Error('ArrayBuffers.from do not support view with offset');\n }\n return v.buffer;\n }\n if (Array.isArray(v)) {\n return new Uint8Array(v);\n }\n const type = classOf(v);\n throw new TypeError(`ArrayBuffers.from unsupported type ${type}`);\n };\n\n static isEncoding = (encoding?: string) => {\n switch (String(encoding).toLowerCase()) {\n case 'hex':\n case 'utf8':\n case 'utf-8':\n case 'ascii':\n case 'latin1':\n case 'binary':\n case 'base64':\n case 'ucs2':\n case 'ucs-2':\n case 'utf16le':\n // case 'utf-16le':\n return true;\n default:\n return false;\n }\n };\n\n // static truncate = (a: ArrayBufferLike, len?: number) => {\n // if (len === 0) {\n // return new ArrayBuffer(0);\n // }\n // if (!len) {\n // return a;\n // }\n // if (a.byteLength > len) {\n // return a.slice(0, len);\n // } else if (a.byteLength < len) {\n // let b = new Uint8Array(len);\n // b.set(new Uint8Array(a));\n // return b;\n // }\n // return a;\n // };\n\n static concat = (buffers: Array<BufferSource>, result?: ArrayBuffer, offset = 0): ArrayBuffer => {\n // https://stackoverflow.com/questions/10786128/appending-arraybuffers\n\n const length = buffers.reduce((a, b) => a + b.byteLength, 0);\n const r = result ? new Uint8Array(result) : new Uint8Array(length);\n for (const buffer of buffers) {\n if (!buffer?.byteLength) continue;\n let n: Uint8Array;\n if (buffer instanceof ArrayBuffer) {\n n = new Uint8Array(buffer);\n } else if (ArrayBuffer.isView(buffer)) {\n n = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n } else {\n throw new Error(`ArrayBuffers.concat unsupported type ${classOf(buffer)}`);\n }\n r.set(n, offset);\n offset += buffer.byteLength;\n }\n return r.buffer;\n };\n}\n\nexport type TypedArray =\n | Uint8Array\n | Uint8ClampedArray\n | Uint16Array\n | Uint32Array\n | Int8Array\n | Int16Array\n | Int32Array\n | BigUint64Array\n | BigInt64Array\n | Float32Array\n | Float64Array;\n\ntype ArrayBufferViewConstructor<T> = new (buffer: ArrayBufferLike, byteOffset?: number, byteLength?: number) => T;\n\nconst hexLookupTable = (function () {\n const alphabet = '0123456789abcdef';\n const table = new Array(256);\n for (let i = 0; i < 16; ++i) {\n const i16 = i * 16;\n for (let j = 0; j < 16; ++j) {\n table[i16 + j] = alphabet[i] + alphabet[j];\n }\n }\n return table;\n})();\n\ndeclare global {\n interface ArrayBuffer {\n resize?: (newByteLength: number) => void;\n resizable?: boolean;\n }\n\n interface ArrayBufferConstructor {\n new (byteLength: number, opts?: { maxByteLength?: number }): ArrayBuffer;\n }\n\n interface SharedArrayBuffer {\n resize?: (newByteLength: number) => void;\n resizable?: boolean;\n }\n\n interface Uint8Array {\n toBase64(): string;\n\n toHex(): string;\n }\n\n interface Uint8ArrayConstructor {\n fromBase64(v: string): Uint8Array;\n\n fromHex(v: string): Uint8Array;\n }\n}\n"],"names":["classOf","getGlobalThis","decodeBase64ToArrayBuffer","encodeArrayBufferToBase64","isBuffer","ArrayBuffers","nativeBufferAllowed","isBufferAvailable","isNativeBufferAvailable","Buffer","isPollyfill","isNativeBufferAllowed","setNativeBufferAllowed","v","isArrayBuffer","ArrayBuffer","toArrayBuffer","buffer","toUint8Array","asView","Uint8Array","toBase64","prototype","from","toString","toHex","fromBase64","fromHex","resize","newByteLength","maxByteLength","undefined","resizable","old","newBuf","oldView","newView","set","slice","o","start","end","call","TypedArray","byteOffset","byteLength","isView","buf","encoding","btoa","Error","view","map","b","hexLookupTable","join","TextDecoder","decode","String","fromCharCode","res","i","length","toJSON","reviver","JSON","parse","alloc","size","fill","TextEncoder","encode","replace","match","byte","parseInt","Array","isArray","type","TypeError","isEncoding","toLowerCase","concat","buffers","result","offset","reduce","a","r","n","alphabet","table","i16","j"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,OAAO,QAAQ,mBAAmB;AAC3C,SAASC,aAAa,QAAQ,2BAA2B;AACzD,SAASC,yBAAyB,EAAEC,yBAAyB,QAAQ,WAAW;AAChF,SAASC,QAAQ,QAAQ,aAAa;AAwFtC,OAAO,MAAMC;IACX,OAAO,CAACC,mBAA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