@wener/utils 1.1.36 → 1.1.38

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 (111) hide show
  1. package/lib/asyncs/createLazyPromise.js +1 -3
  2. package/lib/asyncs/createLazyPromise.js.map +1 -1
  3. package/lib/browsers/download.js +20 -11
  4. package/lib/browsers/download.js.map +1 -1
  5. package/lib/cn/division/DivisionCode.js +204 -0
  6. package/lib/cn/division/DivisionCode.js.map +1 -0
  7. package/lib/cn/id/Mod11Checksum.js +46 -0
  8. package/lib/cn/id/Mod11Checksum.js.map +1 -0
  9. package/lib/cn/id/ResidentIdNumber.js +89 -0
  10. package/lib/cn/id/ResidentIdNumber.js.map +1 -0
  11. package/lib/cn/id/types.js +8 -0
  12. package/lib/cn/id/types.js.map +1 -0
  13. package/lib/cn/index.js +9 -1
  14. package/lib/cn/index.js.map +1 -1
  15. package/lib/cn/uscc/Mod31Checksum.js +52 -0
  16. package/lib/cn/uscc/Mod31Checksum.js.map +1 -0
  17. package/lib/cn/uscc/USCC.js +97 -0
  18. package/lib/cn/uscc/USCC.js.map +1 -0
  19. package/lib/cn/uscc/isUSCC.js +8 -0
  20. package/lib/cn/uscc/isUSCC.js.map +1 -0
  21. package/lib/crypto/getRandomValues.js +1 -1
  22. package/lib/crypto/getRandomValues.js.map +1 -1
  23. package/lib/crypto/randomUUID.js +1 -1
  24. package/lib/crypto/randomUUID.js.map +1 -1
  25. package/lib/crypto/randomUUIDv7.js +3 -0
  26. package/lib/crypto/randomUUIDv7.js.map +1 -0
  27. package/lib/errors/Errors.js +1 -1
  28. package/lib/errors/Errors.js.map +1 -1
  29. package/lib/fetch/HttpStatus.js.map +1 -0
  30. package/lib/fetch/createFetchWith.js +1 -1
  31. package/lib/fetch/createFetchWith.js.map +1 -1
  32. package/lib/fetch/createFetchWithRetry.js +1 -1
  33. package/lib/fetch/createFetchWithRetry.js.map +1 -1
  34. package/lib/index.js +7 -5
  35. package/lib/index.js.map +1 -1
  36. package/lib/io/ArrayBuffers.js +58 -4
  37. package/lib/io/ArrayBuffers.js.map +1 -1
  38. package/lib/io/isTransferable.js +1 -1
  39. package/lib/io/isTransferable.js.map +1 -1
  40. package/lib/io/parseDataUri.js +57 -0
  41. package/lib/io/parseDataUri.js.map +1 -0
  42. package/lib/objects/computeIfAbsent.js +14 -0
  43. package/lib/objects/computeIfAbsent.js.map +1 -0
  44. package/lib/runtime/AsyncCloser.js.map +1 -0
  45. package/lib/runtime/Closer.js.map +1 -0
  46. package/lib/runtime/getGlobalThis.js.map +1 -0
  47. package/lib/runtime/structuredClone.js.map +1 -0
  48. package/lib/server/fetch/createFetchWithProxyByNodeFetch.js +1 -1
  49. package/lib/server/fetch/createFetchWithProxyByNodeFetch.js.map +1 -1
  50. package/lib/server/fetch/createFetchWithProxyByUndici.js +1 -1
  51. package/lib/server/fetch/createFetchWithProxyByUndici.js.map +1 -1
  52. package/lib/server/getPackageDir.js +5 -4
  53. package/lib/server/getPackageDir.js.map +1 -1
  54. package/lib/server/polyfill/polyfillCrypto.js +1 -1
  55. package/lib/server/polyfill/polyfillCrypto.js.map +1 -1
  56. package/lib/server/polyfill/polyfillJsDom.js +1 -1
  57. package/lib/server/polyfill/polyfillJsDom.js.map +1 -1
  58. package/lib/server/polyfill/polyfillWebSocket.js +1 -1
  59. package/lib/server/polyfill/polyfillWebSocket.js.map +1 -1
  60. package/package.json +18 -15
  61. package/src/asyncs/createLazyPromise.ts +0 -2
  62. package/src/browsers/download.ts +20 -13
  63. package/src/cn/division/DivisionCode.ts +109 -0
  64. package/src/cn/id/Mod11Checksum.ts +29 -0
  65. package/src/cn/id/ResidentIdNumber.ts +102 -0
  66. package/src/cn/id/id.test.ts +20 -0
  67. package/src/cn/id/types.ts +26 -0
  68. package/src/cn/index.ts +13 -0
  69. package/src/cn/uscc/Mod31Checksum.ts +42 -0
  70. package/src/cn/uscc/USCC.ts +98 -0
  71. package/src/cn/uscc/isUSCC.ts +8 -0
  72. package/src/cn/uscc/uscc.test.ts +16 -0
  73. package/src/crypto/getRandomValues.ts +1 -1
  74. package/src/crypto/randomUUID.ts +1 -1
  75. package/src/crypto/randomUUIDv7.ts +1 -0
  76. package/src/errors/Errors.ts +1 -1
  77. package/src/fetch/createFetchWith.ts +1 -1
  78. package/src/fetch/createFetchWithRetry.ts +1 -1
  79. package/src/index.ts +7 -5
  80. package/src/io/ArrayBuffers.base64.test.ts +24 -0
  81. package/src/io/ArrayBuffers.ts +106 -4
  82. package/src/io/isTransferable.ts +1 -1
  83. package/src/io/parseDataUri.test.ts +34 -0
  84. package/src/io/parseDataUri.ts +66 -0
  85. package/src/objects/computeIfAbsent.ts +15 -0
  86. package/src/schema/typebox/gen/README.md +2 -0
  87. package/src/server/fetch/createFetchWithProxyByNodeFetch.ts +1 -1
  88. package/src/server/fetch/createFetchWithProxyByUndici.ts +1 -1
  89. package/src/server/getPackageDir.ts +6 -4
  90. package/src/server/polyfill/polyfillCrypto.ts +1 -1
  91. package/src/server/polyfill/polyfillJsDom.ts +1 -1
  92. package/src/server/polyfill/polyfillWebSocket.ts +1 -1
  93. package/lib/http/HttpStatus.js.map +0 -1
  94. package/lib/io/Bytes.js +0 -51
  95. package/lib/io/Bytes.js.map +0 -1
  96. package/lib/isomorphics/getGlobalThis.js.map +0 -1
  97. package/lib/isomorphics/structuredClone.js.map +0 -1
  98. package/lib/langs/AsyncCloser.js.map +0 -1
  99. package/lib/langs/Closer.js.map +0 -1
  100. package/src/io/Bytes.ts +0 -64
  101. /package/lib/{http → fetch}/HttpStatus.js +0 -0
  102. /package/lib/{langs → runtime}/AsyncCloser.js +0 -0
  103. /package/lib/{langs → runtime}/Closer.js +0 -0
  104. /package/lib/{isomorphics → runtime}/getGlobalThis.js +0 -0
  105. /package/lib/{isomorphics → runtime}/structuredClone.js +0 -0
  106. /package/src/{http → fetch}/HttpStatus.ts +0 -0
  107. /package/src/{langs → runtime}/AsyncCloser.ts +0 -0
  108. /package/src/{langs → runtime}/Closer.ts +0 -0
  109. /package/src/{isomorphics → runtime}/getGlobalThis.ts +0 -0
  110. /package/src/{isomorphics → runtime}/structuredClone.test.ts +0 -0
  111. /package/src/{isomorphics → runtime}/structuredClone.ts +0 -0
