@wener/utils 1.1.49 → 1.1.51

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 (204) hide show
  1. package/lib/arrays/MaybeArray.js.map +1 -1
  2. package/lib/arrays/arrayFromAsync.js.map +1 -1
  3. package/lib/asyncs/AsyncInterval.js.map +1 -1
  4. package/lib/asyncs/MaybePromise.js.map +1 -1
  5. package/lib/asyncs/Promises.js.map +1 -1
  6. package/lib/asyncs/createAsyncIterator.js.map +1 -1
  7. package/lib/asyncs/createLazyPromise.js.map +1 -1
  8. package/lib/asyncs/firstOfAsyncIterator.js.map +1 -1
  9. package/lib/asyncs/generatorOfStream.js.map +1 -1
  10. package/lib/asyncs/isIterator.js.map +1 -1
  11. package/lib/asyncs/isPromise.js.map +1 -1
  12. package/lib/asyncs/isThenable.js.map +1 -1
  13. package/lib/asyncs/nextOfAsyncIterator.js.map +1 -1
  14. package/lib/asyncs/promiseOfCallback.js.map +1 -1
  15. package/lib/asyncs/timeout.js.map +1 -1
  16. package/lib/browsers/copy.js.map +1 -1
  17. package/lib/browsers/download.js.map +1 -1
  18. package/lib/browsers/getFileFromDataTransfer.js.map +1 -1
  19. package/lib/browsers/loaders.js.map +1 -1
  20. package/lib/cn/division/DivisionCode.js +21 -15
  21. package/lib/cn/division/DivisionCode.js.map +1 -1
  22. package/lib/cn/division/binarySearch.js.map +1 -1
  23. package/lib/cn/formatChineseAmount.js.map +1 -1
  24. package/lib/cn/id/Mod11.js.map +1 -1
  25. package/lib/cn/id/ResidentIdNumber.js.map +1 -1
  26. package/lib/cn/id/types.js.map +1 -1
  27. package/lib/cn/index.js.map +1 -1
  28. package/lib/cn/parseChineseNumber.js.map +1 -1
  29. package/lib/cn/pinyin/cartesianProduct.js.map +1 -1
  30. package/lib/cn/pinyin/loader.js.map +1 -1
  31. package/lib/cn/pinyin/preload.js.map +1 -1
  32. package/lib/cn/pinyin/toPinyinPure.js.map +1 -1
  33. package/lib/cn/pinyin/transform.js.map +1 -1
  34. package/lib/cn/types.js.map +1 -1
  35. package/lib/cn/uscc/Mod31.js.map +1 -1
  36. package/lib/cn/uscc/USCC.js.map +1 -1
  37. package/lib/cn/uscc/isUSCC.js.map +1 -1
  38. package/lib/crypto/base.js.map +1 -1
  39. package/lib/crypto/getNodeCrypto.js +1 -1
  40. package/lib/crypto/getNodeCrypto.js.map +1 -1
  41. package/lib/crypto/hashing.js.map +1 -1
  42. package/lib/crypto/md5.bench.js.map +1 -1
  43. package/lib/crypto/md5.d.js.map +1 -1
  44. package/lib/crypto/md5.js.map +1 -1
  45. package/lib/crypto/pem/pem.js.map +1 -1
  46. package/lib/crypto/randomUUIDv7.js.map +1 -1
  47. package/lib/crypto/ulid.js +1 -1
  48. package/lib/crypto/ulid.js.map +1 -1
  49. package/lib/emitter/types.js.map +1 -1
  50. package/lib/errors/Errors.js +38 -17
  51. package/lib/errors/Errors.js.map +1 -1
  52. package/lib/fetch/HttpStatus.js.map +1 -1
  53. package/lib/fetch/createFetchWith.js +1 -1
  54. package/lib/fetch/createFetchWith.js.map +1 -1
  55. package/lib/fetch/createFetchWithLogging.js.map +1 -1
  56. package/lib/fetch/createFetchWithRetry.js +1 -1
  57. package/lib/fetch/createFetchWithRetry.js.map +1 -1
  58. package/lib/fetch/dumpRequest.js.map +1 -1
  59. package/lib/fetch/dumpResponse.js.map +1 -1
  60. package/lib/fetch/http.types.js.map +1 -1
  61. package/lib/fetch/index.js.map +1 -1
  62. package/lib/fetch/types.js.map +1 -1
  63. package/lib/i18n/createTranslate.js.map +1 -1
  64. package/lib/index.js +9 -7
  65. package/lib/index.js.map +1 -1
  66. package/lib/io/AbstractEncoding.js.map +1 -1
  67. package/lib/io/ArrayBuffer.test-d.js.map +1 -1
  68. package/lib/io/ArrayBuffers.js +218 -174
  69. package/lib/io/ArrayBuffers.js.map +1 -1
  70. package/lib/io/Buffer.js.map +1 -1
  71. package/lib/io/ByteBuffer.js.map +1 -1
  72. package/lib/io/base64.js +2 -2
  73. package/lib/io/base64.js.map +1 -1
  74. package/lib/io/dump.js.map +1 -1
  75. package/lib/io/isBuffer.js.map +1 -1
  76. package/lib/io/isTransferable.js +1 -1
  77. package/lib/io/isTransferable.js.map +1 -1
  78. package/lib/io/parseDataUri.js.map +1 -1
  79. package/lib/langs/AsyncCloser.js.map +1 -0
  80. package/lib/langs/Closer.js.map +1 -0
  81. package/lib/langs/MaybeFunction.js.map +1 -1
  82. package/lib/langs/classOf.js.map +1 -1
  83. package/lib/langs/deepEqual.js.map +1 -1
  84. package/lib/langs/deepFreeze.js.map +1 -1
  85. package/lib/langs/getGlobalStates.js +11 -3
  86. package/lib/langs/getGlobalStates.js.map +1 -1
  87. package/lib/langs/getObjectId.js +1 -1
  88. package/lib/langs/getObjectId.js.map +1 -1
  89. package/lib/langs/ifPresent.js +5 -0
  90. package/lib/langs/ifPresent.js.map +1 -0
  91. package/lib/langs/isClass.js.map +1 -1
  92. package/lib/langs/isDefined.js.map +1 -1
  93. package/lib/langs/isEmptyObject.js.map +1 -1
  94. package/lib/langs/isFunction.js.map +1 -1
  95. package/lib/langs/isNullish.js.map +1 -1
  96. package/lib/langs/isPlainObject.js.map +1 -1
  97. package/lib/langs/memoize.js.map +1 -1
  98. package/lib/langs/mixin.js.map +1 -1
  99. package/lib/langs/parseBoolean.js.map +1 -1
  100. package/lib/langs/shallowClone.js.map +1 -1
  101. package/lib/langs/shallowEqual.js.map +1 -1
  102. package/lib/libs/ms.js.map +1 -1
  103. package/lib/logging/Logger.js.map +1 -1
  104. package/lib/logging/createChildLogger.js.map +1 -1
  105. package/lib/logging/createLogger.js.map +1 -1
  106. package/lib/logging/createNoopLogger.js.map +1 -1
  107. package/lib/logging/slog.js.map +1 -1
  108. package/lib/maths/clamp.js.map +1 -1
  109. package/lib/maths/random.js.map +1 -1
  110. package/lib/mitt/index.js.map +1 -1
  111. package/lib/modules/isModule.js.map +1 -1
  112. package/lib/modules/parseModuleId.js.map +1 -1
  113. package/lib/objects/computeIfAbsent.js.map +1 -1
  114. package/lib/objects/get.js.map +1 -1
  115. package/lib/objects/get.test-d.js.map +1 -1
  116. package/lib/objects/merge/index.js.map +1 -1
  117. package/lib/objects/merge/isMergeableObject.js.map +1 -1
  118. package/lib/objects/merge/merge.js.map +1 -1
  119. package/lib/objects/parseObjectPath.js.map +1 -1
  120. package/lib/objects/set.js.map +1 -1
  121. package/lib/schema/typebox/index.js.map +1 -1
  122. package/lib/schema/typebox/typebox.js.map +1 -1
  123. package/lib/scripts/getGenerateContext.js +2 -1
  124. package/lib/scripts/getGenerateContext.js.map +1 -1
  125. package/lib/server/crypto/md5.js.map +1 -1
  126. package/lib/server/fetch/createFetchWithProxy.js.map +1 -1
  127. package/lib/server/fetch/createFetchWithProxyByNodeFetch.js +1 -1
  128. package/lib/server/fetch/createFetchWithProxyByNodeFetch.js.map +1 -1
  129. package/lib/server/fetch/createFetchWithProxyByUndici.js +1 -1
  130. package/lib/server/fetch/createFetchWithProxyByUndici.js.map +1 -1
  131. package/lib/server/getPackageDir.js.map +1 -1
  132. package/lib/server/index.js.map +1 -1
  133. package/lib/server/jsdom.js.map +1 -1
  134. package/lib/server/node-fetch.js.map +1 -1
  135. package/lib/server/polyfill/polyfillBrowser.js.map +1 -1
  136. package/lib/server/polyfill/polyfillCrypto.js +1 -1
  137. package/lib/server/polyfill/polyfillCrypto.js.map +1 -1
  138. package/lib/server/polyfill/polyfillFetch.js.map +1 -1
  139. package/lib/server/polyfill/polyfillJsDom.js +1 -1
  140. package/lib/server/polyfill/polyfillJsDom.js.map +1 -1
  141. package/lib/server/polyfill/polyfillWebSocket.js +1 -1
  142. package/lib/server/polyfill/polyfillWebSocket.js.map +1 -1
  143. package/lib/server/ws.js.map +1 -1
  144. package/lib/strings/camelCase.js.map +1 -1
  145. package/lib/strings/formatBytes.js.map +1 -1
  146. package/lib/strings/renderTemplate.js.map +1 -1
  147. package/lib/typedoc.js.map +1 -1
  148. package/lib/types.d.js.map +1 -1
  149. package/lib/validations/asserts.js.map +1 -1
  150. package/lib/validations/isUUID.js.map +1 -1
  151. package/lib/validations/parseTimestamp.js.map +1 -1
  152. package/lib/web/getGlobalThis.js.map +1 -0
  153. package/lib/{crypto → web}/getRandomValues.js +2 -2
  154. package/lib/web/getRandomValues.js.map +1 -0
  155. package/lib/{crypto → web}/randomUUID.js +1 -1
  156. package/lib/web/randomUUID.js.map +1 -0
  157. package/lib/web/requestIdleCallback.js +13 -0
  158. package/lib/web/requestIdleCallback.js.map +1 -0
  159. package/lib/web/structuredClone.js.map +1 -0
  160. package/package.json +4 -7
  161. package/src/asyncs/createAsyncIterator.ts +1 -1
  162. package/src/cn/division/DivisionCode.ts +25 -7
  163. package/src/cn/division/division.test.ts +18 -2
  164. package/src/crypto/getNodeCrypto.ts +1 -1
  165. package/src/crypto/hashing.test.ts +1 -1
  166. package/src/crypto/ulid.test.ts +1 -1
  167. package/src/crypto/ulid.ts +1 -1
  168. package/src/errors/Errors.ts +37 -16
  169. package/src/fetch/createFetchWith.ts +2 -2
  170. package/src/fetch/createFetchWithLogging.ts +1 -1
  171. package/src/fetch/createFetchWithRetry.ts +1 -1
  172. package/src/index.ts +9 -8
  173. package/src/io/ArrayBuffers.base64.test.ts +7 -0
  174. package/src/io/ArrayBuffers.ts +273 -272
  175. package/src/io/base64.ts +2 -2
  176. package/src/io/isTransferable.ts +1 -1
  177. package/src/langs/getGlobalStates.ts +13 -3
  178. package/src/langs/getObjectId.ts +1 -1
  179. package/src/langs/ifPresent.ts +3 -0
  180. package/src/scripts/getGenerateContext.ts +3 -1
  181. package/src/server/fetch/createFetchWithProxyByNodeFetch.ts +2 -2
  182. package/src/server/fetch/createFetchWithProxyByUndici.ts +1 -1
  183. package/src/server/polyfill/polyfillCrypto.ts +1 -1
  184. package/src/server/polyfill/polyfillJsDom.ts +1 -1
  185. package/src/server/polyfill/polyfillWebSocket.ts +1 -1
  186. package/src/validations/isUUID.test.ts +1 -1
  187. package/src/{crypto → web}/getRandomValues.ts +2 -2
  188. package/src/{crypto → web}/randomUUID.ts +1 -1
  189. package/src/web/requestIdleCallback.ts +14 -0
  190. package/lib/crypto/getRandomValues.js.map +0 -1
  191. package/lib/crypto/randomUUID.js.map +0 -1
  192. package/lib/runtime/AsyncCloser.js.map +0 -1
  193. package/lib/runtime/Closer.js.map +0 -1
  194. package/lib/runtime/getGlobalThis.js.map +0 -1
  195. package/lib/runtime/structuredClone.js.map +0 -1
  196. /package/lib/{runtime → langs}/AsyncCloser.js +0 -0
  197. /package/lib/{runtime → langs}/Closer.js +0 -0
  198. /package/lib/{runtime → web}/getGlobalThis.js +0 -0
  199. /package/lib/{runtime → web}/structuredClone.js +0 -0
  200. /package/src/{runtime → langs}/AsyncCloser.ts +0 -0
  201. /package/src/{runtime → langs}/Closer.ts +0 -0
  202. /package/src/{runtime → web}/getGlobalThis.ts +0 -0
  203. /package/src/{runtime → web}/structuredClone.test.ts +0 -0
  204. /package/src/{runtime → web}/structuredClone.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/polyfill/polyfillBrowser.ts"],"sourcesContent":["import { polyfillCrypto } from './polyfillCrypto';\nimport { polyfillFetch } from './polyfillFetch';\nimport { polyfillJsDom } from './polyfillJsDom';\n\n/**\n * Polyfills the browser environment with the necessary APIs for the server.\n * Currently, this includes:\n * - `window`\n * - `document`\n * - `fetch`\n * - `crypto`\n */\nexport async function polyfillBrowser() {\n await polyfillCrypto();\n await polyfillFetch();\n await polyfillJsDom();\n}\n"],"names":["polyfillCrypto","polyfillFetch","polyfillJsDom","polyfillBrowser"],"rangeMappings":";;;;;;;;;;;;;;","mappings":"AAAA,SAASA,cAAc,QAAQ,mBAAmB;AAClD,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,aAAa,QAAQ,kBAAkB;AAEhD;;;;;;;CAOC,GACD,OAAO,eAAeC;IACpB,MAAMH;IACN,MAAMC;IACN,MAAMC;AACR"}
1
+ {"version":3,"sources":["../../../src/server/polyfill/polyfillBrowser.ts"],"sourcesContent":["import { polyfillCrypto } from './polyfillCrypto';\nimport { polyfillFetch } from './polyfillFetch';\nimport { polyfillJsDom } from './polyfillJsDom';\n\n/**\n * Polyfills the browser environment with the necessary APIs for the server.\n * Currently, this includes:\n * - `window`\n * - `document`\n * - `fetch`\n * - `crypto`\n */\nexport async function polyfillBrowser() {\n await polyfillCrypto();\n await polyfillFetch();\n await polyfillJsDom();\n}\n"],"names":["polyfillCrypto","polyfillFetch","polyfillJsDom","polyfillBrowser"],"mappings":"AAAA,SAASA,cAAc,QAAQ,mBAAmB;AAClD,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,aAAa,QAAQ,kBAAkB;AAEhD;;;;;;;CAOC,GACD,OAAO,eAAeC;IACpB,MAAMH;IACN,MAAMC;IACN,MAAMC;AACR"}
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../../runtime/getGlobalThis.js';
1
+ import { getGlobalThis } from '../../web/getGlobalThis.js';
2
2
  export async function polyfillCrypto() {
3
3
  const globalThis = getGlobalThis();
4
4
  if ('crypto' in globalThis) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/polyfill/polyfillCrypto.ts"],"sourcesContent":["import { getGlobalThis } from '../../runtime/getGlobalThis';\n\nexport async function polyfillCrypto() {\n const globalThis = getGlobalThis();\n if ('crypto' in globalThis) {\n return false;\n }\n (globalThis as any).crypto = (await import('node:crypto')).webcrypto as Crypto;\n return true;\n}\n"],"names":["getGlobalThis","polyfillCrypto","globalThis","crypto","webcrypto"],"rangeMappings":";;;;;;;;","mappings":"AAAA,SAASA,aAAa,QAAQ,8BAA8B;AAE5D,OAAO,eAAeC;IACpB,MAAMC,aAAaF;IACnB,IAAI,YAAYE,YAAY;QAC1B,OAAO;IACT;IACCA,WAAmBC,MAAM,GAAG,AAAC,CAAA,MAAM,MAAM,CAAC,cAAa,EAAGC,SAAS;IACpE,OAAO;AACT"}
1
+ {"version":3,"sources":["../../../src/server/polyfill/polyfillCrypto.ts"],"sourcesContent":["import { getGlobalThis } from '../../web/getGlobalThis';\n\nexport async function polyfillCrypto() {\n const globalThis = getGlobalThis();\n if ('crypto' in globalThis) {\n return false;\n }\n (globalThis as any).crypto = (await import('node:crypto')).webcrypto as Crypto;\n return true;\n}\n"],"names":["getGlobalThis","polyfillCrypto","globalThis","crypto","webcrypto"],"mappings":"AAAA,SAASA,aAAa,QAAQ,0BAA0B;AAExD,OAAO,eAAeC;IACpB,MAAMC,aAAaF;IACnB,IAAI,YAAYE,YAAY;QAC1B,OAAO;IACT;IACCA,WAAmBC,MAAM,GAAG,AAAC,CAAA,MAAM,MAAM,CAAC,cAAa,EAAGC,SAAS;IACpE,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/polyfill/polyfillFetch.ts"],"sourcesContent":["import type { MaybePromise } from '../../asyncs/MaybePromise';\n\nexport function polyfillFetch(nodeFetch: typeof import('node-fetch')): boolean;\nexport function polyfillFetch(nodeFetch?: undefined): Promise<boolean>;\nexport function polyfillFetch(nodeFetch?: typeof import('node-fetch')): MaybePromise<boolean> {\n if ('fetch' in globalThis) {\n return false;\n }\n // sync mode\n if (nodeFetch) {\n const { default: fetch, Response, Headers, Request, AbortError, FetchError, FormData, Blob, File } = nodeFetch;\n Object.assign(globalThis, {\n fetch,\n Response,\n Headers,\n Request,\n AbortError,\n FetchError,\n FormData,\n Blob,\n File,\n });\n // abort controller\n return true;\n }\n return import('node-fetch').then((v) => polyfillFetch(v));\n}\n"],"names":["polyfillFetch","nodeFetch","globalThis","default","fetch","Response","Headers","Request","AbortError","FetchError","FormData","Blob","File","Object","assign","then","v"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,OAAO,SAASA,cAAcC,SAAuC;IACnE,IAAI,WAAWC,YAAY;QACzB,OAAO;IACT;IACA,YAAY;IACZ,IAAID,WAAW;QACb,MAAM,EAAEE,SAASC,KAAK,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,OAAO,EAAEC,UAAU,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAGX;QACrGY,OAAOC,MAAM,CAACZ,YAAY;YACxBE;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;QACF;QACA,mBAAmB;QACnB,OAAO;IACT;IACA,OAAO,MAAM,CAAC,cAAcG,IAAI,CAAC,CAACC,IAAMhB,cAAcgB;AACxD"}
1
+ {"version":3,"sources":["../../../src/server/polyfill/polyfillFetch.ts"],"sourcesContent":["import type { MaybePromise } from '../../asyncs/MaybePromise';\n\nexport function polyfillFetch(nodeFetch: typeof import('node-fetch')): boolean;\nexport function polyfillFetch(nodeFetch?: undefined): Promise<boolean>;\nexport function polyfillFetch(nodeFetch?: typeof import('node-fetch')): MaybePromise<boolean> {\n if ('fetch' in globalThis) {\n return false;\n }\n // sync mode\n if (nodeFetch) {\n const { default: fetch, Response, Headers, Request, AbortError, FetchError, FormData, Blob, File } = nodeFetch;\n Object.assign(globalThis, {\n fetch,\n Response,\n Headers,\n Request,\n AbortError,\n FetchError,\n FormData,\n Blob,\n File,\n });\n // abort controller\n return true;\n }\n return import('node-fetch').then((v) => polyfillFetch(v));\n}\n"],"names":["polyfillFetch","nodeFetch","globalThis","default","fetch","Response","Headers","Request","AbortError","FetchError","FormData","Blob","File","Object","assign","then","v"],"mappings":"AAIA,OAAO,SAASA,cAAcC,SAAuC;IACnE,IAAI,WAAWC,YAAY;QACzB,OAAO;IACT;IACA,YAAY;IACZ,IAAID,WAAW;QACb,MAAM,EAAEE,SAASC,KAAK,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,OAAO,EAAEC,UAAU,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAGX;QACrGY,OAAOC,MAAM,CAACZ,YAAY;YACxBE;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;QACF;QACA,mBAAmB;QACnB,OAAO;IACT;IACA,OAAO,MAAM,CAAC,cAAcG,IAAI,CAAC,CAACC,IAAMhB,cAAcgB;AACxD"}
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../../runtime/getGlobalThis.js';
1
+ import { getGlobalThis } from '../../web/getGlobalThis.js';
2
2
  export async function polyfillJsDom() {
3
3
  if (typeof window !== 'undefined') {
4
4
  return false;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/polyfill/polyfillJsDom.ts"],"sourcesContent":["import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\nimport { getGlobalThis } from '../../runtime/getGlobalThis';\n\nexport async function polyfillJsDom() {\n if (typeof window !== 'undefined') {\n return false;\n }\n\n const globalThis = getGlobalThis();\n\n const { ResourceLoader, JSDOM } = await import('jsdom');\n\n // https://github.com/lukechilds/window/blob/master/src/index.js\n // eslint-disable-next-line @typescript-eslint/no-extraneous-class\n class Window {\n constructor(opts: ResourceLoaderConstructorOptions & ConstructorOptions = {}) {\n const { proxy, strictSSL, userAgent, ...jsdomOpts } = opts;\n const resources = new ResourceLoader({\n proxy,\n strictSSL,\n userAgent,\n });\n return new JSDOM(\n '',\n Object.assign(jsdomOpts, {\n resources,\n }),\n ).window;\n }\n }\n\n // https://github.com/lukechilds/browser-env/blob/master/src/index.js\n // Default jsdom config.\n // These settings must override any custom settings to make sure we can iterate\n // over the window object.\n const defaultJsdomConfig = {\n // features: {\n // FetchExternalResources: false,\n // ProcessExternalResources: false,\n // },\n };\n // IIFE executed on import to return an array of global Node.js properties that\n // conflict with global browser properties.\n const protectedProperties = (() =>\n Object.getOwnPropertyNames(new Window(defaultJsdomConfig)).filter(\n (prop) => typeof globalThis[prop as keyof typeof globalThis] !== 'undefined',\n ))();\n\n function installEnv(...args: any[]) {\n // Sets up global browser environment\n // Extract options from args\n const properties = args.filter((arg: any) => Array.isArray(arg))[0];\n const userJsdomConfig = args.filter((arg: any) => !Array.isArray(arg))[0];\n\n // Create window object\n const window = new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig));\n\n // Get all global browser properties\n Object.getOwnPropertyNames(window)\n\n // Remove protected properties\n .filter((prop) => !protectedProperties.includes(prop))\n\n // If we're only applying specific required properties remove everything else\n .filter((prop) => !(properties && properties.indexOf(prop) === -1))\n .filter((prop) => {\n switch (prop) {\n case 'undefined':\n return false;\n }\n return true;\n })\n\n // Copy what's left to the Node.js global scope\n .forEach((prop) => {\n // console.debug(`define globalThis.${prop}`);\n Object.defineProperty(globalThis, prop, {\n configurable: true,\n get: () => window[prop as keyof Window] as any,\n });\n });\n\n return window;\n }\n\n installEnv({ url: 'http://localhost' });\n return true;\n}\n"],"names":["getGlobalThis","polyfillJsDom","window","globalThis","ResourceLoader","JSDOM","Window","constructor","opts","proxy","strictSSL","userAgent","jsdomOpts","resources","Object","assign","defaultJsdomConfig","protectedProperties","getOwnPropertyNames","filter","prop","installEnv","args","properties","arg","Array","isArray","userJsdomConfig","includes","indexOf","forEach","defineProperty","configurable","get","url"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,aAAa,QAAQ,8BAA8B;AAE5D,OAAO,eAAeC;IACpB,IAAI,OAAOC,WAAW,aAAa;QACjC,OAAO;IACT;IAEA,MAAMC,aAAaH;IAEnB,MAAM,EAAEI,cAAc,EAAEC,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC;IAE/C,gEAAgE;IAChE,kEAAkE;IAClE,IAAA,AAAMC,SAAN,MAAMA;QACJC,YAAYC,OAA8D,CAAC,CAAC,CAAE;YAC5E,MAAM,EAAEC,KAAK,EAAEC,SAAS,EAAEC,SAAS,EAAE,GAAGC,WAAW,GAAGJ;YACtD,MAAMK,YAAY,IAAIT,eAAe;gBACnCK;gBACAC;gBACAC;YACF;YACA,OAAO,IAAIN,MACT,IACAS,OAAOC,MAAM,CAACH,WAAW;gBACvBC;YACF,IACAX,MAAM;QACV;IACF;IAEA,qEAAqE;IACrE,wBAAwB;IACxB,+EAA+E;IAC/E,0BAA0B;IAC1B,MAAMc,qBAAqB;IAK3B;IACA,+EAA+E;IAC/E,2CAA2C;IAC3C,MAAMC,sBAAsB,AAAC,CAAA,IAC3BH,OAAOI,mBAAmB,CAAC,IAAIZ,OAAOU,qBAAqBG,MAAM,CAC/D,CAACC,OAAS,OAAOjB,UAAU,CAACiB,KAAgC,KAAK,YACnE;IAEF,SAASC,WAAW,GAAGC,IAAW;QAChC,qCAAqC;QACrC,4BAA4B;QAC5B,MAAMC,aAAaD,KAAKH,MAAM,CAAC,CAACK,MAAaC,MAAMC,OAAO,CAACF,KAAK,CAAC,EAAE;QACnE,MAAMG,kBAAkBL,KAAKH,MAAM,CAAC,CAACK,MAAa,CAACC,MAAMC,OAAO,CAACF,KAAK,CAAC,EAAE;QAEzE,uBAAuB;QACvB,MAAMtB,UAAS,IAAII,OAAOQ,OAAOC,MAAM,CAAC,CAAC,GAAGY,iBAAiBX;QAE7D,oCAAoC;QACpCF,OAAOI,mBAAmB,CAAChB,QAEzB,8BAA8B;SAC7BiB,MAAM,CAAC,CAACC,OAAS,CAACH,oBAAoBW,QAAQ,CAACR,MAEhD,6EAA6E;SAC5ED,MAAM,CAAC,CAACC,OAAS,CAAEG,CAAAA,cAAcA,WAAWM,OAAO,CAACT,UAAU,CAAC,CAAA,GAC/DD,MAAM,CAAC,CAACC;YACP,OAAQA;gBACN,KAAK;oBACH,OAAO;YACX;YACA,OAAO;QACT,EAEA,+CAA+C;SAC9CU,OAAO,CAAC,CAACV;YACR,8CAA8C;YAC9CN,OAAOiB,cAAc,CAAC5B,YAAYiB,MAAM;gBACtCY,cAAc;gBACdC,KAAK,IAAM/B,OAAM,CAACkB,KAAqB;YACzC;QACF;QAEF,OAAOlB;IACT;IAEAmB,WAAW;QAAEa,KAAK;IAAmB;IACrC,OAAO;AACT"}
1
+ {"version":3,"sources":["../../../src/server/polyfill/polyfillJsDom.ts"],"sourcesContent":["import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';\nimport { getGlobalThis } from '../../web/getGlobalThis';\n\nexport async function polyfillJsDom() {\n if (typeof window !== 'undefined') {\n return false;\n }\n\n const globalThis = getGlobalThis();\n\n const { ResourceLoader, JSDOM } = await import('jsdom');\n\n // https://github.com/lukechilds/window/blob/master/src/index.js\n // eslint-disable-next-line @typescript-eslint/no-extraneous-class\n class Window {\n constructor(opts: ResourceLoaderConstructorOptions & ConstructorOptions = {}) {\n const { proxy, strictSSL, userAgent, ...jsdomOpts } = opts;\n const resources = new ResourceLoader({\n proxy,\n strictSSL,\n userAgent,\n });\n return new JSDOM(\n '',\n Object.assign(jsdomOpts, {\n resources,\n }),\n ).window;\n }\n }\n\n // https://github.com/lukechilds/browser-env/blob/master/src/index.js\n // Default jsdom config.\n // These settings must override any custom settings to make sure we can iterate\n // over the window object.\n const defaultJsdomConfig = {\n // features: {\n // FetchExternalResources: false,\n // ProcessExternalResources: false,\n // },\n };\n // IIFE executed on import to return an array of global Node.js properties that\n // conflict with global browser properties.\n const protectedProperties = (() =>\n Object.getOwnPropertyNames(new Window(defaultJsdomConfig)).filter(\n (prop) => typeof globalThis[prop as keyof typeof globalThis] !== 'undefined',\n ))();\n\n function installEnv(...args: any[]) {\n // Sets up global browser environment\n // Extract options from args\n const properties = args.filter((arg: any) => Array.isArray(arg))[0];\n const userJsdomConfig = args.filter((arg: any) => !Array.isArray(arg))[0];\n\n // Create window object\n const window = new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig));\n\n // Get all global browser properties\n Object.getOwnPropertyNames(window)\n\n // Remove protected properties\n .filter((prop) => !protectedProperties.includes(prop))\n\n // If we're only applying specific required properties remove everything else\n .filter((prop) => !(properties && properties.indexOf(prop) === -1))\n .filter((prop) => {\n switch (prop) {\n case 'undefined':\n return false;\n }\n return true;\n })\n\n // Copy what's left to the Node.js global scope\n .forEach((prop) => {\n // console.debug(`define globalThis.${prop}`);\n Object.defineProperty(globalThis, prop, {\n configurable: true,\n get: () => window[prop as keyof Window] as any,\n });\n });\n\n return window;\n }\n\n installEnv({ url: 'http://localhost' });\n return true;\n}\n"],"names":["getGlobalThis","polyfillJsDom","window","globalThis","ResourceLoader","JSDOM","Window","constructor","opts","proxy","strictSSL","userAgent","jsdomOpts","resources","Object","assign","defaultJsdomConfig","protectedProperties","getOwnPropertyNames","filter","prop","installEnv","args","properties","arg","Array","isArray","userJsdomConfig","includes","indexOf","forEach","defineProperty","configurable","get","url"],"mappings":"AACA,SAASA,aAAa,QAAQ,0BAA0B;AAExD,OAAO,eAAeC;IACpB,IAAI,OAAOC,WAAW,aAAa;QACjC,OAAO;IACT;IAEA,MAAMC,aAAaH;IAEnB,MAAM,EAAEI,cAAc,EAAEC,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC;IAE/C,gEAAgE;IAChE,kEAAkE;IAClE,IAAA,AAAMC,SAAN,MAAMA;QACJC,YAAYC,OAA8D,CAAC,CAAC,CAAE;YAC5E,MAAM,EAAEC,KAAK,EAAEC,SAAS,EAAEC,SAAS,EAAE,GAAGC,WAAW,GAAGJ;YACtD,MAAMK,YAAY,IAAIT,eAAe;gBACnCK;gBACAC;gBACAC;YACF;YACA,OAAO,IAAIN,MACT,IACAS,OAAOC,MAAM,CAACH,WAAW;gBACvBC;YACF,IACAX,MAAM;QACV;IACF;IAEA,qEAAqE;IACrE,wBAAwB;IACxB,+EAA+E;IAC/E,0BAA0B;IAC1B,MAAMc,qBAAqB;IAK3B;IACA,+EAA+E;IAC/E,2CAA2C;IAC3C,MAAMC,sBAAsB,AAAC,CAAA,IAC3BH,OAAOI,mBAAmB,CAAC,IAAIZ,OAAOU,qBAAqBG,MAAM,CAC/D,CAACC,OAAS,OAAOjB,UAAU,CAACiB,KAAgC,KAAK,YACnE;IAEF,SAASC,WAAW,GAAGC,IAAW;QAChC,qCAAqC;QACrC,4BAA4B;QAC5B,MAAMC,aAAaD,KAAKH,MAAM,CAAC,CAACK,MAAaC,MAAMC,OAAO,CAACF,KAAK,CAAC,EAAE;QACnE,MAAMG,kBAAkBL,KAAKH,MAAM,CAAC,CAACK,MAAa,CAACC,MAAMC,OAAO,CAACF,KAAK,CAAC,EAAE;QAEzE,uBAAuB;QACvB,MAAMtB,UAAS,IAAII,OAAOQ,OAAOC,MAAM,CAAC,CAAC,GAAGY,iBAAiBX;QAE7D,oCAAoC;QACpCF,OAAOI,mBAAmB,CAAChB,QAEzB,8BAA8B;SAC7BiB,MAAM,CAAC,CAACC,OAAS,CAACH,oBAAoBW,QAAQ,CAACR,MAEhD,6EAA6E;SAC5ED,MAAM,CAAC,CAACC,OAAS,CAAEG,CAAAA,cAAcA,WAAWM,OAAO,CAACT,UAAU,CAAC,CAAA,GAC/DD,MAAM,CAAC,CAACC;YACP,OAAQA;gBACN,KAAK;oBACH,OAAO;YACX;YACA,OAAO;QACT,EAEA,+CAA+C;SAC9CU,OAAO,CAAC,CAACV;YACR,8CAA8C;YAC9CN,OAAOiB,cAAc,CAAC5B,YAAYiB,MAAM;gBACtCY,cAAc;gBACdC,KAAK,IAAM/B,OAAM,CAACkB,KAAqB;YACzC;QACF;QAEF,OAAOlB;IACT;IAEAmB,WAAW;QAAEa,KAAK;IAAmB;IACrC,OAAO;AACT"}
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../../runtime/getGlobalThis.js';
1
+ import { getGlobalThis } from '../../web/getGlobalThis.js';
2
2
  export function polyfillWebSocket(ws) {
3
3
  const globalThis = getGlobalThis();
4
4
  if ('WebSocket' in globalThis) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/polyfill/polyfillWebSocket.ts"],"sourcesContent":["import type { MaybePromise } from '../../asyncs/MaybePromise';\nimport { getGlobalThis } from '../../runtime/getGlobalThis';\n\nexport function polyfillWebSocket(ws: any): boolean;\nexport function polyfillWebSocket(ws?: undefined): Promise<boolean>;\nexport function polyfillWebSocket(ws?: any): MaybePromise<boolean> {\n const globalThis = getGlobalThis();\n if ('WebSocket' in globalThis) {\n return false;\n }\n if (ws && 'then' in ws) {\n return ws.then((v: any) => {\n return polyfillWebSocket(v?.default || v);\n });\n }\n if (ws) {\n const { WebSocket } = ws;\n Object.assign(globalThis, { WebSocket });\n }\n return import('ws').then((ws) => polyfillWebSocket(ws));\n}\n"],"names":["getGlobalThis","polyfillWebSocket","ws","globalThis","then","v","default","WebSocket","Object","assign"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AACA,SAASA,aAAa,QAAQ,8BAA8B;AAI5D,OAAO,SAASC,kBAAkBC,EAAQ;IACxC,MAAMC,aAAaH;IACnB,IAAI,eAAeG,YAAY;QAC7B,OAAO;IACT;IACA,IAAID,MAAM,UAAUA,IAAI;QACtB,OAAOA,GAAGE,IAAI,CAAC,CAACC;YACd,OAAOJ,kBAAkBI,GAAGC,WAAWD;QACzC;IACF;IACA,IAAIH,IAAI;QACN,MAAM,EAAEK,SAAS,EAAE,GAAGL;QACtBM,OAAOC,MAAM,CAACN,YAAY;YAAEI;QAAU;IACxC;IACA,OAAO,MAAM,CAAC,MAAMH,IAAI,CAAC,CAACF,KAAOD,kBAAkBC;AACrD"}
1
+ {"version":3,"sources":["../../../src/server/polyfill/polyfillWebSocket.ts"],"sourcesContent":["import type { MaybePromise } from '../../asyncs/MaybePromise';\nimport { getGlobalThis } from '../../web/getGlobalThis';\n\nexport function polyfillWebSocket(ws: any): boolean;\nexport function polyfillWebSocket(ws?: undefined): Promise<boolean>;\nexport function polyfillWebSocket(ws?: any): MaybePromise<boolean> {\n const globalThis = getGlobalThis();\n if ('WebSocket' in globalThis) {\n return false;\n }\n if (ws && 'then' in ws) {\n return ws.then((v: any) => {\n return polyfillWebSocket(v?.default || v);\n });\n }\n if (ws) {\n const { WebSocket } = ws;\n Object.assign(globalThis, { WebSocket });\n }\n return import('ws').then((ws) => polyfillWebSocket(ws));\n}\n"],"names":["getGlobalThis","polyfillWebSocket","ws","globalThis","then","v","default","WebSocket","Object","assign"],"mappings":"AACA,SAASA,aAAa,QAAQ,0BAA0B;AAIxD,OAAO,SAASC,kBAAkBC,EAAQ;IACxC,MAAMC,aAAaH;IACnB,IAAI,eAAeG,YAAY;QAC7B,OAAO;IACT;IACA,IAAID,MAAM,UAAUA,IAAI;QACtB,OAAOA,GAAGE,IAAI,CAAC,CAACC;YACd,OAAOJ,kBAAkBI,GAAGC,WAAWD;QACzC;IACF;IACA,IAAIH,IAAI;QACN,MAAM,EAAEK,SAAS,EAAE,GAAGL;QACtBM,OAAOC,MAAM,CAACN,YAAY;YAAEI;QAAU;IACxC;IACA,OAAO,MAAM,CAAC,MAAMH,IAAI,CAAC,CAACF,KAAOD,kBAAkBC;AACrD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/server/ws.ts"],"sourcesContent":["export * from './polyfill/polyfillWebSocket';\n"],"names":[],"rangeMappings":"","mappings":"AAAA,cAAc,+BAA+B"}
1
+ {"version":3,"sources":["../../src/server/ws.ts"],"sourcesContent":["export * from './polyfill/polyfillWebSocket';\n"],"names":[],"mappings":"AAAA,cAAc,+BAA+B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/strings/camelCase.ts"],"sourcesContent":["// https://github.com/sindresorhus/camelcase/blob/master/index.js\n\nfunction preserveCamelCase(string: string) {\n let isLastCharLower = false;\n let isLastCharUpper = false;\n let isLastLastCharUpper = false;\n\n for (let i = 0; i < string.length; i++) {\n const character = string[i];\n\n if (isLastCharLower && /[a-zA-Z]/.test(character) && character.toUpperCase() === character) {\n string = string.slice(0, i) + '-' + string.slice(i);\n isLastCharLower = false;\n isLastLastCharUpper = isLastCharUpper;\n isLastCharUpper = true;\n i++;\n } else if (\n isLastCharUpper &&\n isLastLastCharUpper &&\n /[a-zA-Z]/.test(character) &&\n character.toLowerCase() === character\n ) {\n string = string.slice(0, i - 1) + '-' + string.slice(i - 1);\n isLastLastCharUpper = isLastCharUpper;\n isLastCharUpper = false;\n isLastCharLower = true;\n } else {\n isLastCharLower = character.toLowerCase() === character && character.toUpperCase() !== character;\n isLastLastCharUpper = isLastCharUpper;\n isLastCharUpper = character.toUpperCase() === character && character.toLowerCase() !== character;\n }\n }\n\n return string;\n}\n\nexport function pascalCase(input: string | string[]) {\n return camelCase(input, { pascalCase: true });\n}\n\nexport function camelCase(\n input: string | string[],\n options: { pascalCase: boolean } = {\n pascalCase: false,\n },\n) {\n if (!(typeof input === 'string' || Array.isArray(input))) {\n throw new TypeError('Expected the input to be `string | string[]`');\n }\n\n const postProcess = (x: string) => (options.pascalCase ? x.charAt(0).toUpperCase() + x.slice(1) : x);\n\n if (Array.isArray(input)) {\n input = input\n .map((x) => x.trim())\n .filter((x) => x.length)\n .join('-');\n } else {\n input = input.trim();\n }\n\n if (input.length === 0) {\n return '';\n }\n\n if (input.length === 1) {\n return options.pascalCase ? input.toUpperCase() : input.toLowerCase();\n }\n\n const hasUpperCase = input !== input.toLowerCase();\n\n if (hasUpperCase) {\n input = preserveCamelCase(input);\n }\n\n input = input\n .replace(/^[_.\\- ]+/, '')\n .toLowerCase()\n .replace(/[_.\\- ]+(\\w|$)/g, (_, p1) => p1.toUpperCase())\n .replace(/\\d+(\\w|$)/g, (m) => m.toUpperCase());\n\n return postProcess(input);\n}\n"],"names":["preserveCamelCase","string","isLastCharLower","isLastCharUpper","isLastLastCharUpper","i","length","character","test","toUpperCase","slice","toLowerCase","pascalCase","input","camelCase","options","Array","isArray","TypeError","postProcess","x","charAt","map","trim","filter","join","hasUpperCase","replace","_","p1","m"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,iEAAiE;AAEjE,SAASA,kBAAkBC,MAAc;IACvC,IAAIC,kBAAkB;IACtB,IAAIC,kBAAkB;IACtB,IAAIC,sBAAsB;IAE1B,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,OAAOK,MAAM,EAAED,IAAK;QACtC,MAAME,YAAYN,MAAM,CAACI,EAAE;QAE3B,IAAIH,mBAAmB,WAAWM,IAAI,CAACD,cAAcA,UAAUE,WAAW,OAAOF,WAAW;YAC1FN,SAASA,OAAOS,KAAK,CAAC,GAAGL,KAAK,MAAMJ,OAAOS,KAAK,CAACL;YACjDH,kBAAkB;YAClBE,sBAAsBD;YACtBA,kBAAkB;YAClBE;QACF,OAAO,IACLF,mBACAC,uBACA,WAAWI,IAAI,CAACD,cAChBA,UAAUI,WAAW,OAAOJ,WAC5B;YACAN,SAASA,OAAOS,KAAK,CAAC,GAAGL,IAAI,KAAK,MAAMJ,OAAOS,KAAK,CAACL,IAAI;YACzDD,sBAAsBD;YACtBA,kBAAkB;YAClBD,kBAAkB;QACpB,OAAO;YACLA,kBAAkBK,UAAUI,WAAW,OAAOJ,aAAaA,UAAUE,WAAW,OAAOF;YACvFH,sBAAsBD;YACtBA,kBAAkBI,UAAUE,WAAW,OAAOF,aAAaA,UAAUI,WAAW,OAAOJ;QACzF;IACF;IAEA,OAAON;AACT;AAEA,OAAO,SAASW,WAAWC,KAAwB;IACjD,OAAOC,UAAUD,OAAO;QAAED,YAAY;IAAK;AAC7C;AAEA,OAAO,SAASE,UACdD,KAAwB,EACxBE,UAAmC;IACjCH,YAAY;AACd,CAAC;IAED,IAAI,CAAE,CAAA,OAAOC,UAAU,YAAYG,MAAMC,OAAO,CAACJ,MAAK,GAAI;QACxD,MAAM,IAAIK,UAAU;IACtB;IAEA,MAAMC,cAAc,CAACC,IAAeL,QAAQH,UAAU,GAAGQ,EAAEC,MAAM,CAAC,GAAGZ,WAAW,KAAKW,EAAEV,KAAK,CAAC,KAAKU;IAElG,IAAIJ,MAAMC,OAAO,CAACJ,QAAQ;QACxBA,QAAQA,MACLS,GAAG,CAAC,CAACF,IAAMA,EAAEG,IAAI,IACjBC,MAAM,CAAC,CAACJ,IAAMA,EAAEd,MAAM,EACtBmB,IAAI,CAAC;IACV,OAAO;QACLZ,QAAQA,MAAMU,IAAI;IACpB;IAEA,IAAIV,MAAMP,MAAM,KAAK,GAAG;QACtB,OAAO;IACT;IAEA,IAAIO,MAAMP,MAAM,KAAK,GAAG;QACtB,OAAOS,QAAQH,UAAU,GAAGC,MAAMJ,WAAW,KAAKI,MAAMF,WAAW;IACrE;IAEA,MAAMe,eAAeb,UAAUA,MAAMF,WAAW;IAEhD,IAAIe,cAAc;QAChBb,QAAQb,kBAAkBa;IAC5B;IAEAA,QAAQA,MACLc,OAAO,CAAC,aAAa,IACrBhB,WAAW,GACXgB,OAAO,CAAC,mBAAmB,CAACC,GAAGC,KAAOA,GAAGpB,WAAW,IACpDkB,OAAO,CAAC,cAAc,CAACG,IAAMA,EAAErB,WAAW;IAE7C,OAAOU,YAAYN;AACrB"}
1
+ {"version":3,"sources":["../../src/strings/camelCase.ts"],"sourcesContent":["// https://github.com/sindresorhus/camelcase/blob/master/index.js\n\nfunction preserveCamelCase(string: string) {\n let isLastCharLower = false;\n let isLastCharUpper = false;\n let isLastLastCharUpper = false;\n\n for (let i = 0; i < string.length; i++) {\n const character = string[i];\n\n if (isLastCharLower && /[a-zA-Z]/.test(character) && character.toUpperCase() === character) {\n string = string.slice(0, i) + '-' + string.slice(i);\n isLastCharLower = false;\n isLastLastCharUpper = isLastCharUpper;\n isLastCharUpper = true;\n i++;\n } else if (\n isLastCharUpper &&\n isLastLastCharUpper &&\n /[a-zA-Z]/.test(character) &&\n character.toLowerCase() === character\n ) {\n string = string.slice(0, i - 1) + '-' + string.slice(i - 1);\n isLastLastCharUpper = isLastCharUpper;\n isLastCharUpper = false;\n isLastCharLower = true;\n } else {\n isLastCharLower = character.toLowerCase() === character && character.toUpperCase() !== character;\n isLastLastCharUpper = isLastCharUpper;\n isLastCharUpper = character.toUpperCase() === character && character.toLowerCase() !== character;\n }\n }\n\n return string;\n}\n\nexport function pascalCase(input: string | string[]) {\n return camelCase(input, { pascalCase: true });\n}\n\nexport function camelCase(\n input: string | string[],\n options: { pascalCase: boolean } = {\n pascalCase: false,\n },\n) {\n if (!(typeof input === 'string' || Array.isArray(input))) {\n throw new TypeError('Expected the input to be `string | string[]`');\n }\n\n const postProcess = (x: string) => (options.pascalCase ? x.charAt(0).toUpperCase() + x.slice(1) : x);\n\n if (Array.isArray(input)) {\n input = input\n .map((x) => x.trim())\n .filter((x) => x.length)\n .join('-');\n } else {\n input = input.trim();\n }\n\n if (input.length === 0) {\n return '';\n }\n\n if (input.length === 1) {\n return options.pascalCase ? input.toUpperCase() : input.toLowerCase();\n }\n\n const hasUpperCase = input !== input.toLowerCase();\n\n if (hasUpperCase) {\n input = preserveCamelCase(input);\n }\n\n input = input\n .replace(/^[_.\\- ]+/, '')\n .toLowerCase()\n .replace(/[_.\\- ]+(\\w|$)/g, (_, p1) => p1.toUpperCase())\n .replace(/\\d+(\\w|$)/g, (m) => m.toUpperCase());\n\n return postProcess(input);\n}\n"],"names":["preserveCamelCase","string","isLastCharLower","isLastCharUpper","isLastLastCharUpper","i","length","character","test","toUpperCase","slice","toLowerCase","pascalCase","input","camelCase","options","Array","isArray","TypeError","postProcess","x","charAt","map","trim","filter","join","hasUpperCase","replace","_","p1","m"],"mappings":"AAAA,iEAAiE;AAEjE,SAASA,kBAAkBC,MAAc;IACvC,IAAIC,kBAAkB;IACtB,IAAIC,kBAAkB;IACtB,IAAIC,sBAAsB;IAE1B,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,OAAOK,MAAM,EAAED,IAAK;QACtC,MAAME,YAAYN,MAAM,CAACI,EAAE;QAE3B,IAAIH,mBAAmB,WAAWM,IAAI,CAACD,cAAcA,UAAUE,WAAW,OAAOF,WAAW;YAC1FN,SAASA,OAAOS,KAAK,CAAC,GAAGL,KAAK,MAAMJ,OAAOS,KAAK,CAACL;YACjDH,kBAAkB;YAClBE,sBAAsBD;YACtBA,kBAAkB;YAClBE;QACF,OAAO,IACLF,mBACAC,uBACA,WAAWI,IAAI,CAACD,cAChBA,UAAUI,WAAW,OAAOJ,WAC5B;YACAN,SAASA,OAAOS,KAAK,CAAC,GAAGL,IAAI,KAAK,MAAMJ,OAAOS,KAAK,CAACL,IAAI;YACzDD,sBAAsBD;YACtBA,kBAAkB;YAClBD,kBAAkB;QACpB,OAAO;YACLA,kBAAkBK,UAAUI,WAAW,OAAOJ,aAAaA,UAAUE,WAAW,OAAOF;YACvFH,sBAAsBD;YACtBA,kBAAkBI,UAAUE,WAAW,OAAOF,aAAaA,UAAUI,WAAW,OAAOJ;QACzF;IACF;IAEA,OAAON;AACT;AAEA,OAAO,SAASW,WAAWC,KAAwB;IACjD,OAAOC,UAAUD,OAAO;QAAED,YAAY;IAAK;AAC7C;AAEA,OAAO,SAASE,UACdD,KAAwB,EACxBE,UAAmC;IACjCH,YAAY;AACd,CAAC;IAED,IAAI,CAAE,CAAA,OAAOC,UAAU,YAAYG,MAAMC,OAAO,CAACJ,MAAK,GAAI;QACxD,MAAM,IAAIK,UAAU;IACtB;IAEA,MAAMC,cAAc,CAACC,IAAeL,QAAQH,UAAU,GAAGQ,EAAEC,MAAM,CAAC,GAAGZ,WAAW,KAAKW,EAAEV,KAAK,CAAC,KAAKU;IAElG,IAAIJ,MAAMC,OAAO,CAACJ,QAAQ;QACxBA,QAAQA,MACLS,GAAG,CAAC,CAACF,IAAMA,EAAEG,IAAI,IACjBC,MAAM,CAAC,CAACJ,IAAMA,EAAEd,MAAM,EACtBmB,IAAI,CAAC;IACV,OAAO;QACLZ,QAAQA,MAAMU,IAAI;IACpB;IAEA,IAAIV,MAAMP,MAAM,KAAK,GAAG;QACtB,OAAO;IACT;IAEA,IAAIO,MAAMP,MAAM,KAAK,GAAG;QACtB,OAAOS,QAAQH,UAAU,GAAGC,MAAMJ,WAAW,KAAKI,MAAMF,WAAW;IACrE;IAEA,MAAMe,eAAeb,UAAUA,MAAMF,WAAW;IAEhD,IAAIe,cAAc;QAChBb,QAAQb,kBAAkBa;IAC5B;IAEAA,QAAQA,MACLc,OAAO,CAAC,aAAa,IACrBhB,WAAW,GACXgB,OAAO,CAAC,mBAAmB,CAACC,GAAGC,KAAOA,GAAGpB,WAAW,IACpDkB,OAAO,CAAC,cAAc,CAACG,IAAMA,EAAErB,WAAW;IAE7C,OAAOU,YAAYN;AACrB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/strings/formatBytes.ts"],"sourcesContent":["/**\n * Format bytes as human-readable text.\n *\n * @param bytes Number of bytes.\n * @param si True to use metric (SI) units, aka powers of 1000. False to use\n * binary (IEC), aka powers of 1024.\n * @param dp Number of decimal places to display.\n *\n * @return Formatted string.\n */\nexport function formatBytes(bytes: number, si = false, dp = 1) {\n const thresh = si ? 1000 : 1024;\n\n if (Math.abs(bytes) < thresh) {\n return `${bytes} B`;\n }\n\n const units = si\n ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']\n : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];\n let u = -1;\n const r = 10 ** dp;\n\n do {\n bytes /= thresh;\n ++u;\n } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);\n\n return bytes.toFixed(dp) + ' ' + units[u];\n}\n"],"names":["formatBytes","bytes","si","dp","thresh","Math","abs","units","u","r","round","length","toFixed"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;;;;;;;;;CASC,GACD,OAAO,SAASA,YAAYC,KAAa,EAAEC,KAAK,KAAK,EAAEC,KAAK,CAAC;IAC3D,MAAMC,SAASF,KAAK,OAAO;IAE3B,IAAIG,KAAKC,GAAG,CAACL,SAASG,QAAQ;QAC5B,OAAO,CAAC,EAAEH,MAAM,EAAE,CAAC;IACrB;IAEA,MAAMM,QAAQL,KACV;QAAC;QAAM;QAAM;QAAM;QAAM;QAAM;QAAM;QAAM;KAAK,GAChD;QAAC;QAAO;QAAO;QAAO;QAAO;QAAO;QAAO;QAAO;KAAM;IAC5D,IAAIM,IAAI,CAAC;IACT,MAAMC,IAAI,MAAMN;IAEhB,GAAG;QACDF,SAASG;QACT,EAAEI;IACJ,QAASH,KAAKK,KAAK,CAACL,KAAKC,GAAG,CAACL,SAASQ,KAAKA,KAAKL,UAAUI,IAAID,MAAMI,MAAM,GAAG,EAAG;IAEhF,OAAOV,MAAMW,OAAO,CAACT,MAAM,MAAMI,KAAK,CAACC,EAAE;AAC3C"}
1
+ {"version":3,"sources":["../../src/strings/formatBytes.ts"],"sourcesContent":["/**\n * Format bytes as human-readable text.\n *\n * @param bytes Number of bytes.\n * @param si True to use metric (SI) units, aka powers of 1000. False to use\n * binary (IEC), aka powers of 1024.\n * @param dp Number of decimal places to display.\n *\n * @return Formatted string.\n */\nexport function formatBytes(bytes: number, si = false, dp = 1) {\n const thresh = si ? 1000 : 1024;\n\n if (Math.abs(bytes) < thresh) {\n return `${bytes} B`;\n }\n\n const units = si\n ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']\n : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];\n let u = -1;\n const r = 10 ** dp;\n\n do {\n bytes /= thresh;\n ++u;\n } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);\n\n return bytes.toFixed(dp) + ' ' + units[u];\n}\n"],"names":["formatBytes","bytes","si","dp","thresh","Math","abs","units","u","r","round","length","toFixed"],"mappings":"AAAA;;;;;;;;;CASC,GACD,OAAO,SAASA,YAAYC,KAAa,EAAEC,KAAK,KAAK,EAAEC,KAAK,CAAC;IAC3D,MAAMC,SAASF,KAAK,OAAO;IAE3B,IAAIG,KAAKC,GAAG,CAACL,SAASG,QAAQ;QAC5B,OAAO,GAAGH,MAAM,EAAE,CAAC;IACrB;IAEA,MAAMM,QAAQL,KACV;QAAC;QAAM;QAAM;QAAM;QAAM;QAAM;QAAM;QAAM;KAAK,GAChD;QAAC;QAAO;QAAO;QAAO;QAAO;QAAO;QAAO;QAAO;KAAM;IAC5D,IAAIM,IAAI,CAAC;IACT,MAAMC,IAAI,MAAMN;IAEhB,GAAG;QACDF,SAASG;QACT,EAAEI;IACJ,QAASH,KAAKK,KAAK,CAACL,KAAKC,GAAG,CAACL,SAASQ,KAAKA,KAAKL,UAAUI,IAAID,MAAMI,MAAM,GAAG,EAAG;IAEhF,OAAOV,MAAMW,OAAO,CAACT,MAAM,MAAMI,KAAK,CAACC,EAAE;AAC3C"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/strings/renderTemplate.ts"],"sourcesContent":["import { get } from '../objects/get';\n\n/**\n * render template like js template string\n *\n * @example\n * renderTemplate('My name is ${name}',{name:'wener'})\n * // 'My name is wener'\n *\n * @param match `js` for `${name}`, common for `{{name}}`\n */\nexport function renderTemplate(\n template: string,\n data: ((v: string) => any) | object | undefined,\n match: 'js' | 'common' | RegExp = 'js',\n) {\n let getter: Function;\n if (!data) {\n // todo warning in dev\n getter = () => '';\n } else if (typeof data === 'function') {\n getter = data;\n } else {\n getter = (v: string) => get(data, v);\n }\n if (typeof match === 'string') {\n match = Matches[match] || Matches.js;\n }\n return template.replace(match, (_, g) => {\n return getter(g.trim());\n });\n}\n\nconst Matches: Record<string, RegExp> = {\n js: /\\${(.*?)}/g,\n common: /{{(.*?)}}/g,\n};\n"],"names":["get","renderTemplate","template","data","match","getter","v","Matches","js","replace","_","g","trim","common"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,GAAG,QAAQ,iBAAiB;AAErC;;;;;;;;CAQC,GACD,OAAO,SAASC,eACdC,QAAgB,EAChBC,IAA+C,EAC/CC,QAAkC,IAAI;IAEtC,IAAIC;IACJ,IAAI,CAACF,MAAM;QACT,sBAAsB;QACtBE,SAAS,IAAM;IACjB,OAAO,IAAI,OAAOF,SAAS,YAAY;QACrCE,SAASF;IACX,OAAO;QACLE,SAAS,CAACC,IAAcN,IAAIG,MAAMG;IACpC;IACA,IAAI,OAAOF,UAAU,UAAU;QAC7BA,QAAQG,OAAO,CAACH,MAAM,IAAIG,QAAQC,EAAE;IACtC;IACA,OAAON,SAASO,OAAO,CAACL,OAAO,CAACM,GAAGC;QACjC,OAAON,OAAOM,EAAEC,IAAI;IACtB;AACF;AAEA,MAAML,UAAkC;IACtCC,IAAI;IACJK,QAAQ;AACV"}
1
+ {"version":3,"sources":["../../src/strings/renderTemplate.ts"],"sourcesContent":["import { get } from '../objects/get';\n\n/**\n * render template like js template string\n *\n * @example\n * renderTemplate('My name is ${name}',{name:'wener'})\n * // 'My name is wener'\n *\n * @param match `js` for `${name}`, common for `{{name}}`\n */\nexport function renderTemplate(\n template: string,\n data: ((v: string) => any) | object | undefined,\n match: 'js' | 'common' | RegExp = 'js',\n) {\n let getter: Function;\n if (!data) {\n // todo warning in dev\n getter = () => '';\n } else if (typeof data === 'function') {\n getter = data;\n } else {\n getter = (v: string) => get(data, v);\n }\n if (typeof match === 'string') {\n match = Matches[match] || Matches.js;\n }\n return template.replace(match, (_, g) => {\n return getter(g.trim());\n });\n}\n\nconst Matches: Record<string, RegExp> = {\n js: /\\${(.*?)}/g,\n common: /{{(.*?)}}/g,\n};\n"],"names":["get","renderTemplate","template","data","match","getter","v","Matches","js","replace","_","g","trim","common"],"mappings":"AAAA,SAASA,GAAG,QAAQ,iBAAiB;AAErC;;;;;;;;CAQC,GACD,OAAO,SAASC,eACdC,QAAgB,EAChBC,IAA+C,EAC/CC,QAAkC,IAAI;IAEtC,IAAIC;IACJ,IAAI,CAACF,MAAM;QACT,sBAAsB;QACtBE,SAAS,IAAM;IACjB,OAAO,IAAI,OAAOF,SAAS,YAAY;QACrCE,SAASF;IACX,OAAO;QACLE,SAAS,CAACC,IAAcN,IAAIG,MAAMG;IACpC;IACA,IAAI,OAAOF,UAAU,UAAU;QAC7BA,QAAQG,OAAO,CAACH,MAAM,IAAIG,QAAQC,EAAE;IACtC;IACA,OAAON,SAASO,OAAO,CAACL,OAAO,CAACM,GAAGC;QACjC,OAAON,OAAOM,EAAEC,IAAI;IACtB;AACF;AAEA,MAAML,UAAkC;IACtCC,IAAI;IACJK,QAAQ;AACV"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/typedoc.ts"],"sourcesContent":["export * from './index';\n// fixme md5 conflict\n// export * from './server';\n"],"names":[],"rangeMappings":";","mappings":"AAAA,cAAc,UAAU,CACxB,qBAAqB;CACrB,4BAA4B"}
1
+ {"version":3,"sources":["../src/typedoc.ts"],"sourcesContent":["export * from './index';\n// fixme md5 conflict\n// export * from './server';\n"],"names":[],"mappings":"AAAA,cAAc,UAAU,CACxB,qBAAqB;CACrB,4BAA4B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.d.ts"],"sourcesContent":["declare var __DEV__: boolean;\n\nnamespace NodeJS {\n interface Process {\n // webpack check\n readonly browser?: boolean;\n }\n interface ProcessEnv {\n readonly NODE_ENV: 'development' | 'production' | 'test';\n }\n}\n\nexport type AbstractConstructor<T = {}> = abstract new (...args: any[]) => T;\nexport type Constructor<T = {}> = new (...args: any[]) => T;\nexport type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\nexport type PartialRequired<T, K extends keyof T> = Partial<Omit<T, K>> & Required<Pick<T, K>>;\n\n/*\nhttps://github.com/total-typescript/ts-reset/blob/main/src/entrypoints/filter-boolean.d.ts\nhttps://github.com/sindresorhus/type-fest\n */\n"],"names":[],"rangeMappings":";;;","mappings":"AAeA,WAA+F,CAE/F;;;CAGC"}
1
+ {"version":3,"sources":["../src/types.d.ts"],"sourcesContent":["declare var __DEV__: boolean;\n\nnamespace NodeJS {\n interface Process {\n // webpack check\n readonly browser?: boolean;\n }\n interface ProcessEnv {\n readonly NODE_ENV: 'development' | 'production' | 'test';\n }\n}\n\nexport type AbstractConstructor<T = {}> = abstract new (...args: any[]) => T;\nexport type Constructor<T = {}> = new (...args: any[]) => T;\nexport type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\nexport type PartialRequired<T, K extends keyof T> = Partial<Omit<T, K>> & Required<Pick<T, K>>;\n\n/*\nhttps://github.com/total-typescript/ts-reset/blob/main/src/entrypoints/filter-boolean.d.ts\nhttps://github.com/sindresorhus/type-fest\n */\n"],"names":[],"mappings":"AAeA,WAA+F,CAE/F;;;CAGC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/validations/asserts.ts"],"sourcesContent":["export function assert(condition: any, msg?: string): asserts condition {\n // if (!condition) {\n // throw new AssertionError(msg);\n // }\n console.assert(!condition, msg);\n}\n\nexport function assertIsDefined<T>(val: T): asserts val is NonNullable<T> {\n // if (val === undefined || val === null) {\n // throw new AssertionError(`Expected 'val' to be defined, but received ${val}`);\n // }\n console.assert(val === undefined || val === null, 'Expected defined');\n}\n"],"names":["assert","condition","msg","console","assertIsDefined","val","undefined"],"rangeMappings":";;;;;;;;;;;","mappings":"AAAA,OAAO,SAASA,OAAOC,SAAc,EAAEC,GAAY;IACjD,oBAAoB;IACpB,mCAAmC;IACnC,IAAI;IACJC,QAAQH,MAAM,CAAC,CAACC,WAAWC;AAC7B;AAEA,OAAO,SAASE,gBAAmBC,GAAM;IACvC,2CAA2C;IAC3C,mFAAmF;IACnF,IAAI;IACJF,QAAQH,MAAM,CAACK,QAAQC,aAAaD,QAAQ,MAAM;AACpD"}
1
+ {"version":3,"sources":["../../src/validations/asserts.ts"],"sourcesContent":["export function assert(condition: any, msg?: string): asserts condition {\n // if (!condition) {\n // throw new AssertionError(msg);\n // }\n console.assert(!condition, msg);\n}\n\nexport function assertIsDefined<T>(val: T): asserts val is NonNullable<T> {\n // if (val === undefined || val === null) {\n // throw new AssertionError(`Expected 'val' to be defined, but received ${val}`);\n // }\n console.assert(val === undefined || val === null, 'Expected defined');\n}\n"],"names":["assert","condition","msg","console","assertIsDefined","val","undefined"],"mappings":"AAAA,OAAO,SAASA,OAAOC,SAAc,EAAEC,GAAY;IACjD,oBAAoB;IACpB,mCAAmC;IACnC,IAAI;IACJC,QAAQH,MAAM,CAAC,CAACC,WAAWC;AAC7B;AAEA,OAAO,SAASE,gBAAmBC,GAAM;IACvC,2CAA2C;IAC3C,mFAAmF;IACnF,IAAI;IACJF,QAAQH,MAAM,CAACK,QAAQC,aAAaD,QAAQ,MAAM;AACpD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/validations/isUUID.ts"],"sourcesContent":["export function isUUID(str: string | undefined | null) {\n return Boolean(str) && /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(String(str));\n}\n"],"names":["isUUID","str","Boolean","test","String"],"rangeMappings":";;","mappings":"AAAA,OAAO,SAASA,OAAOC,GAA8B;IACnD,OAAOC,QAAQD,QAAQ,yEAAyEE,IAAI,CAACC,OAAOH;AAC9G"}
1
+ {"version":3,"sources":["../../src/validations/isUUID.ts"],"sourcesContent":["export function isUUID(str: string | undefined | null) {\n return Boolean(str) && /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(String(str));\n}\n"],"names":["isUUID","str","Boolean","test","String"],"mappings":"AAAA,OAAO,SAASA,OAAOC,GAA8B;IACnD,OAAOC,QAAQD,QAAQ,yEAAyEE,IAAI,CAACC,OAAOH;AAC9G"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/validations/parseTimestamp.ts"],"sourcesContent":["export function parseTimestamp(raw?: string | number | Date): Date | undefined {\n if (!raw) {\n return undefined;\n }\n if (raw instanceof Date) {\n return raw;\n }\n\n if (typeof raw === 'string' && /^[0-9.]+$/.test(raw)) {\n let n = parseFloat(raw);\n const len = Math.floor(n).toString().length;\n /*\n 最常见的是 10 位和 13 位\n 9999999999 - 10*9 - 1970-04-26\n 99999999999 - 11*9 - 1973\n 999999999999 - 12*9 - 2001\n */\n if (len <= 11) {\n n *= 1000;\n }\n return new Date(n);\n } else if (typeof raw === 'string') {\n const date = new Date(raw);\n if (!isNaN(+date)) {\n return date;\n }\n }\n throw new Error(`parseTimestamp: invalid \"${raw}\"`);\n}\n"],"names":["parseTimestamp","raw","undefined","Date","test","n","parseFloat","len","Math","floor","toString","length","date","isNaN","Error"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAO,SAASA,eAAeC,GAA4B;IACzD,IAAI,CAACA,KAAK;QACR,OAAOC;IACT;IACA,IAAID,eAAeE,MAAM;QACvB,OAAOF;IACT;IAEA,IAAI,OAAOA,QAAQ,YAAY,YAAYG,IAAI,CAACH,MAAM;QACpD,IAAII,IAAIC,WAAWL;QACnB,MAAMM,MAAMC,KAAKC,KAAK,CAACJ,GAAGK,QAAQ,GAAGC,MAAM;QAC3C;;;;;KAKC,GACD,IAAIJ,OAAO,IAAI;YACbF,KAAK;QACP;QACA,OAAO,IAAIF,KAAKE;IAClB,OAAO,IAAI,OAAOJ,QAAQ,UAAU;QAClC,MAAMW,OAAO,IAAIT,KAAKF;QACtB,IAAI,CAACY,MAAM,CAACD,OAAO;YACjB,OAAOA;QACT;IACF;IACA,MAAM,IAAIE,MAAM,CAAC,yBAAyB,EAAEb,IAAI,CAAC,CAAC;AACpD"}
1
+ {"version":3,"sources":["../../src/validations/parseTimestamp.ts"],"sourcesContent":["export function parseTimestamp(raw?: string | number | Date): Date | undefined {\n if (!raw) {\n return undefined;\n }\n if (raw instanceof Date) {\n return raw;\n }\n\n if (typeof raw === 'string' && /^[0-9.]+$/.test(raw)) {\n let n = parseFloat(raw);\n const len = Math.floor(n).toString().length;\n /*\n 最常见的是 10 位和 13 位\n 9999999999 - 10*9 - 1970-04-26\n 99999999999 - 11*9 - 1973\n 999999999999 - 12*9 - 2001\n */\n if (len <= 11) {\n n *= 1000;\n }\n return new Date(n);\n } else if (typeof raw === 'string') {\n const date = new Date(raw);\n if (!isNaN(+date)) {\n return date;\n }\n }\n throw new Error(`parseTimestamp: invalid \"${raw}\"`);\n}\n"],"names":["parseTimestamp","raw","undefined","Date","test","n","parseFloat","len","Math","floor","toString","length","date","isNaN","Error"],"mappings":"AAAA,OAAO,SAASA,eAAeC,GAA4B;IACzD,IAAI,CAACA,KAAK;QACR,OAAOC;IACT;IACA,IAAID,eAAeE,MAAM;QACvB,OAAOF;IACT;IAEA,IAAI,OAAOA,QAAQ,YAAY,YAAYG,IAAI,CAACH,MAAM;QACpD,IAAII,IAAIC,WAAWL;QACnB,MAAMM,MAAMC,KAAKC,KAAK,CAACJ,GAAGK,QAAQ,GAAGC,MAAM;QAC3C;;;;;KAKC,GACD,IAAIJ,OAAO,IAAI;YACbF,KAAK;QACP;QACA,OAAO,IAAIF,KAAKE;IAClB,OAAO,IAAI,OAAOJ,QAAQ,UAAU;QAClC,MAAMW,OAAO,IAAIT,KAAKF;QACtB,IAAI,CAACY,MAAM,CAACD,OAAO;YACjB,OAAOA;QACT;IACF;IACA,MAAM,IAAIE,MAAM,CAAC,yBAAyB,EAAEb,IAAI,CAAC,CAAC;AACpD"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/web/getGlobalThis.ts"],"sourcesContent":["declare const global: typeof globalThis;\n\n/**\n * isomorphic globalThis\n *\n * globalThis supported by ff 65, Chrome 71, Node 12, babel\n *\n * non-standard globalThis supported for Alipay Miniprogram\n *\n * @see https://caniuse.com/#search=globalThis\n * @see https://v8.dev/features/globalthis\n */\nexport const getGlobalThis = (): typeof globalThis => {\n if (typeof globalThis !== 'undefined') return globalThis;\n if (typeof self !== 'undefined') return self;\n if (typeof window !== 'undefined') return window;\n if (typeof global !== 'undefined') return global as any;\n if (typeof this !== 'undefined') return this as any;\n throw new Error('Unable to locate global `this`');\n};\n"],"names":["getGlobalThis","globalThis","self","window","global","Error"],"mappings":"AAEA;;;;;;;;;CASC,GACD,OAAO,MAAMA,gBAAgB;IAC3B,IAAI,OAAOC,eAAe,aAAa,OAAOA;IAC9C,IAAI,OAAOC,SAAS,aAAa,OAAOA;IACxC,IAAI,OAAOC,WAAW,aAAa,OAAOA;IAC1C,IAAI,OAAOC,WAAW,aAAa,OAAOA;IAC1C,IAAI,OAAO,IAAI,KAAK,aAAa,OAAO,IAAI;IAC5C,MAAM,IAAIC,MAAM;AAClB,EAAE"}
@@ -1,6 +1,6 @@
1
1
  // eslint-disable-next-line @typescript-eslint/consistent-type-imports
2
- import { getGlobalThis } from '../runtime/getGlobalThis.js';
3
- import { getNodeCrypto } from './getNodeCrypto.js';
2
+ import { getNodeCrypto } from '../crypto/getNodeCrypto.js';
3
+ import { getGlobalThis } from './getGlobalThis.js';
4
4
  const globalThis = getGlobalThis();
5
5
  // chrome 11+, safari 5+, nodejs 17.4+
6
6
  // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/web/getRandomValues.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { getNodeCrypto } from '../crypto/getNodeCrypto';\nimport type { TypedArray } from '../io/ArrayBuffers';\nimport { getGlobalThis } from './getGlobalThis';\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":["getNodeCrypto","getGlobalThis","globalThis","getRandomValues","crypto","bind","msCrypto","Error","_getRandomValues","buf","nodeCrypto","wc","webcrypto","randomBytes","Uint8Array","TypeError","length","e","code","message","name","bytes","set"],"mappings":"AAAA,sEAAsE;AACtE,SAASA,aAAa,QAAQ,0BAA0B;AAExD,SAASC,aAAa,QAAQ,kBAAkB;AAEhD,MAAMC,aAAaD;AAEnB,sCAAsC;AACtC,0EAA0E;AAC1E,OAAO,IAAIE,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,aAAaV;IACnB,mBAAmB;IACnB,IAAIW,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"}
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../runtime/getGlobalThis.js';
1
+ import { getGlobalThis } from './getGlobalThis.js';
2
2
  const globalThis = getGlobalThis();
3
3
  /**
4
4
  * generate random UUIDv4
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/web/randomUUID.ts"],"sourcesContent":["import { getGlobalThis } from './getGlobalThis';\n\nconst globalThis = getGlobalThis();\n\n/**\n * generate random UUIDv4\n */\nexport const randomUUID: () => string = globalThis.crypto?.randomUUID?.bind(globalThis.crypto) || _randomUUID;\n\n/**\n * @internal\n */\nexport function _randomUUID() {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = (Math.random() * 16) | 0;\n const v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n}\n"],"names":["getGlobalThis","globalThis","randomUUID","crypto","bind","_randomUUID","replace","c","r","Math","random","v","toString"],"mappings":"AAAA,SAASA,aAAa,QAAQ,kBAAkB;AAEhD,MAAMC,aAAaD;AAEnB;;CAEC,GACD,OAAO,MAAME,aAA2BD,WAAWE,MAAM,EAAED,YAAYE,KAAKH,WAAWE,MAAM,KAAKE,YAAY;AAE9G;;CAEC,GACD,OAAO,SAASA;IACd,OAAO,uCAAuCC,OAAO,CAAC,SAAS,CAACC;QAC9D,MAAMC,IAAI,AAACC,KAAKC,MAAM,KAAK,KAAM;QACjC,MAAMC,IAAIJ,MAAM,MAAMC,IAAI,AAACA,IAAI,MAAO;QACtC,OAAOG,EAAEC,QAAQ,CAAC;IACpB;AACF"}
@@ -0,0 +1,13 @@
1
+ // for safari
2
+ export const requestIdleCallback = globalThis.requestIdleCallback || ((callback, options)=>{
3
+ const start = Date.now();
4
+ const deadline = {
5
+ didTimeout: false,
6
+ timeRemaining: ()=>Math.max(0, 50 - (Date.now() - start))
7
+ };
8
+ // skip options?.timeout
9
+ return setTimeout(()=>callback(deadline), 1);
10
+ });
11
+ export const cancelIdleCallback = globalThis.cancelIdleCallback || ((id)=>clearTimeout(id));
12
+
13
+ //# sourceMappingURL=requestIdleCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/web/requestIdleCallback.ts"],"sourcesContent":["// for safari\nexport const requestIdleCallback =\n globalThis.requestIdleCallback ||\n ((callback: (deadline: IdleDeadline) => void, options?: IdleRequestOptions) => {\n const start = Date.now();\n const deadline: IdleDeadline = {\n didTimeout: false,\n timeRemaining: () => Math.max(0, 50 - (Date.now() - start)),\n };\n // skip options?.timeout\n return setTimeout(() => callback(deadline), 1);\n });\n\nexport const cancelIdleCallback = globalThis.cancelIdleCallback || ((id: number) => clearTimeout(id));\n"],"names":["requestIdleCallback","globalThis","callback","options","start","Date","now","deadline","didTimeout","timeRemaining","Math","max","setTimeout","cancelIdleCallback","id","clearTimeout"],"mappings":"AAAA,aAAa;AACb,OAAO,MAAMA,sBACXC,WAAWD,mBAAmB,IAC7B,CAAA,CAACE,UAA4CC;IAC5C,MAAMC,QAAQC,KAAKC,GAAG;IACtB,MAAMC,WAAyB;QAC7BC,YAAY;QACZC,eAAe,IAAMC,KAAKC,GAAG,CAAC,GAAG,KAAMN,CAAAA,KAAKC,GAAG,KAAKF,KAAI;IAC1D;IACA,wBAAwB;IACxB,OAAOQ,WAAW,IAAMV,SAASK,WAAW;AAC9C,CAAA,EAAG;AAEL,OAAO,MAAMM,qBAAqBZ,WAAWY,kBAAkB,IAAK,CAAA,CAACC,KAAeC,aAAaD,GAAE,EAAG"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/web/structuredClone.ts"],"sourcesContent":["/* eslint no-proto:0 */\nimport { classOf } from '../langs/classOf';\n\n/**\n * Clone an object using structured cloning algorithm\n *\n * - Chrome 98, Safari 15.4, NodeJS 17\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/structuredClone structuredClone}\n * @see {@link https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.structured-clone.js core-js}\n */\nexport const structuredClone: <T>(value: T, options?: StructuredSerializeOptions) => T =\n globalThis.structuredClone || _clone;\n\nfunction set(obj: any, key: any, val: any) {\n if (typeof val.value === 'object') val.value = _clone(val.value);\n if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === '__proto__') {\n Object.defineProperty(obj, key, val);\n } else obj[key] = val.value;\n}\n\n/**\n * @see {@link https://github.com/lukeed/klona/blob/master/src/full.js klona}\n */\nexport function _clone(x: any): any {\n // too complex\n // https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/web.structured-clone.js\n\n if (typeof x !== 'object') return x;\n\n let i = 0;\n let k;\n let list;\n let tmp: any;\n const str = classOf(x);\n switch (str) {\n case 'Array':\n tmp = Array(x.length);\n break;\n case 'Object':\n tmp = Object.create(x.__proto__ || null);\n break;\n case 'Set':\n tmp = new Set();\n x.forEach(function (val: any) {\n tmp.add(_clone(val));\n });\n break;\n case 'Map':\n tmp = new Map();\n x.forEach(function (val: any, key: any) {\n tmp.set(_clone(key), _clone(val));\n });\n break;\n case 'Date':\n tmp = new Date(+x);\n break;\n case 'RegExp':\n tmp = new RegExp(x.source, x.flags);\n break;\n case 'DataView':\n tmp = new x.constructor(_clone(x.buffer));\n break;\n case 'ArrayBuffer':\n tmp = x.slice(0);\n break;\n default:\n // typed arrays\n if (str.endsWith('Array')) {\n // ArrayBuffer.isView(x)\n // ~> `new` bcuz `Buffer.slice` => ref\n tmp = new x.constructor(x);\n }\n }\n\n if (tmp) {\n for (list = Object.getOwnPropertySymbols(x); i < list.length; i++) {\n set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));\n }\n\n for (i = 0, list = Object.getOwnPropertyNames(x); i < list.length; i++) {\n if (Object.hasOwnProperty.call(tmp, (k = list[i])) && tmp[k] === x[k]) continue;\n set(tmp, k, Object.getOwnPropertyDescriptor(x, k));\n }\n }\n\n return tmp || x;\n}\n"],"names":["classOf","structuredClone","globalThis","_clone","set","obj","key","val","value","enumerable","get","configurable","writable","Object","defineProperty","x","i","k","list","tmp","str","Array","length","create","__proto__","Set","forEach","add","Map","Date","RegExp","source","flags","constructor","buffer","slice","endsWith","getOwnPropertySymbols","getOwnPropertyDescriptor","getOwnPropertyNames","hasOwnProperty","call"],"mappings":"AAAA,qBAAqB,GACrB,SAASA,OAAO,QAAQ,mBAAmB;AAE3C;;;;;;;CAOC,GACD,OAAO,MAAMC,kBACXC,WAAWD,eAAe,IAAIE,OAAO;AAEvC,SAASC,IAAIC,GAAQ,EAAEC,GAAQ,EAAEC,GAAQ;IACvC,IAAI,OAAOA,IAAIC,KAAK,KAAK,UAAUD,IAAIC,KAAK,GAAGL,OAAOI,IAAIC,KAAK;IAC/D,IAAI,CAACD,IAAIE,UAAU,IAAIF,IAAIG,GAAG,IAAIH,IAAIH,GAAG,IAAI,CAACG,IAAII,YAAY,IAAI,CAACJ,IAAIK,QAAQ,IAAIN,QAAQ,aAAa;QACtGO,OAAOC,cAAc,CAACT,KAAKC,KAAKC;IAClC,OAAOF,GAAG,CAACC,IAAI,GAAGC,IAAIC,KAAK;AAC7B;AAEA;;CAEC,GACD,OAAO,SAASL,OAAOY,CAAM;IAC3B,cAAc;IACd,mGAAmG;IAEnG,IAAI,OAAOA,MAAM,UAAU,OAAOA;IAElC,IAAIC,IAAI;IACR,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,MAAMC,MAAMpB,QAAQe;IACpB,OAAQK;QACN,KAAK;YACHD,MAAME,MAAMN,EAAEO,MAAM;YACpB;QACF,KAAK;YACHH,MAAMN,OAAOU,MAAM,CAACR,EAAES,SAAS,IAAI;YACnC;QACF,KAAK;YACHL,MAAM,IAAIM;YACVV,EAAEW,OAAO,CAAC,SAAUnB,GAAQ;gBAC1BY,IAAIQ,GAAG,CAACxB,OAAOI;YACjB;YACA;QACF,KAAK;YACHY,MAAM,IAAIS;YACVb,EAAEW,OAAO,CAAC,SAAUnB,GAAQ,EAAED,GAAQ;gBACpCa,IAAIf,GAAG,CAACD,OAAOG,MAAMH,OAAOI;YAC9B;YACA;QACF,KAAK;YACHY,MAAM,IAAIU,KAAK,CAACd;YAChB;QACF,KAAK;YACHI,MAAM,IAAIW,OAAOf,EAAEgB,MAAM,EAAEhB,EAAEiB,KAAK;YAClC;QACF,KAAK;YACHb,MAAM,IAAIJ,EAAEkB,WAAW,CAAC9B,OAAOY,EAAEmB,MAAM;YACvC;QACF,KAAK;YACHf,MAAMJ,EAAEoB,KAAK,CAAC;YACd;QACF;YACE,eAAe;YACf,IAAIf,IAAIgB,QAAQ,CAAC,UAAU;gBACzB,wBAAwB;gBACxB,sCAAsC;gBACtCjB,MAAM,IAAIJ,EAAEkB,WAAW,CAAClB;YAC1B;IACJ;IAEA,IAAII,KAAK;QACP,IAAKD,OAAOL,OAAOwB,qBAAqB,CAACtB,IAAIC,IAAIE,KAAKI,MAAM,EAAEN,IAAK;YACjEZ,IAAIe,KAAKD,IAAI,CAACF,EAAE,EAAEH,OAAOyB,wBAAwB,CAACvB,GAAGG,IAAI,CAACF,EAAE;QAC9D;QAEA,IAAKA,IAAI,GAAGE,OAAOL,OAAO0B,mBAAmB,CAACxB,IAAIC,IAAIE,KAAKI,MAAM,EAAEN,IAAK;YACtE,IAAIH,OAAO2B,cAAc,CAACC,IAAI,CAACtB,KAAMF,IAAIC,IAAI,CAACF,EAAE,KAAMG,GAAG,CAACF,EAAE,KAAKF,CAAC,CAACE,EAAE,EAAE;YACvEb,IAAIe,KAAKF,GAAGJ,OAAOyB,wBAAwB,CAACvB,GAAGE;QACjD;IACF;IAEA,OAAOE,OAAOJ;AAChB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wener/utils",
3
- "version": "1.1.49",
3
+ "version": "1.1.51",
4
4
  "type": "module",
5
5
  "description": "Utils for daily use",
6
6
  "repository": {
@@ -70,14 +70,11 @@
70
70
  "lodash"
71
71
  ],
72
72
  "devDependencies": {
73
- "@sinclair/typebox": "^0.33.9",
74
- "@types/lodash": "^4.17.7",
73
+ "@sinclair/typebox": "^0.33.16",
75
74
  "@types/ws": "^8.5.12",
76
- "@wener/utils": "link:",
77
75
  "https-proxy-agent": "^7.0.5",
78
- "lodash": "^4.17.21",
79
76
  "node-fetch": "^3.3.2",
80
- "undici": "^6.19.8",
77
+ "undici": "^6.20.0",
81
78
  "zod": "^3.23.8"
82
79
  },
83
80
  "publishConfig": {
@@ -86,7 +83,7 @@
86
83
  },
87
84
  "sideEffects": false,
88
85
  "scripts": {
89
- "build": "make prepublish",
86
+ "build": "make build",
90
87
  "clean": "make clean",
91
88
  "dev": "make dev",
92
89
  "test": "make test"
@@ -1,5 +1,5 @@
1
1
  import { createLazyPromise, type LazyPromise } from './createLazyPromise';
2
- import { type MaybePromise } from './MaybePromise';
2
+ import type { MaybePromise } from './MaybePromise';
3
3
 
4
4
  type Val<T> = [val: MaybePromise<T> | undefined, done: boolean, err?: any];
5
5
 
@@ -39,12 +39,12 @@ const DivisionCodeLevels = [
39
39
  *
40
40
  * @see https://zh.wikipedia.org/wiki/GB/T_2260 中华人民共和国行政区划代码
41
41
  */
42
- export class DivisionCodeFormat {
43
- static levels = DivisionCodeLevels;
42
+ export namespace DivisionCode {
43
+ export const levels = DivisionCodeLevels;
44
44
 
45
- regex = /^(?<province>\d{2})(?<city>\d{2})?(?<county>\d{2})?(?<town>\d{3})?(?<village>\d{3})?$/;
45
+ export const regex = /^(?<province>\d{2})(?<city>\d{2})?(?<county>\d{2})?(?<town>\d{3})?(?<village>\d{3})?$/;
46
46
 
47
- provinces: Array<[number, string]> = [
47
+ const provinces: Array<[number, string]> = [
48
48
  [11, '北京市'],
49
49
  [12, '天津市'],
50
50
  [13, '河北省'],
@@ -82,9 +82,16 @@ export class DivisionCodeFormat {
82
82
  // 9 国外
83
83
  ];
84
84
 
85
- parse(code: string) {
85
+ export type ParsedCode = {
86
+ province: string;
87
+ city?: string;
88
+ county?: string;
89
+ town?: string;
90
+ village?: string;
91
+ };
92
+
93
+ export function parse(code: string): ParsedCode | undefined {
86
94
  if (!code) return;
87
- const { regex } = this;
88
95
  const match = regex.exec(code);
89
96
  if (!match) return;
90
97
  const { province, city, county, town, village } = match.groups ?? {};
@@ -98,6 +105,15 @@ export class DivisionCodeFormat {
98
105
  village,
99
106
  };
100
107
  }
108
+
109
+ export function random(level: DivisionCodeLevel = 'County'): string {
110
+ const l = DivisionCodeLevels.find((v) => v.code === level) || DivisionCodeLevels[2];
111
+ const l1 = randomPick(provinces);
112
+ if (l.level === 1) {
113
+ return String(l1[0]);
114
+ }
115
+ return l1 + String(Math.floor(Math.random() * parseFloat(`1e${l.length - 2}`) - 1));
116
+ }
101
117
  }
102
118
 
103
119
  interface DivisionTreeNode {
@@ -152,4 +168,6 @@ export interface CodeName {
152
168
  // return label.replace(/省|市|(回族|维吾尔|壮族)?自治区|特别行政区$/, '');
153
169
  // }
154
170
 
155
- export const DivisionCode = new DivisionCodeFormat();
171
+ export function randomPick<T>(s: T[]) {
172
+ return s[Math.floor(Math.random() * s.length)];
173
+ }
@@ -1,6 +1,22 @@
1
- import { test } from 'vitest';
1
+ import { expect, test } from 'vitest';
2
2
  import { DivisionCode } from './DivisionCode';
3
3
 
4
4
  test('division', () => {
5
- console.log(DivisionCode.parse('441900003001'));
5
+ for (const [a, b] of [
6
+ [
7
+ '441900003001',
8
+ {
9
+ province: '44',
10
+ city: '19',
11
+ county: '00',
12
+ town: '003',
13
+ village: '001',
14
+ },
15
+ ],
16
+ ['31', { province: '31' }],
17
+ ['4', undefined],
18
+ ['', undefined],
19
+ ] as Array<[string, any]>) {
20
+ expect(DivisionCode.parse(a)).toMatchObject(b);
21
+ }
6
22
  });
@@ -1,5 +1,5 @@
1
1
  // import type * as NodeCrypto from 'node:crypto';
2
- import { getGlobalThis } from '../runtime/getGlobalThis';
2
+ import { getGlobalThis } from '../web/getGlobalThis';
3
3
 
4
4
  let nodeCrypto;
5
5
  // globalThis.process?.release?.name
@@ -2,10 +2,10 @@ import { assert, beforeAll, expect, test } from 'vitest';
2
2
  import { ArrayBuffers } from '../io/ArrayBuffers';
3
3
  import { polyfillCrypto } from '../server/polyfill/polyfillCrypto';
4
4
  import { isUUID } from '../validations/isUUID';
5
+ import { _randomUUID } from '../web/randomUUID';
5
6
  import { hex } from './base';
6
7
  import { hmac, sha1, sha256, sha384, sha512 } from './hashing';
7
8
  import { md5 } from './md5';
8
- import { _randomUUID } from './randomUUID';
9
9
 
10
10
  beforeAll(async () => {
11
11
  await polyfillCrypto();
@@ -1,5 +1,5 @@
1
1
  import { expect, test } from 'vitest';
2
- import { randomUUID } from './randomUUID';
2
+ import { randomUUID } from '../web/randomUUID';
3
3
  import { createULID, isULID, parseULID, ulid } from './ulid';
4
4
 
5
5
  test('isULID', () => {
@@ -1,4 +1,4 @@
1
- import { getRandomValues } from './getRandomValues';
1
+ import { getRandomValues } from '../web/getRandomValues';
2
2
 
3
3
  type PRNG = () => number;
4
4
 
@@ -152,26 +152,47 @@ export interface ErrorDetail {
152
152
  check<T>(v: T | undefined | null, o?: Partial<ErrorDetailInit> | string): asserts v is NonNullable<T>;
153
153
  }
154
154
 
155
- export class Errors {
156
- static BadRequest: ErrorDetail = this.with({ status: 400 });
157
- static Unauthorized: ErrorDetail = this.with({ status: 403 });
158
- static Forbidden: ErrorDetail = this.with({ status: 403 });
159
- static NotFound: ErrorDetail = this.with({ status: 404 });
160
- static InternalServerError: ErrorDetail = this.with({ status: 500 });
161
- static NotImplemented: ErrorDetail = this.with({ status: 501 });
162
- static ServiceUnavailable: ErrorDetail = this.with({ status: 503 });
163
-
164
- static resolvers: ((e: any) => ErrorDetail | void)[] = [];
165
-
166
- static with(init: ErrorDetailInit): ErrorDetail {
155
+ export namespace Errors {
156
+ /*
157
+ https://github.com/tc39/proposal-error-cause
158
+ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
159
+ Stage 3
160
+ Chrome 93, Safari 15, Node 16.9
161
+
162
+ https://www.npmjs.com/package/pony-cause
163
+ */
164
+
165
+ export const BadRequest: ErrorDetail = create({ status: 400 });
166
+ export const Unauthorized: ErrorDetail = create({ status: 403 });
167
+ export const Forbidden: ErrorDetail = create({ status: 403 });
168
+ export const NotFound: ErrorDetail = create({ status: 404 });
169
+ export const InternalServerError: ErrorDetail = create({ status: 500 });
170
+ export const NotImplemented: ErrorDetail = create({ status: 501 });
171
+ export const ServiceUnavailable: ErrorDetail = create({ status: 503 });
172
+
173
+ // known errors
174
+ // TypeError when an operation could not be performed, typically (but not exclusively) when a value is not of the expected type.
175
+ // RangeError when a number is not within the correct range allowed.
176
+ // AggregateError when multiple errors need to be reported by an operation, for example by Promise.all().
177
+ // 例如 Promise.any() 会返回一个 AggregateError,其中包含所有 rejected 的 Promise 的错误。
178
+ // EvalError when an error occurs during the evaluation of JavaScript code.
179
+ // ReferenceError when a non-existent variable is referenced.
180
+ // SyntaxError when a syntax error occurs while parsing code in eval().
181
+ // URIError when encodeURI() or decodeURI() are passed invalid parameters.
182
+ // InternalError when an internal error in the JavaScript engine is thrown. E.g. "too much recursion".
183
+ // DOMException when an error occurs in the DOM.
184
+
185
+ export const resolvers: ((e: any) => ErrorDetail | void)[] = [];
186
+
187
+ export function create(init: ErrorDetailInit): ErrorDetail {
167
188
  return new DetailHolder(init);
168
189
  }
169
190
 
170
- static ok(res: Response, o?: Partial<ErrorDetailInit>) {
191
+ export function ok(res: Response, o?: Partial<ErrorDetailInit>) {
171
192
  if (res.ok) {
172
193
  return res;
173
194
  }
174
- throw this.with({
195
+ throw create({
175
196
  description: res.statusText,
176
197
  status: res.status,
177
198
  ...o,
@@ -182,7 +203,7 @@ export class Errors {
182
203
  }).asError();
183
204
  }
184
205
 
185
- static resolve(e: any): ErrorDetail {
206
+ export function resolve(e: any): ErrorDetail {
186
207
  if (e instanceof DetailHolder) {
187
208
  return e;
188
209
  }
@@ -191,7 +212,7 @@ export class Errors {
191
212
  return e.detail;
192
213
  }
193
214
 
194
- for (const resolver of this.resolvers) {
215
+ for (const resolver of resolvers) {
195
216
  const r = resolver(e);
196
217
  if (r) {
197
218
  return r;
@@ -1,6 +1,6 @@
1
1
  import type { MaybePromise } from '../asyncs/MaybePromise';
2
- import { getGlobalThis } from '../runtime/getGlobalThis';
3
- import { type FetchLike } from './types';
2
+ import { getGlobalThis } from '../web/getGlobalThis';
3
+ import type { FetchLike } from './types';
4
4
 
5
5
  export function createFetchWith({
6
6
  fetch = getGlobalThis().fetch,
@@ -1,7 +1,7 @@
1
1
  import { createFetchWith } from './createFetchWith';
2
2
  import { dumpRequest } from './dumpRequest';
3
3
  import { dumpResponse } from './dumpResponse';
4
- import { type FetchLike } from './types';
4
+ import type { FetchLike } from './types';
5
5
 
6
6
  export function createFetchWithLogging({
7
7
  fetch,
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../runtime/getGlobalThis';
1
+ import { getGlobalThis } from '../web/getGlobalThis';
2
2
  import type { FetchLike } from './types';
3
3
 
4
4
  type RequestDelayFunction = (attempt: number, error: Error | null, response: Response | null) => number;
package/src/index.ts CHANGED
@@ -42,6 +42,7 @@ export { isClass } from './langs/isClass';
42
42
  export { isDefined } from './langs/isDefined';
43
43
  export { isEmptyObject } from './langs/isEmptyObject';
44
44
  export { isPlainObject } from './langs/isPlainObject';
45
+ export { ifPresent } from './langs/ifPresent';
45
46
  export { parseBoolean } from './langs/parseBoolean';
46
47
  export { maybeFunction, type MaybeFunction } from './langs/MaybeFunction';
47
48
  export { memoize } from './langs/memoize';
@@ -50,8 +51,8 @@ export type { MixinFunction, MixinInstance, MixinReturnValue } from './langs/mix
50
51
  export { getObjectId } from './langs/getObjectId';
51
52
  export { getGlobalStates, setGlobalStates } from './langs/getGlobalStates';
52
53
 
53
- export { AsyncCloser } from './runtime/AsyncCloser';
54
- export { Closer } from './runtime/Closer';
54
+ export { AsyncCloser } from './langs/AsyncCloser';
55
+ export { Closer } from './langs/Closer';
55
56
 
56
57
  export { isUUID } from './validations/isUUID';
57
58
  export { parseTimestamp } from './validations/parseTimestamp';
@@ -89,14 +90,14 @@ export { copy } from './browsers/copy';
89
90
  export { download } from './browsers/download';
90
91
  export { loadScripts, loadStyles } from './browsers/loaders';
91
92
  export { getFileFromDataTransfer } from './browsers/getFileFromDataTransfer';
92
-
93
- // polyfills
94
- export { getGlobalThis } from './runtime/getGlobalThis';
95
- export { structuredClone } from './runtime/structuredClone';
93
+ // web & spec
94
+ export { requestIdleCallback, cancelIdleCallback } from './web/requestIdleCallback';
95
+ export { randomUUID } from './web/randomUUID';
96
+ export { getRandomValues } from './web/getRandomValues';
97
+ export { getGlobalThis } from './web/getGlobalThis';
98
+ export { structuredClone } from './web/structuredClone';
96
99
 
97
100
  // crypto
98
- export { randomUUID } from './crypto/randomUUID';
99
- export { getRandomValues } from './crypto/getRandomValues';
100
101
  export { sha1, sha256, sha384, sha512, hmac, type DigestOptions } from './crypto/hashing';
101
102
  export { md5 } from './crypto/md5';
102
103
  export { hex } from './crypto/base';
@@ -84,3 +84,10 @@ test('toBase64', () => {
84
84
  const buf = ArrayBuffers.from(text, 'utf8', Uint8Array);
85
85
  expect(ArrayBuffers.toBase64(buf)).toEqual('YW9ldQ==');
86
86
  });
87
+
88
+ test('base64: utf8 string', () => {
89
+ const text = '你好';
90
+ // latin1 only
91
+ expect(() => btoa(text)).toThrow('Invalid character');
92
+ expect(ArrayBuffers.toBase64(text)).toEqual('5L2g5aW9');
93
+ });