@wener/utils 1.1.37 → 1.1.39

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 (108) hide show
  1. package/lib/browsers/download.js +20 -11
  2. package/lib/browsers/download.js.map +1 -1
  3. package/lib/cn/division/DivisionCode.js +204 -0
  4. package/lib/cn/division/DivisionCode.js.map +1 -0
  5. package/lib/cn/id/Mod11Checksum.js +46 -0
  6. package/lib/cn/id/Mod11Checksum.js.map +1 -0
  7. package/lib/cn/id/ResidentIdNumber.js +89 -0
  8. package/lib/cn/id/ResidentIdNumber.js.map +1 -0
  9. package/lib/cn/id/types.js +8 -0
  10. package/lib/cn/id/types.js.map +1 -0
  11. package/lib/cn/index.js +9 -1
  12. package/lib/cn/index.js.map +1 -1
  13. package/lib/cn/uscc/Mod31Checksum.js +52 -0
  14. package/lib/cn/uscc/Mod31Checksum.js.map +1 -0
  15. package/lib/cn/uscc/USCC.js +97 -0
  16. package/lib/cn/uscc/USCC.js.map +1 -0
  17. package/lib/cn/uscc/isUSCC.js +8 -0
  18. package/lib/cn/uscc/isUSCC.js.map +1 -0
  19. package/lib/crypto/getRandomValues.js +1 -1
  20. package/lib/crypto/getRandomValues.js.map +1 -1
  21. package/lib/crypto/randomUUID.js +1 -1
  22. package/lib/crypto/randomUUID.js.map +1 -1
  23. package/lib/crypto/randomUUIDv7.js +3 -0
  24. package/lib/crypto/randomUUIDv7.js.map +1 -0
  25. package/lib/errors/Errors.js +1 -1
  26. package/lib/errors/Errors.js.map +1 -1
  27. package/lib/fetch/HttpStatus.js.map +1 -0
  28. package/lib/fetch/createFetchWith.js +1 -1
  29. package/lib/fetch/createFetchWith.js.map +1 -1
  30. package/lib/fetch/createFetchWithRetry.js +1 -1
  31. package/lib/fetch/createFetchWithRetry.js.map +1 -1
  32. package/lib/index.js +7 -5
  33. package/lib/index.js.map +1 -1
  34. package/lib/io/ArrayBuffers.js +58 -4
  35. package/lib/io/ArrayBuffers.js.map +1 -1
  36. package/lib/io/isTransferable.js +1 -1
  37. package/lib/io/isTransferable.js.map +1 -1
  38. package/lib/io/parseDataUri.js +57 -0
  39. package/lib/io/parseDataUri.js.map +1 -0
  40. package/lib/objects/computeIfAbsent.js +14 -0
  41. package/lib/objects/computeIfAbsent.js.map +1 -0
  42. package/lib/runtime/AsyncCloser.js.map +1 -0
  43. package/lib/runtime/Closer.js.map +1 -0
  44. package/lib/runtime/getGlobalThis.js.map +1 -0
  45. package/lib/runtime/structuredClone.js.map +1 -0
  46. package/lib/server/fetch/createFetchWithProxyByNodeFetch.js +1 -1
  47. package/lib/server/fetch/createFetchWithProxyByNodeFetch.js.map +1 -1
  48. package/lib/server/fetch/createFetchWithProxyByUndici.js +1 -1
  49. package/lib/server/fetch/createFetchWithProxyByUndici.js.map +1 -1
  50. package/lib/server/getPackageDir.js +5 -4
  51. package/lib/server/getPackageDir.js.map +1 -1
  52. package/lib/server/polyfill/polyfillCrypto.js +1 -1
  53. package/lib/server/polyfill/polyfillCrypto.js.map +1 -1
  54. package/lib/server/polyfill/polyfillJsDom.js +1 -1
  55. package/lib/server/polyfill/polyfillJsDom.js.map +1 -1
  56. package/lib/server/polyfill/polyfillWebSocket.js +1 -1
  57. package/lib/server/polyfill/polyfillWebSocket.js.map +1 -1
  58. package/package.json +22 -15
  59. package/src/browsers/download.ts +20 -13
  60. package/src/cn/division/DivisionCode.ts +109 -0
  61. package/src/cn/id/Mod11Checksum.ts +29 -0
  62. package/src/cn/id/ResidentIdNumber.ts +102 -0
  63. package/src/cn/id/id.test.ts +20 -0
  64. package/src/cn/id/types.ts +26 -0
  65. package/src/cn/index.ts +13 -0
  66. package/src/cn/uscc/Mod31Checksum.ts +42 -0
  67. package/src/cn/uscc/USCC.ts +98 -0
  68. package/src/cn/uscc/isUSCC.ts +8 -0
  69. package/src/cn/uscc/uscc.test.ts +16 -0
  70. package/src/crypto/getRandomValues.ts +1 -1
  71. package/src/crypto/randomUUID.ts +1 -1
  72. package/src/crypto/randomUUIDv7.ts +1 -0
  73. package/src/errors/Errors.ts +1 -1
  74. package/src/fetch/createFetchWith.ts +1 -1
  75. package/src/fetch/createFetchWithRetry.ts +1 -1
  76. package/src/index.ts +7 -5
  77. package/src/io/ArrayBuffers.base64.test.ts +24 -0
  78. package/src/io/ArrayBuffers.ts +106 -4
  79. package/src/io/isTransferable.ts +1 -1
  80. package/src/io/parseDataUri.test.ts +34 -0
  81. package/src/io/parseDataUri.ts +66 -0
  82. package/src/objects/computeIfAbsent.ts +15 -0
  83. package/src/schema/typebox/gen/README.md +2 -0
  84. package/src/server/fetch/createFetchWithProxyByNodeFetch.ts +1 -1
  85. package/src/server/fetch/createFetchWithProxyByUndici.ts +1 -1
  86. package/src/server/getPackageDir.ts +6 -4
  87. package/src/server/polyfill/polyfillCrypto.ts +1 -1
  88. package/src/server/polyfill/polyfillJsDom.ts +1 -1
  89. package/src/server/polyfill/polyfillWebSocket.ts +1 -1
  90. package/lib/http/HttpStatus.js.map +0 -1
  91. package/lib/io/Bytes.js +0 -51
  92. package/lib/io/Bytes.js.map +0 -1
  93. package/lib/isomorphics/getGlobalThis.js.map +0 -1
  94. package/lib/isomorphics/structuredClone.js.map +0 -1
  95. package/lib/langs/AsyncCloser.js.map +0 -1
  96. package/lib/langs/Closer.js.map +0 -1
  97. package/src/io/Bytes.ts +0 -64
  98. /package/lib/{http → fetch}/HttpStatus.js +0 -0
  99. /package/lib/{langs → runtime}/AsyncCloser.js +0 -0
  100. /package/lib/{langs → runtime}/Closer.js +0 -0
  101. /package/lib/{isomorphics → runtime}/getGlobalThis.js +0 -0
  102. /package/lib/{isomorphics → runtime}/structuredClone.js +0 -0
  103. /package/src/{http → fetch}/HttpStatus.ts +0 -0
  104. /package/src/{langs → runtime}/AsyncCloser.ts +0 -0
  105. /package/src/{langs → runtime}/Closer.ts +0 -0
  106. /package/src/{isomorphics → runtime}/getGlobalThis.ts +0 -0
  107. /package/src/{isomorphics → runtime}/structuredClone.test.ts +0 -0
  108. /package/src/{isomorphics → runtime}/structuredClone.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/fetch/createFetchWithProxyByNodeFetch.ts"],"sourcesContent":["import { type FetchLike } from '../../fetch';\nimport { getGlobalThis } from '../../isomorphics/getGlobalThis';\n\nexport function createFetchWithProxyByNodeFetch({\n proxy,\n fetch,\n}: { proxy?: string; fetch?: FetchLike } = {}): FetchLike {\n const globalThis = getGlobalThis();\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n\n let agent: any;\n const Request = globalThis.Request;\n let NodeRequest: any;\n let NodeFetch: any;\n return async (url, init?: RequestInit) => {\n if (!agent) {\n const { default: createHttpsProxyAgent } = await import('https-proxy-agent');\n agent = (createHttpsProxyAgent as any)(proxy);\n }\n\n // node-fetch 才可以,node v18 fetch 不支持\n if (!NodeRequest) {\n ({ Request: NodeRequest, default: NodeFetch } = await import('node-fetch'));\n }\n\n fetch ||= NodeFetch;\n\n if (url instanceof Request) {\n return (fetch as any)(new Request(url, { agent } as any));\n }\n if ((url as any) instanceof NodeRequest) {\n return (fetch as any)(new NodeRequest(url, { agent } as any));\n }\n return (fetch as any)(url, {\n ...init,\n agent,\n } as any);\n };\n}\n"],"names":["getGlobalThis","createFetchWithProxyByNodeFetch","proxy","fetch","globalThis","agent","Request","NodeRequest","NodeFetch","url","init","default","createHttpsProxyAgent"],"mappings":"AACA,SAASA,aAAa,QAAQ,kCAAkC;AAEhE,OAAO,SAASC,gCAAgC,EAC9CC,KAAK,EACLC,KAAK,EACiC,GAAG,CAAC,CAAC;IAC3C,MAAMC,aAAaJ;IACnB,IAAI,CAACE,OAAO;QACV,OAAOC,SAASC,WAAWD,KAAK;IAClC;IAEA,IAAIE;IACJ,MAAMC,UAAUF,WAAWE,OAAO;IAClC,IAAIC;IACJ,IAAIC;IACJ,OAAO,OAAOC,KAAKC;QACjB,IAAI,CAACL,OAAO;YACV,MAAM,EAAEM,SAASC,qBAAqB,EAAE,GAAG,MAAM,MAAM,CAAC;YACxDP,QAAQ,AAACO,sBAA8BV;QACzC;QAEA,oCAAoC;QACpC,IAAI,CAACK,aAAa;YACf,CAAA,EAAED,SAASC,WAAW,EAAEI,SAASH,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,aAAY;QAC3E;QAEAL,UAAUK;QAEV,IAAIC,eAAeH,SAAS;YAC1B,OAAO,AAACH,MAAc,IAAIG,QAAQG,KAAK;gBAAEJ;YAAM;QACjD;QACA,IAAI,AAACI,eAAuBF,aAAa;YACvC,OAAO,AAACJ,MAAc,IAAII,YAAYE,KAAK;gBAAEJ;YAAM;QACrD;QACA,OAAO,AAACF,MAAcM,KAAK;YACzB,GAAGC,IAAI;YACPL;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/server/fetch/createFetchWithProxyByNodeFetch.ts"],"sourcesContent":["import { type FetchLike } from '../../fetch';\nimport { getGlobalThis } from '../../runtime/getGlobalThis';\n\nexport function createFetchWithProxyByNodeFetch({\n proxy,\n fetch,\n}: { proxy?: string; fetch?: FetchLike } = {}): FetchLike {\n const globalThis = getGlobalThis();\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n\n let agent: any;\n const Request = globalThis.Request;\n let NodeRequest: any;\n let NodeFetch: any;\n return async (url, init?: RequestInit) => {\n if (!agent) {\n const { default: createHttpsProxyAgent } = await import('https-proxy-agent');\n agent = (createHttpsProxyAgent as any)(proxy);\n }\n\n // node-fetch 才可以,node v18 fetch 不支持\n if (!NodeRequest) {\n ({ Request: NodeRequest, default: NodeFetch } = await import('node-fetch'));\n }\n\n fetch ||= NodeFetch;\n\n if (url instanceof Request) {\n return (fetch as any)(new Request(url, { agent } as any));\n }\n if ((url as any) instanceof NodeRequest) {\n return (fetch as any)(new NodeRequest(url, { agent } as any));\n }\n return (fetch as any)(url, {\n ...init,\n agent,\n } as any);\n };\n}\n"],"names":["getGlobalThis","createFetchWithProxyByNodeFetch","proxy","fetch","globalThis","agent","Request","NodeRequest","NodeFetch","url","init","default","createHttpsProxyAgent"],"mappings":"AACA,SAASA,aAAa,QAAQ,8BAA8B;AAE5D,OAAO,SAASC,gCAAgC,EAC9CC,KAAK,EACLC,KAAK,EACiC,GAAG,CAAC,CAAC;IAC3C,MAAMC,aAAaJ;IACnB,IAAI,CAACE,OAAO;QACV,OAAOC,SAASC,WAAWD,KAAK;IAClC;IAEA,IAAIE;IACJ,MAAMC,UAAUF,WAAWE,OAAO;IAClC,IAAIC;IACJ,IAAIC;IACJ,OAAO,OAAOC,KAAKC;QACjB,IAAI,CAACL,OAAO;YACV,MAAM,EAAEM,SAASC,qBAAqB,EAAE,GAAG,MAAM,MAAM,CAAC;YACxDP,QAAQ,AAACO,sBAA8BV;QACzC;QAEA,oCAAoC;QACpC,IAAI,CAACK,aAAa;YACf,CAAA,EAAED,SAASC,WAAW,EAAEI,SAASH,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,aAAY;QAC3E;QAEAL,UAAUK;QAEV,IAAIC,eAAeH,SAAS;YAC1B,OAAO,AAACH,MAAc,IAAIG,QAAQG,KAAK;gBAAEJ;YAAM;QACjD;QACA,IAAI,AAACI,eAAuBF,aAAa;YACvC,OAAO,AAACJ,MAAc,IAAII,YAAYE,KAAK;gBAAEJ;YAAM;QACrD;QACA,OAAO,AAACF,MAAcM,KAAK;YACzB,GAAGC,IAAI;YACPL;QACF;IACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { createFetchWith } from '../../fetch/index.js';
2
- import { getGlobalThis } from '../../isomorphics/getGlobalThis.js';
2
+ import { getGlobalThis } from '../../runtime/getGlobalThis.js';
3
3
  export function createFetchWithProxyByUndici({ proxy, token: _token, fetch, undici } = {}) {
4
4
  if (!proxy) {
5
5
  return fetch || globalThis.fetch;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/fetch/createFetchWithProxyByUndici.ts"],"sourcesContent":["import { MaybePromise } from '../../asyncs/MaybePromise';\nimport { createFetchWith, FetchLike } from '../../fetch';\nimport { getGlobalThis } from '../../isomorphics/getGlobalThis';\n\nexport function createFetchWithProxyByUndici({\n proxy,\n token: _token,\n fetch,\n undici,\n}: {\n proxy?: string;\n token?: string;\n fetch?: FetchLike;\n undici?: MaybePromise<{ fetch: any; ProxyAgent: any }>;\n} = {}): FetchLike {\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n\n if ((getGlobalThis() as any).Bun) {\n return createFetchWith({\n fetch,\n onRequest: ({ url, req, next }) => {\n return next(url, {\n ...req,\n // https://github.com/oven-sh/bun/issues/1829\n proxy,\n } as RequestInit);\n },\n });\n }\n\n let agent: any;\n // https://github.com/nodejs/undici/blob/main/docs/best-practices/proxy.md\n return async (...args) => {\n const init = (args[1] ||= {}) as RequestInit & {\n duplex?: string;\n dispatcher?: any;\n };\n {\n const body = init.body;\n if (typeof body === 'object' && body && (body instanceof ReadableStream || Symbol.asyncIterator in body)) {\n // request.duplex must be set if request.body is ReadableStream or Async Iterables\n init.duplex ||= 'half';\n }\n }\n if (!agent) {\n let uri = proxy;\n let token = _token;\n {\n let u: URL | undefined;\n try {\n u = new URL(proxy);\n } catch (e) {}\n if (!token && u && (u.username || u.password)) {\n token = `Basic ${btoa(`${u.username || ''}:${u.password}`)}`;\n u.username = '';\n u.password = '';\n uri = u.toString();\n }\n }\n // if in next use 'next/dist/compiled/undici'\n undici ||= import('undici');\n const mod = await undici;\n const ProxyAgent = mod.ProxyAgent as new (_: any) => any;\n fetch ||= mod.fetch as FetchLike;\n // https://github.com/nodejs/undici/blob/main/docs/api/ProxyAgent.md\n agent = new ProxyAgent({\n uri,\n token,\n });\n // https://github.com/nodejs/node/issues/43187#issuecomment-1134634174\n // (global as any)[Symbol.for('undici.globalDispatcher.1')] = agent;\n // fixme should unwrap error https://github.com/nodejs/undici/issues/1248\n }\n init.dispatcher = agent;\n return await fetch!(...args);\n };\n}\n"],"names":["createFetchWith","getGlobalThis","createFetchWithProxyByUndici","proxy","token","_token","fetch","undici","globalThis","Bun","onRequest","url","req","next","agent","args","init","body","ReadableStream","Symbol","asyncIterator","duplex","uri","u","URL","e","username","password","btoa","toString","mod","ProxyAgent","dispatcher"],"mappings":"AACA,SAASA,eAAe,QAAmB,cAAc;AACzD,SAASC,aAAa,QAAQ,kCAAkC;AAEhE,OAAO,SAASC,6BAA6B,EAC3CC,KAAK,EACLC,OAAOC,MAAM,EACbC,KAAK,EACLC,MAAM,EAMP,GAAG,CAAC,CAAC;IACJ,IAAI,CAACJ,OAAO;QACV,OAAOG,SAASE,WAAWF,KAAK;IAClC;IAEA,IAAI,AAACL,gBAAwBQ,GAAG,EAAE;QAChC,OAAOT,gBAAgB;YACrBM;YACAI,WAAW,CAAC,EAAEC,GAAG,EAAEC,GAAG,EAAEC,IAAI,EAAE;gBAC5B,OAAOA,KAAKF,KAAK;oBACf,GAAGC,GAAG;oBACN,6CAA6C;oBAC7CT;gBACF;YACF;QACF;IACF;IAEA,IAAIW;IACJ,0EAA0E;IAC1E,OAAO,OAAO,GAAGC;QACf,MAAMC,OAAQD,IAAI,CAAC,EAAE,KAAK,CAAC;QAI3B;YACE,MAAME,OAAOD,KAAKC,IAAI;YACtB,IAAI,OAAOA,SAAS,YAAYA,QAASA,CAAAA,gBAAgBC,kBAAkBC,OAAOC,aAAa,IAAIH,IAAG,GAAI;gBACxG,kFAAkF;gBAClFD,KAAKK,MAAM,KAAK;YAClB;QACF;QACA,IAAI,CAACP,OAAO;YACV,IAAIQ,MAAMnB;YACV,IAAIC,QAAQC;YACZ;gBACE,IAAIkB;gBACJ,IAAI;oBACFA,IAAI,IAAIC,IAAIrB;gBACd,EAAE,OAAOsB,GAAG,CAAC;gBACb,IAAI,CAACrB,SAASmB,KAAMA,CAAAA,EAAEG,QAAQ,IAAIH,EAAEI,QAAQ,AAAD,GAAI;oBAC7CvB,QAAQ,CAAC,MAAM,EAAEwB,KAAK,CAAC,EAAEL,EAAEG,QAAQ,IAAI,GAAG,CAAC,EAAEH,EAAEI,QAAQ,CAAC,CAAC,EAAE,CAAC;oBAC5DJ,EAAEG,QAAQ,GAAG;oBACbH,EAAEI,QAAQ,GAAG;oBACbL,MAAMC,EAAEM,QAAQ;gBAClB;YACF;YACA,6CAA6C;YAC7CtB,WAAW,MAAM,CAAC;YAClB,MAAMuB,MAAM,MAAMvB;YAClB,MAAMwB,aAAaD,IAAIC,UAAU;YACjCzB,UAAUwB,IAAIxB,KAAK;YACnB,oEAAoE;YACpEQ,QAAQ,IAAIiB,WAAW;gBACrBT;gBACAlB;YACF;QACA,sEAAsE;QACtE,oEAAoE;QACpE,yEAAyE;QAC3E;QACAY,KAAKgB,UAAU,GAAGlB;QAClB,OAAO,MAAMR,SAAUS;IACzB;AACF"}
1
+ {"version":3,"sources":["../../../src/server/fetch/createFetchWithProxyByUndici.ts"],"sourcesContent":["import { MaybePromise } from '../../asyncs/MaybePromise';\nimport { createFetchWith, FetchLike } from '../../fetch';\nimport { getGlobalThis } from '../../runtime/getGlobalThis';\n\nexport function createFetchWithProxyByUndici({\n proxy,\n token: _token,\n fetch,\n undici,\n}: {\n proxy?: string;\n token?: string;\n fetch?: FetchLike;\n undici?: MaybePromise<{ fetch: any; ProxyAgent: any }>;\n} = {}): FetchLike {\n if (!proxy) {\n return fetch || globalThis.fetch;\n }\n\n if ((getGlobalThis() as any).Bun) {\n return createFetchWith({\n fetch,\n onRequest: ({ url, req, next }) => {\n return next(url, {\n ...req,\n // https://github.com/oven-sh/bun/issues/1829\n proxy,\n } as RequestInit);\n },\n });\n }\n\n let agent: any;\n // https://github.com/nodejs/undici/blob/main/docs/best-practices/proxy.md\n return async (...args) => {\n const init = (args[1] ||= {}) as RequestInit & {\n duplex?: string;\n dispatcher?: any;\n };\n {\n const body = init.body;\n if (typeof body === 'object' && body && (body instanceof ReadableStream || Symbol.asyncIterator in body)) {\n // request.duplex must be set if request.body is ReadableStream or Async Iterables\n init.duplex ||= 'half';\n }\n }\n if (!agent) {\n let uri = proxy;\n let token = _token;\n {\n let u: URL | undefined;\n try {\n u = new URL(proxy);\n } catch (e) {}\n if (!token && u && (u.username || u.password)) {\n token = `Basic ${btoa(`${u.username || ''}:${u.password}`)}`;\n u.username = '';\n u.password = '';\n uri = u.toString();\n }\n }\n // if in next use 'next/dist/compiled/undici'\n undici ||= import('undici');\n const mod = await undici;\n const ProxyAgent = mod.ProxyAgent as new (_: any) => any;\n fetch ||= mod.fetch as FetchLike;\n // https://github.com/nodejs/undici/blob/main/docs/api/ProxyAgent.md\n agent = new ProxyAgent({\n uri,\n token,\n });\n // https://github.com/nodejs/node/issues/43187#issuecomment-1134634174\n // (global as any)[Symbol.for('undici.globalDispatcher.1')] = agent;\n // fixme should unwrap error https://github.com/nodejs/undici/issues/1248\n }\n init.dispatcher = agent;\n return await fetch!(...args);\n };\n}\n"],"names":["createFetchWith","getGlobalThis","createFetchWithProxyByUndici","proxy","token","_token","fetch","undici","globalThis","Bun","onRequest","url","req","next","agent","args","init","body","ReadableStream","Symbol","asyncIterator","duplex","uri","u","URL","e","username","password","btoa","toString","mod","ProxyAgent","dispatcher"],"mappings":"AACA,SAASA,eAAe,QAAmB,cAAc;AACzD,SAASC,aAAa,QAAQ,8BAA8B;AAE5D,OAAO,SAASC,6BAA6B,EAC3CC,KAAK,EACLC,OAAOC,MAAM,EACbC,KAAK,EACLC,MAAM,EAMP,GAAG,CAAC,CAAC;IACJ,IAAI,CAACJ,OAAO;QACV,OAAOG,SAASE,WAAWF,KAAK;IAClC;IAEA,IAAI,AAACL,gBAAwBQ,GAAG,EAAE;QAChC,OAAOT,gBAAgB;YACrBM;YACAI,WAAW,CAAC,EAAEC,GAAG,EAAEC,GAAG,EAAEC,IAAI,EAAE;gBAC5B,OAAOA,KAAKF,KAAK;oBACf,GAAGC,GAAG;oBACN,6CAA6C;oBAC7CT;gBACF;YACF;QACF;IACF;IAEA,IAAIW;IACJ,0EAA0E;IAC1E,OAAO,OAAO,GAAGC;QACf,MAAMC,OAAQD,IAAI,CAAC,EAAE,KAAK,CAAC;QAI3B;YACE,MAAME,OAAOD,KAAKC,IAAI;YACtB,IAAI,OAAOA,SAAS,YAAYA,QAASA,CAAAA,gBAAgBC,kBAAkBC,OAAOC,aAAa,IAAIH,IAAG,GAAI;gBACxG,kFAAkF;gBAClFD,KAAKK,MAAM,KAAK;YAClB;QACF;QACA,IAAI,CAACP,OAAO;YACV,IAAIQ,MAAMnB;YACV,IAAIC,QAAQC;YACZ;gBACE,IAAIkB;gBACJ,IAAI;oBACFA,IAAI,IAAIC,IAAIrB;gBACd,EAAE,OAAOsB,GAAG,CAAC;gBACb,IAAI,CAACrB,SAASmB,KAAMA,CAAAA,EAAEG,QAAQ,IAAIH,EAAEI,QAAQ,AAAD,GAAI;oBAC7CvB,QAAQ,CAAC,MAAM,EAAEwB,KAAK,CAAC,EAAEL,EAAEG,QAAQ,IAAI,GAAG,CAAC,EAAEH,EAAEI,QAAQ,CAAC,CAAC,EAAE,CAAC;oBAC5DJ,EAAEG,QAAQ,GAAG;oBACbH,EAAEI,QAAQ,GAAG;oBACbL,MAAMC,EAAEM,QAAQ;gBAClB;YACF;YACA,6CAA6C;YAC7CtB,WAAW,MAAM,CAAC;YAClB,MAAMuB,MAAM,MAAMvB;YAClB,MAAMwB,aAAaD,IAAIC,UAAU;YACjCzB,UAAUwB,IAAIxB,KAAK;YACnB,oEAAoE;YACpEQ,QAAQ,IAAIiB,WAAW;gBACrBT;gBACAlB;YACF;QACA,sEAAsE;QACtE,oEAAoE;QACpE,yEAAyE;QAC3E;QACAY,KAAKgB,UAAU,GAAGlB;QAClB,OAAO,MAAMR,SAAUS;IACzB;AACF"}
@@ -1,9 +1,9 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
- const __filename = fileURLToPath(import.meta.url);
5
- const __dirname = path.dirname(__filename);
6
- export function getPackageDir(currentDir = __dirname) {
3
+ // import { fileURLToPath } from 'node:url';
4
+ // const __filename = fileURLToPath(import.meta.url);
5
+ // const __dirname = path.dirname(__filename);
6
+ export function getPackageDir(currentDir = process.cwd()) {
7
7
  while(!fs.existsSync(path.join(currentDir, 'package.json'))){
8
8
  currentDir = path.resolve(currentDir, '..');
9
9
  if (currentDir === '/') {
@@ -12,5 +12,6 @@ export function getPackageDir(currentDir = __dirname) {
12
12
  }
13
13
  return currentDir;
14
14
  }
15
+ function findUp() {}
15
16
 
16
17
  //# sourceMappingURL=getPackageDir.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/server/getPackageDir.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nexport function getPackageDir(currentDir: string = __dirname) {\n while (!fs.existsSync(path.join(currentDir, 'package.json'))) {\n currentDir = path.resolve(currentDir, '..');\n if (currentDir === '/') {\n return undefined;\n }\n }\n return currentDir;\n}\n"],"names":["fs","path","fileURLToPath","__filename","url","__dirname","dirname","getPackageDir","currentDir","existsSync","join","resolve","undefined"],"mappings":"AAAA,OAAOA,QAAQ,UAAU;AACzB,OAAOC,UAAU,YAAY;AAC7B,SAASC,aAAa,QAAQ,WAAW;AAEzC,MAAMC,aAAaD,cAAc,YAAYE,GAAG;AAChD,MAAMC,YAAYJ,KAAKK,OAAO,CAACH;AAE/B,OAAO,SAASI,cAAcC,aAAqBH,SAAS;IAC1D,MAAO,CAACL,GAAGS,UAAU,CAACR,KAAKS,IAAI,CAACF,YAAY,iBAAkB;QAC5DA,aAAaP,KAAKU,OAAO,CAACH,YAAY;QACtC,IAAIA,eAAe,KAAK;YACtB,OAAOI;QACT;IACF;IACA,OAAOJ;AACT"}
1
+ {"version":3,"sources":["../../src/server/getPackageDir.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\n// import { fileURLToPath } from 'node:url';\n// const __filename = fileURLToPath(import.meta.url);\n// const __dirname = path.dirname(__filename);\n\nexport function getPackageDir(currentDir: string = process.cwd()) {\n while (!fs.existsSync(path.join(currentDir, 'package.json'))) {\n currentDir = path.resolve(currentDir, '..');\n if (currentDir === '/') {\n return undefined;\n }\n }\n return currentDir;\n}\n\nfunction findUp() {}\n"],"names":["fs","path","getPackageDir","currentDir","process","cwd","existsSync","join","resolve","undefined","findUp"],"mappings":"AAAA,OAAOA,QAAQ,UAAU;AACzB,OAAOC,UAAU,YAAY;AAE7B,4CAA4C;AAC5C,qDAAqD;AACrD,8CAA8C;AAE9C,OAAO,SAASC,cAAcC,aAAqBC,QAAQC,GAAG,EAAE;IAC9D,MAAO,CAACL,GAAGM,UAAU,CAACL,KAAKM,IAAI,CAACJ,YAAY,iBAAkB;QAC5DA,aAAaF,KAAKO,OAAO,CAACL,YAAY;QACtC,IAAIA,eAAe,KAAK;YACtB,OAAOM;QACT;IACF;IACA,OAAON;AACT;AAEA,SAASO,UAAU"}
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../../isomorphics/getGlobalThis.js';
1
+ import { getGlobalThis } from '../../runtime/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 '../../isomorphics/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,kCAAkC;AAEhE,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 '../../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"],"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,4 +1,4 @@
1
- import { getGlobalThis } from '../../isomorphics/getGlobalThis.js';
1
+ import { getGlobalThis } from '../../runtime/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 '../../isomorphics/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,kCAAkC;AAEhE,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 '../../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"],"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,4 +1,4 @@
1
- import { getGlobalThis } from '../../isomorphics/getGlobalThis.js';
1
+ import { getGlobalThis } from '../../runtime/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 '../../isomorphics/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,kCAAkC;AAIhE,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 '../../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"],"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wener/utils",
3
- "version": "1.1.37",
3
+ "version": "1.1.39",
4
4
  "type": "module",
5
5
  "description": "Utils for daily use",
6
6
  "repository": {
@@ -15,30 +15,37 @@
15
15
  "types": "./src/index.ts",
16
16
  "default": "./lib/index.js"
17
17
  },
18
- "./types": "./src/types.d.ts",
18
+ "./cn": {
19
+ "types": "./src/cn/index.ts",
20
+ "default": "./lib/cn/index.js"
21
+ },
22
+ "./schema/typebox": {
23
+ "types": "./src/schema/typebox/index.ts",
24
+ "default": "./lib/schema/typebox/index.js"
25
+ },
26
+ "./schema/typebox/gen": {
27
+ "types": "./src/schema/typebox/gen/index.ts",
28
+ "default": "./lib/schema/typebox/gen/index.js"
29
+ },
19
30
  "./server": {
20
31
  "types": "./src/server/index.ts",
21
32
  "default": "./lib/server/index.js"
22
33
  },
23
- "./server/node-fetch": {
24
- "types": "./src/server/node-fetch.ts",
25
- "default": "./lib/server/node-fetch.js"
26
- },
27
34
  "./server/jsdom": {
28
35
  "types": "./src/server/jsdom.ts",
29
36
  "default": "./lib/server/jsdom.js"
30
37
  },
38
+ "./server/node-fetch": {
39
+ "types": "./src/server/node-fetch.ts",
40
+ "default": "./lib/server/node-fetch.js"
41
+ },
31
42
  "./server/ws": {
32
43
  "types": "./src/server/ws.ts",
33
44
  "default": "./lib/server/ws.js"
34
45
  },
35
- "./schema/typebox": {
36
- "types": "./src/schema/typebox/index.ts",
37
- "default": "./lib/schema/typebox/index.js"
38
- },
39
- "./schema/typebox/gen": {
40
- "types": "./src/schema/typebox/gen/index.ts",
41
- "default": "./lib/schema/typebox/gen/index.js"
46
+ "./types": {
47
+ "types": "./src/types.d.ts",
48
+ "default": "./lib/types.d.js"
42
49
  },
43
50
  "./package.json": "./package.json"
44
51
  },
@@ -67,12 +74,12 @@
67
74
  },
68
75
  "devDependencies": {
69
76
  "@sinclair/typebox": "^0.32.15",
70
- "@types/lodash": "^4.14.202",
77
+ "@types/lodash": "^4.17.0",
71
78
  "@types/ws": "^8.5.10",
72
79
  "https-proxy-agent": "^7.0.4",
73
80
  "lodash": "^4.17.21",
74
81
  "node-fetch": "^3.3.2",
75
- "undici": "^6.7.0",
82
+ "undici": "^6.9.0",
76
83
  "zod": "^3.22.4"
77
84
  },
78
85
  "publishConfig": {
@@ -5,17 +5,23 @@
5
5
  * @param type content type
6
6
  * @param raw if true, data is treated as raw data, not url
7
7
  */
8
- export function download(filename: string, data: any, { type = 'application/octet-stream', raw = false } = {}) {
8
+ export async function download(filename: string, data: any, { type = 'application/octet-stream', raw = false } = {}) {
9
9
  const a = document.createElement('a');
10
10
  let closer: () => void = () => null;
11
11
  try {
12
12
  a.download = filename;
13
13
 
14
- // console.info(`downloading ${name}`, data);
15
-
16
14
  // url or data url
17
15
  if (typeof data === 'string' && /^(https?:|data:)/.test(data) && !raw) {
18
16
  a.href = data;
17
+ // 只有 same-origin 才能 download
18
+ if (/^https?:/.test(data)) {
19
+ if (new URL(data).origin !== location.origin) {
20
+ // 非同源
21
+ a.href = '';
22
+ data = await fetch(data).then((res) => res.blob());
23
+ }
24
+ }
19
25
  } else if (typeof data === 'string') {
20
26
  data = new TextEncoder().encode(data);
21
27
  }
@@ -23,17 +29,18 @@ export function download(filename: string, data: any, { type = 'application/octe
23
29
  if (data instanceof Uint8Array) {
24
30
  data = new Blob([data], { type });
25
31
  }
26
-
27
- if (data instanceof File || data instanceof Blob || data instanceof MediaSource) {
28
- a.href = URL.createObjectURL(data);
29
- closer = () => {
30
- URL.revokeObjectURL(a.href);
31
- };
32
- } else {
33
- console.error(`invalid download data`, data);
34
- throw new Error(`can not download ${Object.getPrototypeOf(data)}`);
32
+ {
33
+ if (data instanceof File || data instanceof Blob || data instanceof MediaSource) {
34
+ a.href = URL.createObjectURL(data);
35
+ closer = () => {
36
+ URL.revokeObjectURL(a.href);
37
+ };
38
+ } else {
39
+ console.error(`invalid download data`, data);
40
+ throw new Error(`can not download ${data && Object.getPrototypeOf(data)}`);
41
+ }
42
+ a.click();
35
43
  }
36
- a.click();
37
44
  } finally {
38
45
  closer();
39
46
  }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Codes for the administrative divisions of the People's Republic of China
3
+ *
4
+ * @see https://zh.wikipedia.org/wiki/GB/T_2260 中华人民共和国行政区划代码
5
+ */
6
+ export class DivisionCode {
7
+ static Levels = {
8
+ Province: {
9
+ level: 1,
10
+ code: 'Province',
11
+ length: 2,
12
+ },
13
+ City: {
14
+ level: 2,
15
+ code: 'City',
16
+ length: 4,
17
+ },
18
+ County: {
19
+ level: 3,
20
+ code: 'County',
21
+ length: 6,
22
+ },
23
+ Town: {
24
+ level: 4,
25
+ code: 'Town',
26
+ length: 9,
27
+ },
28
+ Village: {
29
+ level: 5,
30
+ code: 'Village',
31
+ length: 12,
32
+ },
33
+ } as const;
34
+
35
+ private static instance: DivisionCode;
36
+
37
+ static get() {
38
+ return this.instance || (this.instance = new DivisionCode());
39
+ }
40
+
41
+ regex = /^(?<province>\d{2})(?<city>\d{2})?(?<county>\d{2})?(?<town>\d{3})?(?<village>\d{3})?$/;
42
+
43
+ provinces: Array<[number, string]> = [
44
+ [11, '北京市'],
45
+ [12, '天津市'],
46
+ [13, '河北省'],
47
+ [14, '山西省'],
48
+ [15, '内蒙古自治区'],
49
+ [21, '辽宁省'],
50
+ [22, '吉林省'],
51
+ [23, '黑龙江省'],
52
+ [31, '上海市'],
53
+ [32, '江苏省'],
54
+ [33, '浙江省'],
55
+ [34, '安徽省'],
56
+ [35, '福建省'],
57
+ [36, '江西省'],
58
+ [37, '山东省'],
59
+ [41, '河南省'],
60
+ [42, '湖北省'],
61
+ [43, '湖南省'],
62
+ [44, '广东省'],
63
+ [45, '广西壮族自治区'],
64
+ [46, '海南省'],
65
+ [50, '重庆市'],
66
+ [51, '四川省'],
67
+ [52, '贵州省'],
68
+ [53, '云南省'],
69
+ [54, '西藏自治区'],
70
+ [61, '陕西省'],
71
+ [62, '甘肃省'],
72
+ [63, '青海省'],
73
+ [64, '宁夏回族自治区'],
74
+ [65, '新疆维吾尔自治区'],
75
+ [71, '台湾省'],
76
+ [81, '香港特别行政区'],
77
+ [82, '澳门特别行政区'],
78
+ // 9 国外
79
+ ];
80
+ }
81
+
82
+ export function binarySearch<T, S = number>(arr: T[], value: S, compare: (a: T, b: S) => number) {
83
+ let low = 0;
84
+ let high = arr.length - 1;
85
+ while (low <= high) {
86
+ const mid = (low + high) >> 1;
87
+ const cmp = compare(arr[mid], value);
88
+ if (cmp < 0) {
89
+ low = mid + 1;
90
+ } else if (cmp > 0) {
91
+ high = mid - 1;
92
+ } else {
93
+ return mid;
94
+ }
95
+ }
96
+ return -1;
97
+ }
98
+
99
+ // export function getSimpleProvinceLabel(value: string) {
100
+ // if (!value) {
101
+ // return;
102
+ // }
103
+ // let label = value;
104
+ // if (/[0-9]/.test(label)) {
105
+ // label = label.slice(0, 2);
106
+ // label = options.find((v) => v.value === label)?.label || label;
107
+ // }
108
+ // return label.replace(/省|市|(回族|维吾尔|壮族)?自治区|特别行政区$/, '');
109
+ // }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * ISO 7064:1983, MOD 11-2.
3
+ */
4
+ export class Mod11Checksum {
5
+ weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1];
6
+ private static instance: Mod11Checksum;
7
+
8
+ static get() {
9
+ return this.instance || (this.instance = new Mod11Checksum());
10
+ }
11
+
12
+ verify(s: string) {
13
+ return s.at(-1) === this.generate(s.slice(0, s.length - 1));
14
+ }
15
+
16
+ generate(s: string) {
17
+ const { weights } = this;
18
+ let sum = 0;
19
+ for (let i = 0; i < s.length; i++) {
20
+ sum += parseInt(s[i]) * weights[i];
21
+ }
22
+ const num = (12 - (sum % 11)) % 11;
23
+ if (num < 10) {
24
+ return num.toString();
25
+ } else {
26
+ return 'X';
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,102 @@
1
+ import { Mod11Checksum } from './Mod11Checksum';
2
+
3
+ export class ResidentIdNumber {
4
+ checksum = Mod11Checksum.get();
5
+
6
+ // 9 https://zh.wikipedia.org/wiki/中华人民共和国外国人永久居留身份证
7
+ // 9 标识码
8
+ // 申领地代码 - 2 位行政区划
9
+ // 国籍国代码 - 3 位数字 https://zh.wikipedia.org/wiki/ISO_3166-1数字代码
10
+
11
+ regex =
12
+ /^(?<division>[1-9]\d{5})(?<year>18|19|20)\d{2}(?<month>0[1-9]|1[0-2])(?<day>0[1-9]|[12]\d|3[01])(?<sequence>\d{3})(?<checksum>[0-9Xx])$/;
13
+
14
+ private static instance: ResidentIdNumber;
15
+
16
+ static get() {
17
+ return (this.instance ||= new ResidentIdNumber());
18
+ }
19
+
20
+ verify(s: string) {
21
+ if (!s) return false;
22
+ return this.regex.test(s) && this.checksum.verify(s.toUpperCase());
23
+ }
24
+
25
+ parse(s: string): IdNumber | undefined {
26
+ if (!this.verify(s)) {
27
+ return;
28
+ }
29
+
30
+ let date = s.slice(6, 14);
31
+ let y = parseInt(date.slice(0, 4));
32
+ let m = parseInt(date.slice(4, 6));
33
+ let d = parseInt(date.slice(6));
34
+ return new IdNumber(
35
+ s.slice(0, 6),
36
+ new Date(`${y}-${m}-${d}`), // YYYYMMDD
37
+ // new Date(y, m - 1, d, 0, 0, 0, 0), // 有时区问题
38
+ parseInt(s.slice(14, 17)),
39
+ s.slice(17, 18).toUpperCase(),
40
+ );
41
+ }
42
+ }
43
+
44
+ class IdNumber {
45
+ constructor(
46
+ public division: string,
47
+ public date: Date,
48
+ public sequence: number,
49
+ public checksum: string,
50
+ ) {}
51
+
52
+ toString() {
53
+ return this.subject + this.checksum;
54
+ }
55
+
56
+ toJSON() {
57
+ return this.toString();
58
+ }
59
+
60
+ toObject() {
61
+ const { division, date, sequence, checksum } = this;
62
+ return {
63
+ division,
64
+ date,
65
+ sequence,
66
+ checksum,
67
+ };
68
+ }
69
+
70
+ get male() {
71
+ return this.sequence % 2 === 1;
72
+ }
73
+
74
+ get female() {
75
+ return this.sequence % 2 === 0;
76
+ }
77
+
78
+ get age() {
79
+ return new Date().getFullYear() - this.date.getFullYear();
80
+ }
81
+
82
+ get gender(): 'male' | 'female' {
83
+ return this.sequence % 2 === 1 ? 'male' : 'female';
84
+ }
85
+
86
+ get subject() {
87
+ return [this.division, formatDate(this.date, 'YYYYMMDD'), this.sequence.toString().padStart(3, '0')].join('');
88
+ }
89
+ }
90
+
91
+ function formatDate(date: Date, format = 'YYYYMMDD') {
92
+ switch (format) {
93
+ case 'YYYYMMDD': {
94
+ const year = date.getFullYear();
95
+ const month = (date.getMonth() + 1).toString().padStart(2, '0');
96
+ const day = date.getDate().toString().padStart(2, '0');
97
+ return `${year}${month}${day}`;
98
+ }
99
+ default:
100
+ throw new Error(`Invalid format`);
101
+ }
102
+ }
@@ -0,0 +1,20 @@
1
+ import { test, assert, expect } from 'vitest';
2
+ import { Mod11Checksum } from './Mod11Checksum';
3
+ import { ResidentIdNumber } from './ResidentIdNumber';
4
+
5
+ test('id', (t) => {
6
+ const ids = ['11010519491231002X', '11010219840406970X'];
7
+
8
+ let cs = Mod11Checksum.get();
9
+ for (const id of ids) {
10
+ assert.equal(cs.generate(id.slice(0, -1)), id.at(-1));
11
+ }
12
+
13
+ let parse = ResidentIdNumber.get().parse(ids[0]);
14
+ expect(parse?.toObject()).toEqual({
15
+ division: '110105',
16
+ date: new Date('1949-12-31'),
17
+ sequence: 2,
18
+ checksum: 'X',
19
+ });
20
+ });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 居民身份证
3
+ *
4
+ * @see https://en.wikipedia.org/wiki/Resident_Identity_Card
5
+ * @see https://en.wikipedia.org/wiki/Foreign_Permanent_Resident_ID_Card
6
+ */
7
+ export interface ResidentIdentityCard {
8
+ // 姓名
9
+ name: string;
10
+ // 性别
11
+ gender: string;
12
+ // 民族
13
+ ethnicity: string;
14
+ // 出生日期
15
+ birthDate: Date;
16
+ // 地址
17
+ domicile: string;
18
+ // 身份证号
19
+ idNumber: string;
20
+ // 签发机关
21
+ issuingAuthority: string;
22
+ // 有效期开始日期
23
+ validStartDate: Date;
24
+ // 有效期结束日期
25
+ validEndDate?: Date;
26
+ }
package/src/cn/index.ts CHANGED
@@ -1 +1,14 @@
1
+ /**
2
+ * China related utilities.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+
1
7
  export { parseChineseNumber } from './parseChineseNumber';
8
+
9
+ export { isUSCC } from './uscc/isUSCC';
10
+ export { USCC } from './uscc/USCC';
11
+
12
+ export { ResidentIdNumber } from './id/ResidentIdNumber';
13
+
14
+ export { DivisionCode } from './division/DivisionCode';
@@ -0,0 +1,42 @@
1
+ /**
2
+ * GB/T 17710(采ISO 7064)的模31校验码
3
+ *
4
+ * Mod31-3
5
+ */
6
+ export class Mod31Checksum {
7
+ weights = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];
8
+ chars = '0123456789ABCDEFGHJKLMNPQRTUWXY';
9
+ numbers: Record<string, number> = this.chars.split('').reduce(
10
+ (acc, cur, i) => {
11
+ acc[cur] = i;
12
+ return acc;
13
+ },
14
+ {} as Record<string, number>,
15
+ );
16
+
17
+ private static instance: Mod31Checksum;
18
+
19
+ static get() {
20
+ return this.instance || (this.instance = new Mod31Checksum());
21
+ }
22
+
23
+ toChar(n: number) {
24
+ return this.chars[n];
25
+ }
26
+
27
+ toNumber(c: string) {
28
+ return this.numbers[c];
29
+ }
30
+
31
+ verify(s: string) {
32
+ return s.at(-1) === this.generate(s.slice(0, s.length - 1));
33
+ }
34
+
35
+ generate(s: string) {
36
+ let sum = 0;
37
+ for (let i = 0; i < s.length; i++) {
38
+ sum += this.numbers[s[i]] * this.weights[i];
39
+ }
40
+ return this.toChar(31 - (sum % 31));
41
+ }
42
+ }