@@ -0,0 +1,66 @@
1
+ import { ArrayBuffers } from './ArrayBuffers';
2
+
3
+ export interface ParsedDataUri {
4
+ type: string;
5
+ params: Record<string, string | boolean>;
6
+ content: string;
7
+ base64: boolean;
8
+
9
+ getData(enc: 'utf-8' | 'base64'): Promise<string>;
10
+
11
+ getData(): Promise<ArrayBuffer>;
12
+ }
13
+
14
+ export function parseDataUri(data: string): undefined | ParsedDataUri {
15
+ if (!data || !data.startsWith('data:')) {
16
+ return;
17
+ }
18
+ // https://en.wikipedia.org/wiki/Data_URI_scheme
19
+ // data:content/type;base64,
20
+ // data:content/type;a=b,content
21
+ const [header, body] = data.split(',');
22
+ const [type, ...paramsStr] = header.slice('data:'.length).split(';');
23
+ const content = body;
24
+ const params: Record<string, string | boolean> = Object.fromEntries(
25
+ paramsStr.map((s) => {
26
+ const [k, v] = s.trim().split('=');
27
+ return [k, v ?? true];
28
+ }),
29
+ );
30
+ // params charset=utf-8
31
+ // params base64
32
+ // params a=b
33
+ let base64 = Boolean(params['base64']);
34
+ return {
35
+ type,
36
+ params,
37
+ content,
38
+ base64,
39
+ getData: async (enc?: 'utf-8' | 'base64') => {
40
+ if (!enc) {
41
+ return await fetch(data).then((v) => v.arrayBuffer());
42
+ }
43
+ //
44
+ let buf: BufferSource;
45
+ if (base64) {
46
+ if (enc === 'base64') {
47
+ return content;
48
+ }
49
+ buf = await fetch(data).then((v) => v.arrayBuffer());
50
+ } else {
51
+ let raw = decodeURIComponent(content);
52
+ if (enc === 'utf-8') {
53
+ return raw;
54
+ }
55
+ buf = ArrayBuffers.from(raw, 'utf-8');
56
+ }
57
+ if (enc === 'utf-8') {
58
+ return new TextDecoder(enc).decode(buf);
59
+ }
60
+ if (enc === 'base64') {
61
+ return ArrayBuffers.toString(buf, 'base64');
62
+ }
63
+ return buf;
64
+ },
65
+ } as ParsedDataUri;
66
+ }
@@ -0,0 +1,15 @@
1
+ export function computeIfAbsent<K, V>(map: Map<K, V>, key: K, fn: () => V): V ;
2
+ export function computeIfAbsent<K extends string | symbol | number, V>(map: Record<K, V>, key: K, fn: () => V): V ;
3
+ export function computeIfAbsent<K, V>(map: any, key: K, fn: () => V): V {
4
+ if (map instanceof Map) {
5
+ if (!map.has(key)) {
6
+ map.set(key, fn());
7
+ }
8
+ return map.get(key)!;
9
+ }
10
+
11
+ if (!map[key]) {
12
+ map[key] = fn();
13
+ }
14
+ return map[key];
15
+ }
@@ -0,0 +1,2 @@
1
+ - 增加了 literal 处理
2
+ - 关闭了内置 prettier
@@ -1,5 +1,5 @@
1
1
  import { type FetchLike } from '../../fetch';
2
- import { getGlobalThis } from '../../isomorphics/getGlobalThis';
2
+ import { getGlobalThis } from '../../runtime/getGlobalThis';
3
3
 
4
4
  export function createFetchWithProxyByNodeFetch({
5
5
  proxy,
@@ -1,6 +1,6 @@
1
1
  import { MaybePromise } from '../../asyncs/MaybePromise';
2
2
  import { createFetchWith, FetchLike } from '../../fetch';
3
- import { getGlobalThis } from '../../isomorphics/getGlobalThis';
3
+ import { getGlobalThis } from '../../runtime/getGlobalThis';
4
4
 
5
5
  export function createFetchWithProxyByUndici({
6
6
  proxy,
@@ -1,11 +1,11 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
3
 
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = path.dirname(__filename);
4
+ // import { fileURLToPath } from 'node:url';
5
+ // const __filename = fileURLToPath(import.meta.url);
6
+ // const __dirname = path.dirname(__filename);
7
7
 
8
- export function getPackageDir(currentDir: string = __dirname) {
8
+ export function getPackageDir(currentDir: string = process.cwd()) {
9
9
  while (!fs.existsSync(path.join(currentDir, 'package.json'))) {
10
10
  currentDir = path.resolve(currentDir, '..');
11
11
  if (currentDir === '/') {
@@ -14,3 +14,5 @@ export function getPackageDir(currentDir: string = __dirname) {
14
14
  }
15
15
  return currentDir;
16
16
  }
17
+
18
+ function findUp() {}
@@ -1,4 +1,4 @@
1
- import { getGlobalThis } from '../../isomorphics/getGlobalThis';
1
+ import { getGlobalThis } from '../../runtime/getGlobalThis';
2
2
 
3
3
  export async function polyfillCrypto() {
4
4
  const globalThis = getGlobalThis();
@@ -1,5 +1,5 @@
1
1
  import type { ConstructorOptions, ResourceLoaderConstructorOptions } from 'jsdom';
2
- import { getGlobalThis } from '../../isomorphics/getGlobalThis';
2
+ import { getGlobalThis } from '../../runtime/getGlobalThis';
3
3
 
4
4
  export async function polyfillJsDom() {
5
5
  if (typeof window !== 'undefined') {
@@ -1,5 +1,5 @@
1
1
  import type { MaybePromise } from '../../asyncs/MaybePromise';
2
- import { getGlobalThis } from '../../isomorphics/getGlobalThis';
2
+ import { getGlobalThis } from '../../runtime/getGlobalThis';
3
3
 
4
4
  export function polyfillWebSocket(ws: any): boolean;
5
5
  export function polyfillWebSocket(ws?: undefined): Promise<boolean>;
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/http/HttpStatus.ts"],"sourcesContent":["// http://httpstat.us/\n// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes\nconst HttpStatus: Record<string, string> = {\n 100: 'Continue',\n 101: 'Switching Protocols',\n 102: 'Processing',\n 103: 'Early Hints',\n 200: 'OK',\n 201: 'Created',\n 202: 'Accepted',\n 203: 'Non-Authoritative Information',\n 204: 'No Content',\n 205: 'Reset Content',\n 206: 'Partial Content',\n 207: 'Multi-Status',\n 208: 'Already Reported',\n 226: 'IM Used',\n 300: 'Multiple Choices',\n 301: 'Moved Permanently',\n 302: 'Found',\n 303: 'See Other',\n 304: 'Not Modified',\n 305: 'Use Proxy',\n 306: 'Unused',\n 307: 'Temporary Redirect',\n 308: 'Permanent Redirect',\n\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 402: 'Payment Required',\n 403: 'Forbidden',\n 404: 'Not Found',\n 405: 'Method Not Allowed',\n 406: 'Not Acceptable',\n 407: 'Proxy Authentication Required',\n 408: 'Request Timeout',\n 409: 'Conflict',\n 410: 'Gone',\n 411: 'Length Required',\n 412: 'Precondition Required',\n 413: 'Request Entry Too Large',\n 414: 'Request-URI Too Long',\n 415: 'Unsupported Media Type',\n 416: 'Requested Range Not Satisfiable',\n 417: 'Expectation Failed',\n 418: \"I'm a teapot\",\n 421: 'Misdirected Request',\n 422: 'Unprocessable Entity',\n 423: 'Locked',\n 424: 'Failed Dependency',\n 425: 'Too Early',\n 426: 'Upgrade Required',\n 428: 'Precondition Required',\n 429: 'Too Many Requests',\n 431: 'Request Header Fields Too Large',\n 451: 'Unavailable For Legal Reasons',\n 500: 'Internal Server Error',\n 501: 'Not Implemented',\n 502: 'Bad Gateway',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n 505: 'HTTP Version Not Supported',\n 506: 'Variant Also Negotiates',\n 507: 'Insufficient Storage',\n 508: 'Loop Detected',\n 509: 'Bandwidth Limit Exceeded',\n 510: 'Not Extended',\n 511: 'Network Authentication Required',\n};\n\nexport function getHttpStatusText(status: number | string): string | undefined {\n return HttpStatus[status];\n}\n\nexport function isRetryableHttpStatus(status: number) {\n switch (status) {\n /*\n408 Request Timeout\n425 Too Early\n429 Too Many Requests\n500 Internal Server Error\n502 Bad Gateway\n503 Service Unavailable\n504 Gateway Timeout\n */\n case 408:\n case 425:\n case 429:\n case 502:\n case 503:\n case 504:\n return true;\n default:\n return false;\n }\n}\n"],"names":["HttpStatus","getHttpStatusText","status","isRetryableHttpStatus"],"mappings":"AAAA,sBAAsB;AACtB,0DAA0D;AAC1D,MAAMA,aAAqC;IACzC,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IAEL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;AACP;AAEA,OAAO,SAASC,kBAAkBC,MAAuB;IACvD,OAAOF,UAAU,CAACE,OAAO;AAC3B;AAEA,OAAO,SAASC,sBAAsBD,MAAc;IAClD,OAAQA;QACN;;;;;;;;KAQC,GACD,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;YACH,OAAO;QACT;YACE,OAAO;IACX;AACF"}
package/lib/io/Bytes.js DELETED
@@ -1,51 +0,0 @@
1
- const objectToString = Object.prototype.toString;
2
- const uint8ArrayStringified = '[object Uint8Array]';
3
- /**
4
- * Utils for UInt8Array
5
- *
6
- * @see https://github.com/sindresorhus/uint8array-extras/blob/main/index.js
7
- */ export class Bytes {
8
- static #decoder = new globalThis.TextDecoder();
9
- static isUint8Array(value) {
10
- if (!value) {
11
- return false;
12
- }
13
- if (value.constructor === Uint8Array) {
14
- return true;
15
- }
16
- return objectToString.call(value) === uint8ArrayStringified;
17
- }
18
- static require(value) {
19
- if (!this.isUint8Array(value)) {
20
- throw new TypeError(`Expected \`Uint8Array\`, got \`${typeof value}\``);
21
- }
22
- return value;
23
- }
24
- static toUint8Array(value) {
25
- if (value instanceof ArrayBuffer) {
26
- return new Uint8Array(value);
27
- }
28
- if (ArrayBuffer.isView(value)) {
29
- return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
30
- }
31
- throw new TypeError(`Unsupported value, got \`${typeof value}\`.`);
32
- }
33
- static concat(arrays, totalLength) {
34
- if (arrays.length === 0) {
35
- return new Uint8Array(0);
36
- }
37
- totalLength ??= arrays.reduce((accumulator, currentValue)=>accumulator + currentValue.length, 0);
38
- const returnValue = new Uint8Array(totalLength);
39
- let offset = 0;
40
- for (const array of arrays){
41
- returnValue.set(this.require(array), offset);
42
- offset += array.length;
43
- }
44
- return returnValue;
45
- }
46
- static toString(value) {
47
- return this.#decoder.decode(value);
48
- }
49
- }
50
-
51
- //# sourceMappingURL=Bytes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/io/Bytes.ts"],"sourcesContent":["const objectToString = Object.prototype.toString;\nconst uint8ArrayStringified = '[object Uint8Array]';\n\n/**\n * Utils for UInt8Array\n *\n * @see https://github.com/sindresorhus/uint8array-extras/blob/main/index.js\n */\nexport class Bytes {\n static #decoder = new globalThis.TextDecoder();\n\n static isUint8Array(value: any): value is Uint8Array {\n if (!value) {\n return false;\n }\n\n if (value.constructor === Uint8Array) {\n return true;\n }\n\n return objectToString.call(value) === uint8ArrayStringified;\n }\n\n static require(value: any): Uint8Array {\n if (!this.isUint8Array(value)) {\n throw new TypeError(`Expected \\`Uint8Array\\`, got \\`${typeof value}\\``);\n }\n return value;\n }\n\n static toUint8Array(value: ArrayBuffer | ArrayBufferView): Uint8Array {\n if (value instanceof ArrayBuffer) {\n return new Uint8Array(value);\n }\n\n if (ArrayBuffer.isView(value)) {\n return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);\n }\n\n throw new TypeError(`Unsupported value, got \\`${typeof value}\\`.`);\n }\n\n static concat(arrays: Uint8Array[], totalLength: number): Uint8Array {\n if (arrays.length === 0) {\n return new Uint8Array(0);\n }\n\n totalLength ??= arrays.reduce((accumulator, currentValue) => accumulator + currentValue.length, 0);\n\n const returnValue = new Uint8Array(totalLength);\n\n let offset = 0;\n for (const array of arrays) {\n returnValue.set(this.require(array), offset);\n offset += array.length;\n }\n\n return returnValue;\n }\n\n static toString(value: Uint8Array) {\n return this.#decoder.decode(value);\n }\n}\n"],"names":["objectToString","Object","prototype","toString","uint8ArrayStringified","Bytes","decoder","globalThis","TextDecoder","isUint8Array","value","constructor","Uint8Array","call","require","TypeError","toUint8Array","ArrayBuffer","isView","buffer","byteOffset","byteLength","concat","arrays","totalLength","length","reduce","accumulator","currentValue","returnValue","offset","array","set","decode"],"mappings":"AAAA,MAAMA,iBAAiBC,OAAOC,SAAS,CAACC,QAAQ;AAChD,MAAMC,wBAAwB;AAE9B;;;;CAIC,GACD,OAAO,MAAMC;IACX,OAAO,CAACC,OAAO,GAAG,IAAIC,WAAWC,WAAW,GAAG;IAE/C,OAAOC,aAAaC,KAAU,EAAuB;QACnD,IAAI,CAACA,OAAO;YACV,OAAO;QACT;QAEA,IAAIA,MAAMC,WAAW,KAAKC,YAAY;YACpC,OAAO;QACT;QAEA,OAAOZ,eAAea,IAAI,CAACH,WAAWN;IACxC;IAEA,OAAOU,QAAQJ,KAAU,EAAc;QACrC,IAAI,CAAC,IAAI,CAACD,YAAY,CAACC,QAAQ;YAC7B,MAAM,IAAIK,UAAU,CAAC,+BAA+B,EAAE,OAAOL,MAAM,EAAE,CAAC;QACxE;QACA,OAAOA;IACT;IAEA,OAAOM,aAAaN,KAAoC,EAAc;QACpE,IAAIA,iBAAiBO,aAAa;YAChC,OAAO,IAAIL,WAAWF;QACxB;QAEA,IAAIO,YAAYC,MAAM,CAACR,QAAQ;YAC7B,OAAO,IAAIE,WAAWF,MAAMS,MAAM,EAAET,MAAMU,UAAU,EAAEV,MAAMW,UAAU;QACxE;QAEA,MAAM,IAAIN,UAAU,CAAC,yBAAyB,EAAE,OAAOL,MAAM,GAAG,CAAC;IACnE;IAEA,OAAOY,OAAOC,MAAoB,EAAEC,WAAmB,EAAc;QACnE,IAAID,OAAOE,MAAM,KAAK,GAAG;YACvB,OAAO,IAAIb,WAAW;QACxB;QAEAY,gBAAgBD,OAAOG,MAAM,CAAC,CAACC,aAAaC,eAAiBD,cAAcC,aAAaH,MAAM,EAAE;QAEhG,MAAMI,cAAc,IAAIjB,WAAWY;QAEnC,IAAIM,SAAS;QACb,KAAK,MAAMC,SAASR,OAAQ;YAC1BM,YAAYG,GAAG,CAAC,IAAI,CAAClB,OAAO,CAACiB,QAAQD;YACrCA,UAAUC,MAAMN,MAAM;QACxB;QAEA,OAAOI;IACT;IAEA,OAAO1B,SAASO,KAAiB,EAAE;QACjC,OAAO,IAAI,CAAC,CAACJ,OAAO,CAAC2B,MAAM,CAACvB;IAC9B;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/isomorphics/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 +0,0 @@
1
- {"version":3,"sources":["../../src/isomorphics/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"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/langs/AsyncCloser.ts"],"sourcesContent":["type AsyncClosable = { close(): void | Promise<void> } | (() => void | Promise<void>) | AsyncDisposable | Disposable;\n\n/**\n * @see AsyncDisposableStack\n */\nexport class AsyncCloser implements AsyncDisposable {\n closers: Array<AsyncClosable> = [];\n\n defer(closer: AsyncClosable | null | undefined) {\n if (!closer) {\n return;\n }\n this.closers.push(closer);\n }\n\n add<T extends AsyncClosable | null | undefined>(closer: T): T {\n if (!closer) {\n return closer;\n }\n this.closers.push(closer);\n return closer;\n }\n\n async [Symbol.asyncDispose]() {\n for (let closer of this.closers) {\n let o;\n if (typeof closer === 'function') {\n o = closer();\n } else if (Symbol.asyncDispose in closer) {\n o = closer[Symbol.asyncDispose]();\n } else if (Symbol.dispose in closer) {\n closer[Symbol.dispose]();\n } else {\n o = closer.close();\n }\n if (o && typeof o.then === 'function') {\n await o;\n }\n }\n }\n\n close() {\n return this[Symbol.asyncDispose]();\n }\n}\n"],"names":["AsyncCloser","closers","defer","closer","push","add","Symbol","asyncDispose","o","dispose","close","then"],"mappings":"AAEA;;CAEC,GACD,OAAO,MAAMA;IACXC,UAAgC,EAAE,CAAC;IAEnCC,MAAMC,MAAwC,EAAE;QAC9C,IAAI,CAACA,QAAQ;YACX;QACF;QACA,IAAI,CAACF,OAAO,CAACG,IAAI,CAACD;IACpB;IAEAE,IAAgDF,MAAS,EAAK;QAC5D,IAAI,CAACA,QAAQ;YACX,OAAOA;QACT;QACA,IAAI,CAACF,OAAO,CAACG,IAAI,CAACD;QAClB,OAAOA;IACT;IAEA,MAAM,CAACG,OAAOC,YAAY,CAAC,GAAG;QAC5B,KAAK,IAAIJ,UAAU,IAAI,CAACF,OAAO,CAAE;YAC/B,IAAIO;YACJ,IAAI,OAAOL,WAAW,YAAY;gBAChCK,IAAIL;YACN,OAAO,IAAIG,OAAOC,YAAY,IAAIJ,QAAQ;gBACxCK,IAAIL,MAAM,CAACG,OAAOC,YAAY,CAAC;YACjC,OAAO,IAAID,OAAOG,OAAO,IAAIN,QAAQ;gBACnCA,MAAM,CAACG,OAAOG,OAAO,CAAC;YACxB,OAAO;gBACLD,IAAIL,OAAOO,KAAK;YAClB;YACA,IAAIF,KAAK,OAAOA,EAAEG,IAAI,KAAK,YAAY;gBACrC,MAAMH;YACR;QACF;IACF;IAEAE,QAAQ;QACN,OAAO,IAAI,CAACJ,OAAOC,YAAY,CAAC;IAClC;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/langs/Closer.ts"],"sourcesContent":["type Closable = { close(): void } | (() => void) | Disposable;\n\n/**\n * @see DisposableStack\n */\nexport class Closer implements Disposable {\n closers: Array<Closable> = [];\n\n defer(closer: Closable | null | undefined) {\n if (!closer) {\n return;\n }\n this.closers.push(closer);\n }\n\n add<T extends Closable | null | undefined>(closer: T): T {\n if (!closer) {\n return closer;\n }\n this.closers.push(closer);\n return closer;\n }\n\n [Symbol.dispose]() {\n for (let closer of this.closers) {\n if (typeof closer === 'function') {\n closer();\n } else if (Symbol.dispose in closer) {\n closer[Symbol.dispose]();\n } else {\n closer.close();\n }\n }\n }\n\n close() {\n this[Symbol.dispose]();\n }\n}\n"],"names":["Closer","closers","defer","closer","push","add","Symbol","dispose","close"],"mappings":"AAEA;;CAEC,GACD,OAAO,MAAMA;IACXC,UAA2B,EAAE,CAAC;IAE9BC,MAAMC,MAAmC,EAAE;QACzC,IAAI,CAACA,QAAQ;YACX;QACF;QACA,IAAI,CAACF,OAAO,CAACG,IAAI,CAACD;IACpB;IAEAE,IAA2CF,MAAS,EAAK;QACvD,IAAI,CAACA,QAAQ;YACX,OAAOA;QACT;QACA,IAAI,CAACF,OAAO,CAACG,IAAI,CAACD;QAClB,OAAOA;IACT;IAEA,CAACG,OAAOC,OAAO,CAAC,GAAG;QACjB,KAAK,IAAIJ,UAAU,IAAI,CAACF,OAAO,CAAE;YAC/B,IAAI,OAAOE,WAAW,YAAY;gBAChCA;YACF,OAAO,IAAIG,OAAOC,OAAO,IAAIJ,QAAQ;gBACnCA,MAAM,CAACG,OAAOC,OAAO,CAAC;YACxB,OAAO;gBACLJ,OAAOK,KAAK;YACd;QACF;IACF;IAEAA,QAAQ;QACN,IAAI,CAACF,OAAOC,OAAO,CAAC;IACtB;AACF"}
package/src/io/Bytes.ts DELETED
@@ -1,64 +0,0 @@
1
- const objectToString = Object.prototype.toString;
2
- const uint8ArrayStringified = '[object Uint8Array]';
3
-
4
- /**
5
- * Utils for UInt8Array
6
- *
7
- * @see https://github.com/sindresorhus/uint8array-extras/blob/main/index.js
8
- */
9
- export class Bytes {
10
- static #decoder = new globalThis.TextDecoder();
11
-
12
- static isUint8Array(value: any): value is Uint8Array {
13
- if (!value) {
14
- return false;
15
- }
16
-
17
- if (value.constructor === Uint8Array) {
18
- return true;
19
- }
20
-
21
- return objectToString.call(value) === uint8ArrayStringified;
22
- }
23
-
24
- static require(value: any): Uint8Array {
25
- if (!this.isUint8Array(value)) {
26
- throw new TypeError(`Expected \`Uint8Array\`, got \`${typeof value}\``);
27
- }
28
- return value;
29
- }
30
-
31
- static toUint8Array(value: ArrayBuffer | ArrayBufferView): Uint8Array {
32
- if (value instanceof ArrayBuffer) {
33
- return new Uint8Array(value);
34
- }
35
-
36
- if (ArrayBuffer.isView(value)) {
37
- return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
38
- }
39
-
40
- throw new TypeError(`Unsupported value, got \`${typeof value}\`.`);
41
- }
42
-
43
- static concat(arrays: Uint8Array[], totalLength: number): Uint8Array {
44
- if (arrays.length === 0) {
45
- return new Uint8Array(0);
46
- }
47
-
48
- totalLength ??= arrays.reduce((accumulator, currentValue) => accumulator + currentValue.length, 0);
49
-
50
- const returnValue = new Uint8Array(totalLength);
51
-
52
- let offset = 0;
53
- for (const array of arrays) {
54
- returnValue.set(this.require(array), offset);
55
- offset += array.length;
56
- }
57
-
58
- return returnValue;
59
- }
60
-
61
- static toString(value: Uint8Array) {
62
- return this.#decoder.decode(value);
63
- }
64
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes