@wener/utils 1.1.48 → 1.1.50
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.
- package/lib/arrays/MaybeArray.js.map +1 -1
- package/lib/arrays/arrayFromAsync.js.map +1 -1
- package/lib/asyncs/AsyncInterval.js.map +1 -1
- package/lib/asyncs/MaybePromise.js.map +1 -1
- package/lib/asyncs/Promises.js +9 -1
- package/lib/asyncs/Promises.js.map +1 -1
- package/lib/asyncs/createAsyncIterator.js.map +1 -1
- package/lib/asyncs/createLazyPromise.js +52 -51
- package/lib/asyncs/createLazyPromise.js.map +1 -1
- package/lib/asyncs/firstOfAsyncIterator.js.map +1 -1
- package/lib/asyncs/generatorOfStream.js.map +1 -1
- package/lib/asyncs/isIterator.js.map +1 -1
- package/lib/asyncs/isPromise.js.map +1 -1
- package/lib/asyncs/isThenable.js.map +1 -1
- package/lib/asyncs/nextOfAsyncIterator.js.map +1 -1
- package/lib/asyncs/promiseOfCallback.js.map +1 -1
- package/lib/asyncs/timeout.js +4 -4
- package/lib/asyncs/timeout.js.map +1 -1
- package/lib/browsers/copy.js.map +1 -1
- package/lib/browsers/download.js.map +1 -1
- package/lib/browsers/getFileFromDataTransfer.js.map +1 -1
- package/lib/browsers/loaders.js.map +1 -1
- package/lib/cn/division/DivisionCode.js.map +1 -1
- package/lib/cn/division/binarySearch.js.map +1 -1
- package/lib/cn/formatChineseAmount.js.map +1 -1
- package/lib/cn/id/Mod11.js.map +1 -1
- package/lib/cn/id/ResidentIdNumber.js.map +1 -1
- package/lib/cn/id/types.js.map +1 -1
- package/lib/cn/index.js.map +1 -1
- package/lib/cn/parseChineseNumber.js.map +1 -1
- package/lib/cn/pinyin/cartesianProduct.js.map +1 -1
- package/lib/cn/pinyin/loader.js.map +1 -1
- package/lib/cn/pinyin/preload.js.map +1 -1
- package/lib/cn/pinyin/toPinyinPure.js.map +1 -1
- package/lib/cn/pinyin/transform.js.map +1 -1
- package/lib/cn/types.js +3 -0
- package/lib/cn/types.js.map +1 -0
- package/lib/cn/uscc/Mod31.js.map +1 -1
- package/lib/cn/uscc/USCC.js.map +1 -1
- package/lib/cn/uscc/isUSCC.js.map +1 -1
- package/lib/crypto/base.js.map +1 -1
- package/lib/crypto/getNodeCrypto.js +1 -0
- package/lib/crypto/getNodeCrypto.js.map +1 -1
- package/lib/crypto/getRandomValues.js.map +1 -1
- package/lib/crypto/hashing.js.map +1 -1
- package/lib/crypto/md5.bench.js.map +1 -1
- package/lib/crypto/md5.d.js.map +1 -1
- package/lib/crypto/md5.js.map +1 -1
- package/lib/crypto/pem/pem.js.map +1 -1
- package/lib/crypto/randomUUID.js.map +1 -1
- package/lib/crypto/randomUUIDv7.js.map +1 -1
- package/lib/crypto/ulid.js.map +1 -1
- package/lib/emitter/types.js.map +1 -1
- package/lib/errors/Errors.js +38 -17
- package/lib/errors/Errors.js.map +1 -1
- package/lib/fetch/HttpStatus.js.map +1 -1
- package/lib/fetch/createFetchWith.js.map +1 -1
- package/lib/fetch/createFetchWithLogging.js.map +1 -1
- package/lib/fetch/createFetchWithRetry.js.map +1 -1
- package/lib/fetch/dumpRequest.js.map +1 -1
- package/lib/fetch/dumpResponse.js.map +1 -1
- package/lib/fetch/http.types.js.map +1 -1
- package/lib/fetch/index.js.map +1 -1
- package/lib/fetch/types.js.map +1 -1
- package/lib/i18n/createTranslate.js.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/io/AbstractEncoding.js.map +1 -1
- package/lib/io/ArrayBuffer.test-d.js.map +1 -1
- package/lib/io/ArrayBuffers.js +217 -173
- package/lib/io/ArrayBuffers.js.map +1 -1
- package/lib/io/Buffer.js.map +1 -1
- package/lib/io/ByteBuffer.js +233 -34
- package/lib/io/ByteBuffer.js.map +1 -1
- package/lib/io/base64.js +2 -2
- package/lib/io/base64.js.map +1 -1
- package/lib/io/dump.js.map +1 -1
- package/lib/io/isBuffer.js.map +1 -1
- package/lib/io/isTransferable.js.map +1 -1
- package/lib/io/parseDataUri.js.map +1 -1
- package/lib/langs/MaybeFunction.js.map +1 -1
- package/lib/langs/classOf.js.map +1 -1
- package/lib/langs/deepEqual.js.map +1 -1
- package/lib/langs/deepFreeze.js.map +1 -1
- package/lib/langs/getGlobalStates.js +17 -0
- package/lib/langs/getGlobalStates.js.map +1 -0
- package/lib/langs/getObjectId.js +18 -0
- package/lib/langs/getObjectId.js.map +1 -0
- package/lib/langs/isClass.js.map +1 -1
- package/lib/langs/isDefined.js.map +1 -1
- package/lib/langs/isEmptyObject.js.map +1 -1
- package/lib/langs/isFunction.js.map +1 -1
- package/lib/langs/isNullish.js +5 -0
- package/lib/langs/isNullish.js.map +1 -0
- package/lib/langs/isPlainObject.js.map +1 -1
- package/lib/langs/memoize.js.map +1 -1
- package/lib/langs/mixin.js.map +1 -1
- package/lib/langs/parseBoolean.js.map +1 -1
- package/lib/langs/shallowClone.js.map +1 -1
- package/lib/langs/shallowEqual.js.map +1 -1
- package/lib/libs/ms.js.map +1 -1
- package/lib/logging/Logger.js.map +1 -1
- package/lib/logging/createChildLogger.js.map +1 -1
- package/lib/logging/createLogger.js.map +1 -1
- package/lib/logging/createNoopLogger.js.map +1 -1
- package/lib/logging/slog.js.map +1 -1
- package/lib/maths/clamp.js +7 -6
- package/lib/maths/clamp.js.map +1 -1
- package/lib/maths/random.js.map +1 -1
- package/lib/mitt/index.js.map +1 -1
- package/lib/modules/isModule.js.map +1 -1
- package/lib/modules/parseModuleId.js.map +1 -1
- package/lib/objects/computeIfAbsent.js.map +1 -1
- package/lib/objects/get.js.map +1 -1
- package/lib/objects/get.test-d.js.map +1 -1
- package/lib/objects/merge/index.js.map +1 -1
- package/lib/objects/merge/isMergeableObject.js.map +1 -1
- package/lib/objects/merge/merge.js.map +1 -1
- package/lib/objects/parseObjectPath.js.map +1 -1
- package/lib/objects/set.js.map +1 -1
- package/lib/runtime/AsyncCloser.js.map +1 -1
- package/lib/runtime/Closer.js.map +1 -1
- package/lib/runtime/getGlobalThis.js.map +1 -1
- package/lib/runtime/structuredClone.js.map +1 -1
- package/lib/schema/typebox/index.js.map +1 -1
- package/lib/schema/typebox/typebox.js.map +1 -1
- package/lib/scripts/getGenerateContext.js.map +1 -1
- package/lib/server/crypto/md5.js.map +1 -1
- package/lib/server/fetch/createFetchWithProxy.js.map +1 -1
- package/lib/server/fetch/createFetchWithProxyByNodeFetch.js.map +1 -1
- package/lib/server/fetch/createFetchWithProxyByUndici.js.map +1 -1
- package/lib/server/getPackageDir.js.map +1 -1
- package/lib/server/index.js.map +1 -1
- package/lib/server/jsdom.js.map +1 -1
- package/lib/server/node-fetch.js.map +1 -1
- package/lib/server/polyfill/polyfillBrowser.js.map +1 -1
- package/lib/server/polyfill/polyfillCrypto.js.map +1 -1
- package/lib/server/polyfill/polyfillFetch.js.map +1 -1
- package/lib/server/polyfill/polyfillJsDom.js.map +1 -1
- package/lib/server/polyfill/polyfillWebSocket.js.map +1 -1
- package/lib/server/ws.js.map +1 -1
- package/lib/strings/camelCase.js.map +1 -1
- package/lib/strings/formatBytes.js.map +1 -1
- package/lib/strings/renderTemplate.js.map +1 -1
- package/lib/typedoc.js.map +1 -1
- package/lib/types.d.js.map +1 -1
- package/lib/validations/asserts.js.map +1 -1
- package/lib/validations/isUUID.js.map +1 -1
- package/lib/validations/parseTimestamp.js.map +1 -1
- package/package.json +4 -4
- package/src/asyncs/Promises.ts +12 -2
- package/src/asyncs/createLazyPromise.test.ts +52 -13
- package/src/asyncs/createLazyPromise.ts +66 -61
- package/src/asyncs/firstOfAsyncIterator.ts +1 -1
- package/src/asyncs/nextOfAsyncIterator.ts +1 -1
- package/src/asyncs/timeout.ts +4 -4
- package/src/cn/types.ts +11 -0
- package/src/crypto/getNodeCrypto.ts +1 -0
- package/src/errors/Errors.ts +37 -16
- package/src/fetch/createFetchWith.ts +1 -1
- package/src/fetch/createFetchWithRetry.ts +1 -1
- package/src/index.ts +2 -0
- package/src/io/ArrayBuffers.base64.test.ts +7 -0
- package/src/io/ArrayBuffers.ts +276 -271
- package/src/io/ByteBuffer.test.ts +26 -14
- package/src/io/ByteBuffer.ts +270 -38
- package/src/io/base64.ts +2 -2
- package/src/langs/getGlobalStates.ts +21 -0
- package/src/langs/getObjectId.ts +20 -0
- package/src/langs/isNullish.ts +3 -0
- package/src/langs/mixin.test.ts +4 -0
- package/src/logging/slog.ts +1 -1
- package/src/maths/clamp.test.ts +5 -1
- package/src/maths/clamp.ts +7 -7
- package/src/objects/merge/merge.test.ts +1 -1
- package/src/schema/typebox/typebox.ts +1 -1
- package/src/server/fetch/createFetchWithProxyByUndici.ts +2 -2
- package/tsconfig.json +4 -1
- package/lib/schema/typebox/gen/codegen/common/encoder.js +0 -94
- package/lib/schema/typebox/gen/codegen/common/encoder.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/common/formatter.js +0 -33
- package/lib/schema/typebox/gen/codegen/common/formatter.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/common/index.js +0 -29
- package/lib/schema/typebox/gen/codegen/common/index.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/common/jsdoc.js +0 -117
- package/lib/schema/typebox/gen/codegen/common/jsdoc.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/expression/compiler.js +0 -364
- package/lib/schema/typebox/gen/codegen/expression/compiler.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/expression/errors.js +0 -259
- package/lib/schema/typebox/gen/codegen/expression/errors.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/expression/evaluator.js +0 -254
- package/lib/schema/typebox/gen/codegen/expression/evaluator.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/expression/expression.js +0 -381
- package/lib/schema/typebox/gen/codegen/expression/expression.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/expression/index.js +0 -32
- package/lib/schema/typebox/gen/codegen/expression/index.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/index.js +0 -29
- package/lib/schema/typebox/gen/codegen/index.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/index.js +0 -40
- package/lib/schema/typebox/gen/codegen/model/index.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model-to-arktype.js +0 -260
- package/lib/schema/typebox/gen/codegen/model/model-to-arktype.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model-to-expression.js +0 -383
- package/lib/schema/typebox/gen/codegen/model/model-to-expression.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model-to-grpc.js +0 -238
- package/lib/schema/typebox/gen/codegen/model/model-to-grpc.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model-to-io-ts.js +0 -274
- package/lib/schema/typebox/gen/codegen/model/model-to-io-ts.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model-to-javascript.js +0 -47
- package/lib/schema/typebox/gen/codegen/model/model-to-javascript.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model-to-json-schema.js +0 -192
- package/lib/schema/typebox/gen/codegen/model/model-to-json-schema.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model-to-typebox.js +0 -33
- package/lib/schema/typebox/gen/codegen/model/model-to-typebox.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model-to-typescript.js +0 -188
- package/lib/schema/typebox/gen/codegen/model/model-to-typescript.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model-to-valibot.js +0 -239
- package/lib/schema/typebox/gen/codegen/model/model-to-valibot.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model-to-value.js +0 -43
- package/lib/schema/typebox/gen/codegen/model/model-to-value.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model-to-yrel.js +0 -227
- package/lib/schema/typebox/gen/codegen/model/model-to-yrel.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model-to-yup.js +0 -225
- package/lib/schema/typebox/gen/codegen/model/model-to-yup.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model-to-zod.js +0 -248
- package/lib/schema/typebox/gen/codegen/model/model-to-zod.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/model/model.js +0 -27
- package/lib/schema/typebox/gen/codegen/model/model.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/typescript/index.js +0 -28
- package/lib/schema/typebox/gen/codegen/typescript/index.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-model.js +0 -72
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-model.js.map +0 -1
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-typebox.js +0 -620
- package/lib/schema/typebox/gen/codegen/typescript/typescript-to-typebox.js.map +0 -1
- package/lib/schema/typebox/gen/index.js +0 -3
- package/lib/schema/typebox/gen/index.js.map +0 -1
- package/src/schema/typebox/gen/codegen/common/encoder.ts +0 -99
- package/src/schema/typebox/gen/codegen/common/formatter.ts +0 -31
- package/src/schema/typebox/gen/codegen/common/index.ts +0 -29
- package/src/schema/typebox/gen/codegen/common/jsdoc.ts +0 -93
- package/src/schema/typebox/gen/codegen/expression/compiler.ts +0 -377
- package/src/schema/typebox/gen/codegen/expression/errors.ts +0 -302
- package/src/schema/typebox/gen/codegen/expression/evaluator.ts +0 -268
- package/src/schema/typebox/gen/codegen/expression/expression.ts +0 -538
- package/src/schema/typebox/gen/codegen/expression/index.ts +0 -32
- package/src/schema/typebox/gen/codegen/index.ts +0 -29
- package/src/schema/typebox/gen/codegen/model/index.ts +0 -40
- package/src/schema/typebox/gen/codegen/model/model-to-arktype.ts +0 -266
- package/src/schema/typebox/gen/codegen/model/model-to-expression.ts +0 -378
- package/src/schema/typebox/gen/codegen/model/model-to-grpc.ts +0 -244
- package/src/schema/typebox/gen/codegen/model/model-to-io-ts.ts +0 -294
- package/src/schema/typebox/gen/codegen/model/model-to-javascript.ts +0 -42
- package/src/schema/typebox/gen/codegen/model/model-to-json-schema.ts +0 -166
- package/src/schema/typebox/gen/codegen/model/model-to-typebox.ts +0 -32
- package/src/schema/typebox/gen/codegen/model/model-to-typescript.ts +0 -189
- package/src/schema/typebox/gen/codegen/model/model-to-valibot.ts +0 -236
- package/src/schema/typebox/gen/codegen/model/model-to-value.ts +0 -42
- package/src/schema/typebox/gen/codegen/model/model-to-yrel.ts +0 -232
- package/src/schema/typebox/gen/codegen/model/model-to-yup.ts +0 -226
- package/src/schema/typebox/gen/codegen/model/model-to-zod.ts +0 -251
- package/src/schema/typebox/gen/codegen/model/model.ts +0 -33
- package/src/schema/typebox/gen/codegen/typescript/index.ts +0 -28
- package/src/schema/typebox/gen/codegen/typescript/typescript-to-model.ts +0 -61
- package/src/schema/typebox/gen/codegen/typescript/typescript-to-typebox.ts +0 -647
- package/src/schema/typebox/gen/gen.test.ts +0 -12
- package/src/schema/typebox/gen/index.ts +0 -1
- /package/src/schema/{typebox/gen/README.md → README.md} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fetch/dumpRequest.ts"],"sourcesContent":["export function dumpRequest({\n url,\n req = {},\n log = console.log,\n}: {\n url: string;\n req?: RequestInit;\n log?: (s: string) => void;\n}) {\n const { method = 'GET' } = req;\n let out = `-> ${method} ${url}\n${Array.from(new Headers(req.headers).entries())\n .map(([k, v]) => `${k}: ${v}`)\n .join('\\n')}\n`;\n\n let done: Promise<string> | undefined;\n if (req.body) {\n let hdr = new Headers(req.headers);\n let ct = hdr.get('content-type');\n if (ct === 'application/octet-stream') {\n // skip\n } else if (req.body instanceof ReadableStream) {\n const [a, b] = req.body.tee();\n req.body = a;\n const signal = req.signal;\n done = Promise.resolve().then(async () => {\n const reader = b.getReader();\n log(out);\n while (true) {\n if (signal?.aborted) {\n break;\n }\n\n let { done, value } = await reader.read();\n value instanceof Uint8Array && (value = new TextDecoder().decode(value));\n out += value;\n log(value);\n if (!done) {\n break;\n }\n }\n // maybe for archive\n out += `\\n`;\n return out;\n });\n } else {\n out += `\n${req.body}\n`;\n }\n log(out);\n }\n return done || Promise.resolve(out);\n}\n"],"names":["dumpRequest","url","req","log","console","method","out","Array","from","Headers","headers","entries","map","k","v","join","done","body","hdr","ct","get","ReadableStream","a","b","tee","signal","Promise","resolve","then","reader","getReader","aborted","value","read","Uint8Array","TextDecoder","decode"],"
|
|
1
|
+
{"version":3,"sources":["../../src/fetch/dumpRequest.ts"],"sourcesContent":["export function dumpRequest({\n url,\n req = {},\n log = console.log,\n}: {\n url: string;\n req?: RequestInit;\n log?: (s: string) => void;\n}) {\n const { method = 'GET' } = req;\n let out = `-> ${method} ${url}\n${Array.from(new Headers(req.headers).entries())\n .map(([k, v]) => `${k}: ${v}`)\n .join('\\n')}\n`;\n\n let done: Promise<string> | undefined;\n if (req.body) {\n let hdr = new Headers(req.headers);\n let ct = hdr.get('content-type');\n if (ct === 'application/octet-stream') {\n // skip\n } else if (req.body instanceof ReadableStream) {\n const [a, b] = req.body.tee();\n req.body = a;\n const signal = req.signal;\n done = Promise.resolve().then(async () => {\n const reader = b.getReader();\n log(out);\n while (true) {\n if (signal?.aborted) {\n break;\n }\n\n let { done, value } = await reader.read();\n value instanceof Uint8Array && (value = new TextDecoder().decode(value));\n out += value;\n log(value);\n if (!done) {\n break;\n }\n }\n // maybe for archive\n out += `\\n`;\n return out;\n });\n } else {\n out += `\n${req.body}\n`;\n }\n log(out);\n }\n return done || Promise.resolve(out);\n}\n"],"names":["dumpRequest","url","req","log","console","method","out","Array","from","Headers","headers","entries","map","k","v","join","done","body","hdr","ct","get","ReadableStream","a","b","tee","signal","Promise","resolve","then","reader","getReader","aborted","value","read","Uint8Array","TextDecoder","decode"],"mappings":"AAAA,OAAO,SAASA,YAAY,EAC1BC,GAAG,EACHC,MAAM,CAAC,CAAC,EACRC,MAAMC,QAAQD,GAAG,EAKlB;IACC,MAAM,EAAEE,SAAS,KAAK,EAAE,GAAGH;IAC3B,IAAII,MAAM,CAAC,GAAG,EAAED,OAAO,CAAC,EAAEJ,IAAI;AAChC,EAAEM,MAAMC,IAAI,CAAC,IAAIC,QAAQP,IAAIQ,OAAO,EAAEC,OAAO,IAC1CC,GAAG,CAAC,CAAC,CAACC,GAAGC,EAAE,GAAK,GAAGD,EAAE,EAAE,EAAEC,GAAG,EAC5BC,IAAI,CAAC,MAAM;AACd,CAAC;IAEC,IAAIC;IACJ,IAAId,IAAIe,IAAI,EAAE;QACZ,IAAIC,MAAM,IAAIT,QAAQP,IAAIQ,OAAO;QACjC,IAAIS,KAAKD,IAAIE,GAAG,CAAC;QACjB,IAAID,OAAO,4BAA4B;QACrC,OAAO;QACT,OAAO,IAAIjB,IAAIe,IAAI,YAAYI,gBAAgB;YAC7C,MAAM,CAACC,GAAGC,EAAE,GAAGrB,IAAIe,IAAI,CAACO,GAAG;YAC3BtB,IAAIe,IAAI,GAAGK;YACX,MAAMG,SAASvB,IAAIuB,MAAM;YACzBT,OAAOU,QAAQC,OAAO,GAAGC,IAAI,CAAC;gBAC5B,MAAMC,SAASN,EAAEO,SAAS;gBAC1B3B,IAAIG;gBACJ,MAAO,KAAM;oBACX,IAAImB,QAAQM,SAAS;wBACnB;oBACF;oBAEA,IAAI,EAAEf,IAAI,EAAEgB,KAAK,EAAE,GAAG,MAAMH,OAAOI,IAAI;oBACvCD,iBAAiBE,cAAeF,CAAAA,QAAQ,IAAIG,cAAcC,MAAM,CAACJ,MAAK;oBACtE1B,OAAO0B;oBACP7B,IAAI6B;oBACJ,IAAI,CAAChB,MAAM;wBACT;oBACF;gBACF;gBACA,oBAAoB;gBACpBV,OAAO,CAAC,EAAE,CAAC;gBACX,OAAOA;YACT;QACF,OAAO;YACLA,OAAO,CAAC;AACd,EAAEJ,IAAIe,IAAI,CAAC;AACX,CAAC;QACG;QACAd,IAAIG;IACN;IACA,OAAOU,QAAQU,QAAQC,OAAO,CAACrB;AACjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fetch/dumpResponse.ts"],"sourcesContent":["export async function dumpResponse({\n res,\n url,\n req,\n log = console.log,\n}: {\n res: Response;\n url: string;\n req: RequestInit;\n log?: (s: string) => void;\n}) {\n let out = `<- ${res.status} ${res.statusText} ${req.method} ${url}\n${Array.from(res.headers.entries())\n .map(([k, v]) => `${k}: ${v}`)\n .join('\\n')}\n `;\n let contentType = res.headers.get('content-type');\n // TODO text/event-stream\n if (contentType?.includes('application/json') || contentType?.includes('text/plain')) {\n const body = await res.text();\n out += `\\n${body}\\n`;\n res = new Response(body, res);\n }\n\n log(out);\n\n return res;\n}\n"],"names":["dumpResponse","res","url","req","log","console","out","status","statusText","method","Array","from","headers","entries","map","k","v","join","contentType","get","includes","body","text","Response"],"
|
|
1
|
+
{"version":3,"sources":["../../src/fetch/dumpResponse.ts"],"sourcesContent":["export async function dumpResponse({\n res,\n url,\n req,\n log = console.log,\n}: {\n res: Response;\n url: string;\n req: RequestInit;\n log?: (s: string) => void;\n}) {\n let out = `<- ${res.status} ${res.statusText} ${req.method} ${url}\n${Array.from(res.headers.entries())\n .map(([k, v]) => `${k}: ${v}`)\n .join('\\n')}\n `;\n let contentType = res.headers.get('content-type');\n // TODO text/event-stream\n if (contentType?.includes('application/json') || contentType?.includes('text/plain')) {\n const body = await res.text();\n out += `\\n${body}\\n`;\n res = new Response(body, res);\n }\n\n log(out);\n\n return res;\n}\n"],"names":["dumpResponse","res","url","req","log","console","out","status","statusText","method","Array","from","headers","entries","map","k","v","join","contentType","get","includes","body","text","Response"],"mappings":"AAAA,OAAO,eAAeA,aAAa,EACjCC,GAAG,EACHC,GAAG,EACHC,GAAG,EACHC,MAAMC,QAAQD,GAAG,EAMlB;IACC,IAAIE,MAAM,CAAC,GAAG,EAAEL,IAAIM,MAAM,CAAC,CAAC,EAAEN,IAAIO,UAAU,CAAC,CAAC,EAAEL,IAAIM,MAAM,CAAC,CAAC,EAAEP,IAAI;AACpE,EAAEQ,MAAMC,IAAI,CAACV,IAAIW,OAAO,CAACC,OAAO,IAC7BC,GAAG,CAAC,CAAC,CAACC,GAAGC,EAAE,GAAK,GAAGD,EAAE,EAAE,EAAEC,GAAG,EAC5BC,IAAI,CAAC,MAAM;GACX,CAAC;IACF,IAAIC,cAAcjB,IAAIW,OAAO,CAACO,GAAG,CAAC;IAClC,yBAAyB;IACzB,IAAID,aAAaE,SAAS,uBAAuBF,aAAaE,SAAS,eAAe;QACpF,MAAMC,OAAO,MAAMpB,IAAIqB,IAAI;QAC3BhB,OAAO,CAAC,EAAE,EAAEe,KAAK,EAAE,CAAC;QACpBpB,MAAM,IAAIsB,SAASF,MAAMpB;IAC3B;IAEAG,IAAIE;IAEJ,OAAOL;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fetch/http.types.ts"],"sourcesContent":["// from hono\n\nexport type InfoStatusCode = 100 | 101 | 102 | 103;\nexport type SuccessStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;\nexport type DeprecatedStatusCode = 305 | 306;\nexport type RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | DeprecatedStatusCode | 307 | 308;\nexport type ClientErrorStatusCode =\n | 400\n | 401\n | 402\n | 403\n | 404\n | 405\n | 406\n | 407\n | 408\n | 409\n | 410\n | 411\n | 412\n | 413\n | 414\n | 415\n | 416\n | 417\n | 418\n | 421\n | 422\n | 423\n | 424\n | 425\n | 426\n | 428\n | 429\n | 431\n | 451;\nexport type ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;\n\nexport type UnofficialStatusCode = -1;\nexport type StatusCode =\n | InfoStatusCode\n | SuccessStatusCode\n | RedirectStatusCode\n | ClientErrorStatusCode\n | ServerErrorStatusCode\n | UnofficialStatusCode;\n"],"names":[],"
|
|
1
|
+
{"version":3,"sources":["../../src/fetch/http.types.ts"],"sourcesContent":["// from hono\n\nexport type InfoStatusCode = 100 | 101 | 102 | 103;\nexport type SuccessStatusCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;\nexport type DeprecatedStatusCode = 305 | 306;\nexport type RedirectStatusCode = 300 | 301 | 302 | 303 | 304 | DeprecatedStatusCode | 307 | 308;\nexport type ClientErrorStatusCode =\n | 400\n | 401\n | 402\n | 403\n | 404\n | 405\n | 406\n | 407\n | 408\n | 409\n | 410\n | 411\n | 412\n | 413\n | 414\n | 415\n | 416\n | 417\n | 418\n | 421\n | 422\n | 423\n | 424\n | 425\n | 426\n | 428\n | 429\n | 431\n | 451;\nexport type ServerErrorStatusCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;\n\nexport type UnofficialStatusCode = -1;\nexport type StatusCode =\n | InfoStatusCode\n | SuccessStatusCode\n | RedirectStatusCode\n | ClientErrorStatusCode\n | ServerErrorStatusCode\n | UnofficialStatusCode;\n"],"names":[],"mappings":"AAAA,YAAY;AAuCZ,WAMyB"}
|
package/lib/fetch/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fetch/index.ts"],"sourcesContent":["export type * from './types';\nexport { createFetchWith } from './createFetchWith';\nexport { createFetchWithLogging } from './createFetchWithLogging';\nexport { dumpRequest } from './dumpRequest';\nexport { dumpResponse } from './dumpResponse';\nexport { createFetchWithRetry, type FetchWithRetryOptions } from './createFetchWithRetry';\n"],"names":["createFetchWith","createFetchWithLogging","dumpRequest","dumpResponse","createFetchWithRetry"],"
|
|
1
|
+
{"version":3,"sources":["../../src/fetch/index.ts"],"sourcesContent":["export type * from './types';\nexport { createFetchWith } from './createFetchWith';\nexport { createFetchWithLogging } from './createFetchWithLogging';\nexport { dumpRequest } from './dumpRequest';\nexport { dumpResponse } from './dumpResponse';\nexport { createFetchWithRetry, type FetchWithRetryOptions } from './createFetchWithRetry';\n"],"names":["createFetchWith","createFetchWithLogging","dumpRequest","dumpResponse","createFetchWithRetry"],"mappings":"AACA,SAASA,eAAe,QAAQ,oBAAoB;AACpD,SAASC,sBAAsB,QAAQ,2BAA2B;AAClE,SAASC,WAAW,QAAQ,gBAAgB;AAC5C,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,oBAAoB,QAAoC,yBAAyB"}
|
package/lib/fetch/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fetch/types.ts"],"sourcesContent":["export type FetchLike<R extends RequestInit = RequestInit> = (\n url: string | URL | Request,\n init?: R,\n) => Promise<Response>;\n"],"names":[],"
|
|
1
|
+
{"version":3,"sources":["../../src/fetch/types.ts"],"sourcesContent":["export type FetchLike<R extends RequestInit = RequestInit> = (\n url: string | URL | Request,\n init?: R,\n) => Promise<Response>;\n"],"names":[],"mappings":"AAAA,WAGuB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/i18n/createTranslate.ts"],"sourcesContent":["import { get } from '../objects/get';\nimport type { ObjectPathLike } from '../objects/parseObjectPath';\nimport { renderTemplate } from '../strings/renderTemplate';\n\nexport interface Translate<T extends object> {\n /** Get/Set the language key */\n locale(lang?: string): string;\n\n /** Define the dict of translations for a language */\n dict(lang: string, dict: T): void;\n\n /** Get the dict of translations for a language */\n dict(lang: string): T;\n\n /** Retrieve a translation segment for the current language */\n t<X extends Record<string, any> | any[]>(key: ObjectPathLike, params?: X, lang?: string): string;\n}\n\nexport function createTranslate<T extends object>(obj?: Record<string, T>): Translate<T> {\n let locale = '';\n const tree = obj || {};\n // en-US -> en-US,en\n const keyOfDict = (s: string | string[]) => {\n if (Array.isArray(s)) {\n return s;\n }\n const sp = s.split(/[_-]/);\n if (sp.length > 1) {\n return [s, sp[0]];\n }\n return [s];\n };\n return {\n locale(lang) {\n return (locale = lang || locale);\n },\n\n dict: ((lang, dict?) => {\n if (dict) {\n tree[lang] = Object.assign(tree[lang] || {}, dict);\n return;\n }\n return tree[lang];\n }) as Translate<T>['dict'],\n\n t(key, params, lang) {\n let val: any;\n for (const k of keyOfDict(lang || locale)) {\n val = get(tree[k], key, '');\n if (val) {\n break;\n }\n }\n if (process.env.NODE_ENV === 'development') {\n if (val == null) {\n console.error(\n `[Translate] Missing the \"${[].concat(key as any).join('.')}\" key within the \"${\n lang || locale\n }\" dictionary`,\n );\n return;\n }\n }\n if (typeof val === 'function') return val(params);\n if (typeof val === 'string') return renderTemplate(val, params, 'common');\n return val;\n },\n };\n}\n"],"names":["get","renderTemplate","createTranslate","obj","locale","tree","keyOfDict","s","Array","isArray","sp","split","length","lang","dict","Object","assign","t","key","params","val","k","process","env","NODE_ENV","console","error","concat","join"],"
|
|
1
|
+
{"version":3,"sources":["../../src/i18n/createTranslate.ts"],"sourcesContent":["import { get } from '../objects/get';\nimport type { ObjectPathLike } from '../objects/parseObjectPath';\nimport { renderTemplate } from '../strings/renderTemplate';\n\nexport interface Translate<T extends object> {\n /** Get/Set the language key */\n locale(lang?: string): string;\n\n /** Define the dict of translations for a language */\n dict(lang: string, dict: T): void;\n\n /** Get the dict of translations for a language */\n dict(lang: string): T;\n\n /** Retrieve a translation segment for the current language */\n t<X extends Record<string, any> | any[]>(key: ObjectPathLike, params?: X, lang?: string): string;\n}\n\nexport function createTranslate<T extends object>(obj?: Record<string, T>): Translate<T> {\n let locale = '';\n const tree = obj || {};\n // en-US -> en-US,en\n const keyOfDict = (s: string | string[]) => {\n if (Array.isArray(s)) {\n return s;\n }\n const sp = s.split(/[_-]/);\n if (sp.length > 1) {\n return [s, sp[0]];\n }\n return [s];\n };\n return {\n locale(lang) {\n return (locale = lang || locale);\n },\n\n dict: ((lang, dict?) => {\n if (dict) {\n tree[lang] = Object.assign(tree[lang] || {}, dict);\n return;\n }\n return tree[lang];\n }) as Translate<T>['dict'],\n\n t(key, params, lang) {\n let val: any;\n for (const k of keyOfDict(lang || locale)) {\n val = get(tree[k], key, '');\n if (val) {\n break;\n }\n }\n if (process.env.NODE_ENV === 'development') {\n if (val == null) {\n console.error(\n `[Translate] Missing the \"${[].concat(key as any).join('.')}\" key within the \"${\n lang || locale\n }\" dictionary`,\n );\n return;\n }\n }\n if (typeof val === 'function') return val(params);\n if (typeof val === 'string') return renderTemplate(val, params, 'common');\n return val;\n },\n };\n}\n"],"names":["get","renderTemplate","createTranslate","obj","locale","tree","keyOfDict","s","Array","isArray","sp","split","length","lang","dict","Object","assign","t","key","params","val","k","process","env","NODE_ENV","console","error","concat","join"],"mappings":"AAAA,SAASA,GAAG,QAAQ,iBAAiB;AAErC,SAASC,cAAc,QAAQ,4BAA4B;AAgB3D,OAAO,SAASC,gBAAkCC,GAAuB;IACvE,IAAIC,SAAS;IACb,MAAMC,OAAOF,OAAO,CAAC;IACrB,oBAAoB;IACpB,MAAMG,YAAY,CAACC;QACjB,IAAIC,MAAMC,OAAO,CAACF,IAAI;YACpB,OAAOA;QACT;QACA,MAAMG,KAAKH,EAAEI,KAAK,CAAC;QACnB,IAAID,GAAGE,MAAM,GAAG,GAAG;YACjB,OAAO;gBAACL;gBAAGG,EAAE,CAAC,EAAE;aAAC;QACnB;QACA,OAAO;YAACH;SAAE;IACZ;IACA,OAAO;QACLH,QAAOS,IAAI;YACT,OAAQT,SAASS,QAAQT;QAC3B;QAEAU,MAAO,CAACD,MAAMC;YACZ,IAAIA,MAAM;gBACRT,IAAI,CAACQ,KAAK,GAAGE,OAAOC,MAAM,CAACX,IAAI,CAACQ,KAAK,IAAI,CAAC,GAAGC;gBAC7C;YACF;YACA,OAAOT,IAAI,CAACQ,KAAK;QACnB;QAEAI,GAAEC,GAAG,EAAEC,MAAM,EAAEN,IAAI;YACjB,IAAIO;YACJ,KAAK,MAAMC,KAAKf,UAAUO,QAAQT,QAAS;gBACzCgB,MAAMpB,IAAIK,IAAI,CAACgB,EAAE,EAAEH,KAAK;gBACxB,IAAIE,KAAK;oBACP;gBACF;YACF;YACA,IAAIE,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;gBAC1C,IAAIJ,OAAO,MAAM;oBACfK,QAAQC,KAAK,CACX,CAAC,yBAAyB,EAAE,EAAE,CAACC,MAAM,CAACT,KAAYU,IAAI,CAAC,KAAK,kBAAkB,EAC5Ef,QAAQT,OACT,YAAY,CAAC;oBAEhB;gBACF;YACF;YACA,IAAI,OAAOgB,QAAQ,YAAY,OAAOA,IAAID;YAC1C,IAAI,OAAOC,QAAQ,UAAU,OAAOnB,eAAemB,KAAKD,QAAQ;YAChE,OAAOC;QACT;IACF;AACF"}
|
package/lib/index.js
CHANGED
|
@@ -34,6 +34,8 @@ export { parseBoolean } from './langs/parseBoolean.js';
|
|
|
34
34
|
export { maybeFunction } from './langs/MaybeFunction.js';
|
|
35
35
|
export { memoize } from './langs/memoize.js';
|
|
36
36
|
export { mixin } from './langs/mixin.js';
|
|
37
|
+
export { getObjectId } from './langs/getObjectId.js';
|
|
38
|
+
export { getGlobalStates, setGlobalStates } from './langs/getGlobalStates.js';
|
|
37
39
|
export { AsyncCloser } from './runtime/AsyncCloser.js';
|
|
38
40
|
export { Closer } from './runtime/Closer.js';
|
|
39
41
|
export { isUUID } from './validations/isUUID.js';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Promises } from './asyncs/Promises';\n\n// arrays\nexport {\n firstOfMaybeArray,\n lastOfMaybeArray,\n arrayOfMaybeArray,\n objectOfMaybeArray,\n type MaybeArray,\n} from './arrays/MaybeArray';\nexport { arrayFromAsync } from './arrays/arrayFromAsync';\n\n// object\nexport { get } from './objects/get';\nexport { set } from './objects/set';\nexport { parseObjectPath } from './objects/parseObjectPath';\nexport { computeIfAbsent } from './objects/computeIfAbsent';\nexport { merge, type MergeOptions } from './objects/merge';\n\n// async\nexport { createLazyPromise, type LazyPromise } from './asyncs/createLazyPromise';\nexport { setAsyncInterval, clearAsyncInterval } from './asyncs/AsyncInterval';\nexport { type MaybePromise } from './asyncs/MaybePromise';\n// async - iterator\nexport { createAsyncIterator } from './asyncs/createAsyncIterator';\nexport { firstOfAsyncIterator } from './asyncs/firstOfAsyncIterator';\nexport { nextOfAsyncIterator } from './asyncs/nextOfAsyncIterator';\nexport { isIterator } from './asyncs/isIterator';\n\nexport { Promises } from './asyncs/Promises';\nexport const sleep = Promises.sleep;\nexport const isPromise = Promises.isPromise;\nexport { timeout, TimeoutError } from './asyncs/timeout';\n\n// langs\nexport { shallowEqual } from './langs/shallowEqual';\nexport { deepEqual } from './langs/deepEqual';\nexport { deepFreeze } from './langs/deepFreeze';\nexport { classOf } from './langs/classOf';\nexport { shallowClone } from './langs/shallowClone';\nexport { isClass } from './langs/isClass';\nexport { isDefined } from './langs/isDefined';\nexport { isEmptyObject } from './langs/isEmptyObject';\nexport { isPlainObject } from './langs/isPlainObject';\nexport { parseBoolean } from './langs/parseBoolean';\nexport { maybeFunction, type MaybeFunction } from './langs/MaybeFunction';\nexport { memoize } from './langs/memoize';\nexport { mixin } from './langs/mixin';\nexport type { MixinFunction, MixinInstance, MixinReturnValue } from './langs/mixin';\n\nexport { AsyncCloser } from './runtime/AsyncCloser';\nexport { Closer } from './runtime/Closer';\n\nexport { isUUID } from './validations/isUUID';\nexport { parseTimestamp } from './validations/parseTimestamp';\n\n// modules\nexport { parseModuleId, type ParsedModuleId } from './modules/parseModuleId';\nexport { isModule, type Module } from './modules/isModule';\n\n// logging\nexport { type Logger, type LogLevel } from './logging/Logger';\nexport { createLogger } from './logging/createLogger';\nexport { createNoopLogger } from './logging/createNoopLogger';\nexport { createChildLogger } from './logging/createChildLogger';\n\n// strings\nexport { pascalCase, camelCase } from './strings/camelCase';\nexport { renderTemplate } from './strings/renderTemplate';\nexport { formatBytes } from './strings/formatBytes';\n\n// i18n\nexport { createTranslate } from './i18n/createTranslate';\n\n// io\nexport { isBuffer } from './io/isBuffer';\nexport { isTransferable } from './io/isTransferable';\nexport { ArrayBuffers } from './io/ArrayBuffers';\nexport { ByteBuffer } from './io/ByteBuffer';\nexport { fromHexDump, toHexDump } from './io/dump';\nexport { Buffer } from './io/Buffer';\nexport { parseDataUri, type ParsedDataUri } from './io/parseDataUri';\nexport type { AbstractEncoding } from './io/AbstractEncoding';\n\n// browser\nexport { copy } from './browsers/copy';\nexport { download } from './browsers/download';\nexport { loadScripts, loadStyles } from './browsers/loaders';\nexport { getFileFromDataTransfer } from './browsers/getFileFromDataTransfer';\n\n// polyfills\nexport { getGlobalThis } from './runtime/getGlobalThis';\nexport { structuredClone } from './runtime/structuredClone';\n\n// crypto\nexport { randomUUID } from './crypto/randomUUID';\nexport { getRandomValues } from './crypto/getRandomValues';\nexport { sha1, sha256, sha384, sha512, hmac, type DigestOptions } from './crypto/hashing';\nexport { md5 } from './crypto/md5';\nexport { hex } from './crypto/base';\nexport { isULID, createULID, ulid, parseULID } from './crypto/ulid';\nexport { PEM } from './crypto/pem/pem';\n\n// math\nexport { createRandom } from './maths/random';\nexport { clamp } from './maths/clamp';\n\n// network\nexport {\n type FetchLike,\n createFetchWith,\n createFetchWithLogging,\n dumpResponse,\n dumpRequest,\n createFetchWithRetry,\n type FetchWithRetryOptions,\n} from './fetch';\n\n// bundled\nexport { default as ms } from './libs/ms';\n\n// error\nexport { Errors, DetailError, type ErrorDetail, type ErrorDetailInit } from './errors/Errors';\n// http\nexport { getHttpStatusText, isRetryableHttpStatus } from './fetch/HttpStatus';\n\nexport type * from './types';\n"],"names":["Promises","firstOfMaybeArray","lastOfMaybeArray","arrayOfMaybeArray","objectOfMaybeArray","arrayFromAsync","get","set","parseObjectPath","computeIfAbsent","merge","createLazyPromise","setAsyncInterval","clearAsyncInterval","createAsyncIterator","firstOfAsyncIterator","nextOfAsyncIterator","isIterator","sleep","isPromise","timeout","TimeoutError","shallowEqual","deepEqual","deepFreeze","classOf","shallowClone","isClass","isDefined","isEmptyObject","isPlainObject","parseBoolean","maybeFunction","memoize","mixin","AsyncCloser","Closer","isUUID","parseTimestamp","parseModuleId","isModule","createLogger","createNoopLogger","createChildLogger","pascalCase","camelCase","renderTemplate","formatBytes","createTranslate","isBuffer","isTransferable","ArrayBuffers","ByteBuffer","fromHexDump","toHexDump","Buffer","parseDataUri","copy","download","loadScripts","loadStyles","getFileFromDataTransfer","getGlobalThis","structuredClone","randomUUID","getRandomValues","sha1","sha256","sha384","sha512","hmac","md5","hex","isULID","createULID","ulid","parseULID","PEM","createRandom","clamp","createFetchWith","createFetchWithLogging","dumpResponse","dumpRequest","createFetchWithRetry","default","ms","Errors","DetailError","getHttpStatusText","isRetryableHttpStatus"],"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Promises } from './asyncs/Promises';\n\n// arrays\nexport {\n firstOfMaybeArray,\n lastOfMaybeArray,\n arrayOfMaybeArray,\n objectOfMaybeArray,\n type MaybeArray,\n} from './arrays/MaybeArray';\nexport { arrayFromAsync } from './arrays/arrayFromAsync';\n\n// object\nexport { get } from './objects/get';\nexport { set } from './objects/set';\nexport { parseObjectPath } from './objects/parseObjectPath';\nexport { computeIfAbsent } from './objects/computeIfAbsent';\nexport { merge, type MergeOptions } from './objects/merge';\n\n// async\nexport { createLazyPromise, type LazyPromise } from './asyncs/createLazyPromise';\nexport { setAsyncInterval, clearAsyncInterval } from './asyncs/AsyncInterval';\nexport { type MaybePromise } from './asyncs/MaybePromise';\n// async - iterator\nexport { createAsyncIterator } from './asyncs/createAsyncIterator';\nexport { firstOfAsyncIterator } from './asyncs/firstOfAsyncIterator';\nexport { nextOfAsyncIterator } from './asyncs/nextOfAsyncIterator';\nexport { isIterator } from './asyncs/isIterator';\n\nexport { Promises } from './asyncs/Promises';\nexport const sleep = Promises.sleep;\nexport const isPromise = Promises.isPromise;\nexport { timeout, TimeoutError } from './asyncs/timeout';\n\n// langs\nexport { shallowEqual } from './langs/shallowEqual';\nexport { deepEqual } from './langs/deepEqual';\nexport { deepFreeze } from './langs/deepFreeze';\nexport { classOf } from './langs/classOf';\nexport { shallowClone } from './langs/shallowClone';\nexport { isClass } from './langs/isClass';\nexport { isDefined } from './langs/isDefined';\nexport { isEmptyObject } from './langs/isEmptyObject';\nexport { isPlainObject } from './langs/isPlainObject';\nexport { parseBoolean } from './langs/parseBoolean';\nexport { maybeFunction, type MaybeFunction } from './langs/MaybeFunction';\nexport { memoize } from './langs/memoize';\nexport { mixin } from './langs/mixin';\nexport type { MixinFunction, MixinInstance, MixinReturnValue } from './langs/mixin';\nexport { getObjectId } from './langs/getObjectId';\nexport { getGlobalStates, setGlobalStates } from './langs/getGlobalStates';\n\nexport { AsyncCloser } from './runtime/AsyncCloser';\nexport { Closer } from './runtime/Closer';\n\nexport { isUUID } from './validations/isUUID';\nexport { parseTimestamp } from './validations/parseTimestamp';\n\n// modules\nexport { parseModuleId, type ParsedModuleId } from './modules/parseModuleId';\nexport { isModule, type Module } from './modules/isModule';\n\n// logging\nexport { type Logger, type LogLevel } from './logging/Logger';\nexport { createLogger } from './logging/createLogger';\nexport { createNoopLogger } from './logging/createNoopLogger';\nexport { createChildLogger } from './logging/createChildLogger';\n\n// strings\nexport { pascalCase, camelCase } from './strings/camelCase';\nexport { renderTemplate } from './strings/renderTemplate';\nexport { formatBytes } from './strings/formatBytes';\n\n// i18n\nexport { createTranslate } from './i18n/createTranslate';\n\n// io\nexport { isBuffer } from './io/isBuffer';\nexport { isTransferable } from './io/isTransferable';\nexport { ArrayBuffers } from './io/ArrayBuffers';\nexport { ByteBuffer } from './io/ByteBuffer';\nexport { fromHexDump, toHexDump } from './io/dump';\nexport { Buffer } from './io/Buffer';\nexport { parseDataUri, type ParsedDataUri } from './io/parseDataUri';\nexport type { AbstractEncoding } from './io/AbstractEncoding';\n\n// browser\nexport { copy } from './browsers/copy';\nexport { download } from './browsers/download';\nexport { loadScripts, loadStyles } from './browsers/loaders';\nexport { getFileFromDataTransfer } from './browsers/getFileFromDataTransfer';\n\n// polyfills\nexport { getGlobalThis } from './runtime/getGlobalThis';\nexport { structuredClone } from './runtime/structuredClone';\n\n// crypto\nexport { randomUUID } from './crypto/randomUUID';\nexport { getRandomValues } from './crypto/getRandomValues';\nexport { sha1, sha256, sha384, sha512, hmac, type DigestOptions } from './crypto/hashing';\nexport { md5 } from './crypto/md5';\nexport { hex } from './crypto/base';\nexport { isULID, createULID, ulid, parseULID } from './crypto/ulid';\nexport { PEM } from './crypto/pem/pem';\n\n// math\nexport { createRandom } from './maths/random';\nexport { clamp } from './maths/clamp';\n\n// network\nexport {\n type FetchLike,\n createFetchWith,\n createFetchWithLogging,\n dumpResponse,\n dumpRequest,\n createFetchWithRetry,\n type FetchWithRetryOptions,\n} from './fetch';\n\n// bundled\nexport { default as ms } from './libs/ms';\n\n// error\nexport { Errors, DetailError, type ErrorDetail, type ErrorDetailInit } from './errors/Errors';\n// http\nexport { getHttpStatusText, isRetryableHttpStatus } from './fetch/HttpStatus';\n\nexport type * from './types';\n"],"names":["Promises","firstOfMaybeArray","lastOfMaybeArray","arrayOfMaybeArray","objectOfMaybeArray","arrayFromAsync","get","set","parseObjectPath","computeIfAbsent","merge","createLazyPromise","setAsyncInterval","clearAsyncInterval","createAsyncIterator","firstOfAsyncIterator","nextOfAsyncIterator","isIterator","sleep","isPromise","timeout","TimeoutError","shallowEqual","deepEqual","deepFreeze","classOf","shallowClone","isClass","isDefined","isEmptyObject","isPlainObject","parseBoolean","maybeFunction","memoize","mixin","getObjectId","getGlobalStates","setGlobalStates","AsyncCloser","Closer","isUUID","parseTimestamp","parseModuleId","isModule","createLogger","createNoopLogger","createChildLogger","pascalCase","camelCase","renderTemplate","formatBytes","createTranslate","isBuffer","isTransferable","ArrayBuffers","ByteBuffer","fromHexDump","toHexDump","Buffer","parseDataUri","copy","download","loadScripts","loadStyles","getFileFromDataTransfer","getGlobalThis","structuredClone","randomUUID","getRandomValues","sha1","sha256","sha384","sha512","hmac","md5","hex","isULID","createULID","ulid","parseULID","PEM","createRandom","clamp","createFetchWith","createFetchWithLogging","dumpResponse","dumpRequest","createFetchWithRetry","default","ms","Errors","DetailError","getHttpStatusText","isRetryableHttpStatus"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,oBAAoB;AAE7C,SAAS;AACT,SACEC,iBAAiB,EACjBC,gBAAgB,EAChBC,iBAAiB,EACjBC,kBAAkB,QAEb,sBAAsB;AAC7B,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,SAAS;AACT,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,KAAK,QAA2B,kBAAkB;AAE3D,QAAQ;AACR,SAASC,iBAAiB,QAA0B,6BAA6B;AACjF,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,yBAAyB;AAE9E,mBAAmB;AACnB,SAASC,mBAAmB,QAAQ,+BAA+B;AACnE,SAASC,oBAAoB,QAAQ,gCAAgC;AACrE,SAASC,mBAAmB,QAAQ,+BAA+B;AACnE,SAASC,UAAU,QAAQ,sBAAsB;AAEjD,SAASjB,QAAQ,QAAQ,oBAAoB;AAC7C,OAAO,MAAMkB,QAAQlB,SAASkB,KAAK,CAAC;AACpC,OAAO,MAAMC,YAAYnB,SAASmB,SAAS,CAAC;AAC5C,SAASC,OAAO,EAAEC,YAAY,QAAQ,mBAAmB;AAEzD,QAAQ;AACR,SAASC,YAAY,QAAQ,uBAAuB;AACpD,SAASC,SAAS,QAAQ,oBAAoB;AAC9C,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SAASC,OAAO,QAAQ,kBAAkB;AAC1C,SAASC,YAAY,QAAQ,uBAAuB;AACpD,SAASC,OAAO,QAAQ,kBAAkB;AAC1C,SAASC,SAAS,QAAQ,oBAAoB;AAC9C,SAASC,aAAa,QAAQ,wBAAwB;AACtD,SAASC,aAAa,QAAQ,wBAAwB;AACtD,SAASC,YAAY,QAAQ,uBAAuB;AACpD,SAASC,aAAa,QAA4B,wBAAwB;AAC1E,SAASC,OAAO,QAAQ,kBAAkB;AAC1C,SAASC,KAAK,QAAQ,gBAAgB;AAEtC,SAASC,WAAW,QAAQ,sBAAsB;AAClD,SAASC,eAAe,EAAEC,eAAe,QAAQ,0BAA0B;AAE3E,SAASC,WAAW,QAAQ,wBAAwB;AACpD,SAASC,MAAM,QAAQ,mBAAmB;AAE1C,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,SAASC,cAAc,QAAQ,+BAA+B;AAE9D,UAAU;AACV,SAASC,aAAa,QAA6B,0BAA0B;AAC7E,SAASC,QAAQ,QAAqB,qBAAqB;AAI3D,SAASC,YAAY,QAAQ,yBAAyB;AACtD,SAASC,gBAAgB,QAAQ,6BAA6B;AAC9D,SAASC,iBAAiB,QAAQ,8BAA8B;AAEhE,UAAU;AACV,SAASC,UAAU,EAAEC,SAAS,QAAQ,sBAAsB;AAC5D,SAASC,cAAc,QAAQ,2BAA2B;AAC1D,SAASC,WAAW,QAAQ,wBAAwB;AAEpD,OAAO;AACP,SAASC,eAAe,QAAQ,yBAAyB;AAEzD,KAAK;AACL,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,cAAc,QAAQ,sBAAsB;AACrD,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,WAAW,EAAEC,SAAS,QAAQ,YAAY;AACnD,SAASC,MAAM,QAAQ,cAAc;AACrC,SAASC,YAAY,QAA4B,oBAAoB;AAGrE,UAAU;AACV,SAASC,IAAI,QAAQ,kBAAkB;AACvC,SAASC,QAAQ,QAAQ,sBAAsB;AAC/C,SAASC,WAAW,EAAEC,UAAU,QAAQ,qBAAqB;AAC7D,SAASC,uBAAuB,QAAQ,qCAAqC;AAE7E,YAAY;AACZ,SAASC,aAAa,QAAQ,0BAA0B;AACxD,SAASC,eAAe,QAAQ,4BAA4B;AAE5D,SAAS;AACT,SAASC,UAAU,QAAQ,sBAAsB;AACjD,SAASC,eAAe,QAAQ,2BAA2B;AAC3D,SAASC,IAAI,EAAEC,MAAM,EAAEC,MAAM,EAAEC,MAAM,EAAEC,IAAI,QAA4B,mBAAmB;AAC1F,SAASC,GAAG,QAAQ,eAAe;AACnC,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,MAAM,EAAEC,UAAU,EAAEC,IAAI,EAAEC,SAAS,QAAQ,gBAAgB;AACpE,SAASC,GAAG,QAAQ,mBAAmB;AAEvC,OAAO;AACP,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,KAAK,QAAQ,gBAAgB;AAEtC,UAAU;AACV,SAEEC,eAAe,EACfC,sBAAsB,EACtBC,YAAY,EACZC,WAAW,EACXC,oBAAoB,QAEf,UAAU;AAEjB,UAAU;AACV,SAASC,WAAWC,EAAE,QAAQ,YAAY;AAE1C,QAAQ;AACR,SAASC,MAAM,EAAEC,WAAW,QAAgD,kBAAkB;AAC9F,OAAO;AACP,SAASC,iBAAiB,EAAEC,qBAAqB,QAAQ,qBAAqB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/io/AbstractEncoding.ts"],"sourcesContent":["/**\n * AbstractEncoding contract\n *\n * @see https://github.com/mafintosh/abstract-encoding\n */\nexport interface AbstractEncoding<T> {\n /**\n * encode a value to a buffer\n */\n encode(data: T, buffer?: ArrayBuffer, offset?: number): BufferSource;\n\n /**\n * decode data from buffer\n */\n decode(buffer: BufferSource, start?: number, end?: number): T;\n\n /**\n * byteLength of data\n */\n byteLength?: (data: T) => number;\n}\n"],"names":[],"
|
|
1
|
+
{"version":3,"sources":["../../src/io/AbstractEncoding.ts"],"sourcesContent":["/**\n * AbstractEncoding contract\n *\n * @see https://github.com/mafintosh/abstract-encoding\n */\nexport interface AbstractEncoding<T> {\n /**\n * encode a value to a buffer\n */\n encode(data: T, buffer?: ArrayBuffer, offset?: number): BufferSource;\n\n /**\n * decode data from buffer\n */\n decode(buffer: BufferSource, start?: number, end?: number): T;\n\n /**\n * byteLength of data\n */\n byteLength?: (data: T) => number;\n}\n"],"names":[],"mappings":"AAAA;;;;CAIC,GACD,WAeC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/io/ArrayBuffer.test-d.ts"],"sourcesContent":["import { expectTypeOf, test } from 'vitest';\nimport { ArrayBuffers } from './ArrayBuffers';\n\ntest('my types work properly', () => {\n expectTypeOf(ArrayBuffers.asView(Buffer, new Uint8Array())).toMatchTypeOf<Buffer>();\n});\n"],"names":["expectTypeOf","test","ArrayBuffers","asView","Buffer","Uint8Array","toMatchTypeOf"],"
|
|
1
|
+
{"version":3,"sources":["../../src/io/ArrayBuffer.test-d.ts"],"sourcesContent":["import { expectTypeOf, test } from 'vitest';\nimport { ArrayBuffers } from './ArrayBuffers';\n\ntest('my types work properly', () => {\n expectTypeOf(ArrayBuffers.asView(Buffer, new Uint8Array())).toMatchTypeOf<Buffer>();\n});\n"],"names":["expectTypeOf","test","ArrayBuffers","asView","Buffer","Uint8Array","toMatchTypeOf"],"mappings":"AAAA,SAASA,YAAY,EAAEC,IAAI,QAAQ,SAAS;AAC5C,SAASC,YAAY,QAAQ,iBAAiB;AAE9CD,KAAK,0BAA0B;IAC7BD,aAAaE,aAAaC,MAAM,CAACC,QAAQ,IAAIC,eAAeC,aAAa;AAC3E"}
|
package/lib/io/ArrayBuffers.js
CHANGED
|
@@ -1,150 +1,106 @@
|
|
|
1
1
|
import { classOf } from '../langs/classOf.js';
|
|
2
2
|
import { getGlobalThis } from '../runtime/getGlobalThis.js';
|
|
3
|
-
import {
|
|
3
|
+
import { decodeBase64ToUint8Array, encodeArrayBufferToBase64 } from './base64.js';
|
|
4
4
|
import { isBuffer } from './isBuffer.js';
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
export var ArrayBuffers;
|
|
6
|
+
(function(ArrayBuffers) {
|
|
7
|
+
let nativeBufferAllowed = true;
|
|
8
|
+
let isBufferAvailable;
|
|
9
|
+
function isNativeBufferAvailable() {
|
|
9
10
|
// eslint-disable-next-line no-return-assign
|
|
10
|
-
return
|
|
11
|
+
return isBufferAvailable ??= !getGlobalThis().Buffer?.isPollyfill?.();
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* isNativeBufferAvailable check if the native {@link Buffer} is available
|
|
15
|
+
*/ ArrayBuffers.isNativeBufferAvailable = isNativeBufferAvailable;
|
|
16
|
+
function isNativeBufferAllowed() {
|
|
17
|
+
return Boolean(nativeBufferAllowed && isBufferAvailable);
|
|
14
18
|
}
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
ArrayBuffers.isNativeBufferAllowed = isNativeBufferAllowed;
|
|
20
|
+
function setNativeBufferAllowed(v) {
|
|
21
|
+
nativeBufferAllowed = v;
|
|
17
22
|
}
|
|
18
|
-
|
|
23
|
+
ArrayBuffers.setNativeBufferAllowed = setNativeBufferAllowed;
|
|
24
|
+
function isArrayBuffer(v) {
|
|
19
25
|
return v instanceof ArrayBuffer;
|
|
20
|
-
};
|
|
21
|
-
static toArrayBuffer(v) {
|
|
22
|
-
return v instanceof ArrayBuffer ? v : v.buffer;
|
|
23
26
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if ('toBase64' in Uint8Array.prototype) {
|
|
29
|
-
return this.toUint8Array(v).toBase64();
|
|
30
|
-
}
|
|
31
|
-
if (ArrayBuffers.isNativeBufferAllowed()) {
|
|
32
|
-
return Buffer.from(ArrayBuffers.asView(Uint8Array, v)).toString('base64');
|
|
33
|
-
}
|
|
34
|
-
return encodeArrayBufferToBase64(this.toArrayBuffer(v));
|
|
35
|
-
};
|
|
36
|
-
static toHex = (v)=>{
|
|
37
|
-
if ('toHex' in Uint8Array.prototype) {
|
|
38
|
-
return this.toUint8Array(v).toHex();
|
|
39
|
-
}
|
|
40
|
-
if (ArrayBuffers.isNativeBufferAllowed()) {
|
|
41
|
-
return Buffer.from(ArrayBuffers.asView(Uint8Array, v)).toString('hex');
|
|
42
|
-
}
|
|
43
|
-
return ArrayBuffers.toString(v, 'hex');
|
|
44
|
-
};
|
|
45
|
-
static fromBase64 = (v)=>{
|
|
46
|
-
if ('fromBase64' in Uint8Array) {
|
|
47
|
-
return Uint8Array.fromBase64(v);
|
|
48
|
-
}
|
|
49
|
-
if (ArrayBuffers.isNativeBufferAllowed()) {
|
|
50
|
-
return Buffer.from(v, 'base64');
|
|
51
|
-
}
|
|
52
|
-
return this.toUint8Array(decodeBase64ToArrayBuffer(v));
|
|
53
|
-
};
|
|
54
|
-
static fromHex = (v)=>{
|
|
55
|
-
if ('fromHex' in Uint8Array) {
|
|
56
|
-
return Uint8Array.fromHex(v);
|
|
57
|
-
}
|
|
58
|
-
return this.toUint8Array(ArrayBuffers.from(v, 'hex'));
|
|
59
|
-
};
|
|
60
|
-
static resize = (v, newByteLength, maxByteLength)=>{
|
|
61
|
-
if (newByteLength === undefined || newByteLength === null) {
|
|
62
|
-
return v;
|
|
63
|
-
}
|
|
64
|
-
// Chrome 111, Nodejs 20
|
|
65
|
-
if ('resize' in v && typeof v.resize === 'function') {
|
|
66
|
-
if ('resizable' in v && v.resizable) {
|
|
67
|
-
if ('maxByteLength' in v && typeof v.maxByteLength === 'number' && v.maxByteLength >= newByteLength) {
|
|
68
|
-
v.resize(newByteLength);
|
|
69
|
-
return v;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const old = v;
|
|
74
|
-
const newBuf = new ArrayBuffer(newByteLength, {
|
|
75
|
-
maxByteLength: maxByteLength
|
|
76
|
-
});
|
|
77
|
-
const oldView = new Uint8Array(old);
|
|
78
|
-
const newView = new Uint8Array(newBuf);
|
|
79
|
-
newView.set(oldView);
|
|
80
|
-
return newBuf;
|
|
81
|
-
};
|
|
82
|
-
static slice = (o, start, end)=>{
|
|
27
|
+
/**
|
|
28
|
+
* isArrayBuffer check if the given value is an {@link ArrayBuffer}
|
|
29
|
+
*/ ArrayBuffers.isArrayBuffer = isArrayBuffer;
|
|
30
|
+
function slice(o, start, end) {
|
|
83
31
|
// NodeJS Buffer slice is not the same as UInt8Array slice
|
|
84
32
|
// https://nodejs.org/api/buffer.html#bufslicestart-end
|
|
85
33
|
if (isBuffer(o)) {
|
|
86
34
|
return Uint8Array.prototype.slice.call(o, start, end);
|
|
87
35
|
}
|
|
88
36
|
return o.slice(start, end);
|
|
89
|
-
}
|
|
90
|
-
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* slice the given view with the given offset and length, will handle the {@link Buffer} as well
|
|
40
|
+
*
|
|
41
|
+
* @see {@link https://nodejs.org/api/buffer.html#bufslicestart-end Buffer.slice}
|
|
42
|
+
*/ ArrayBuffers.slice = slice;
|
|
43
|
+
function asView(TypedArray, v, byteOffset, byteLength) {
|
|
91
44
|
if (v instanceof TypedArray && (byteOffset ?? 0) === 0 && byteLength === undefined) {
|
|
92
45
|
return v;
|
|
93
46
|
}
|
|
94
47
|
if (ArrayBuffer.isView(v) || isBuffer(v)) {
|
|
95
|
-
if (
|
|
48
|
+
if (isNativeBufferAllowed() && TypedArray === Buffer) {
|
|
96
49
|
// new Buffer() is deprecated
|
|
97
50
|
return Buffer.from(v.buffer, byteOffset, byteLength);
|
|
98
51
|
}
|
|
99
52
|
return new TypedArray(v.buffer, v.byteOffset + (byteOffset ?? 0), byteLength ?? v.byteLength);
|
|
100
53
|
}
|
|
101
54
|
return new TypedArray(v, byteOffset, byteLength);
|
|
102
|
-
}
|
|
103
|
-
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* asView convert the given value to given {@link TypedArray} view
|
|
58
|
+
*
|
|
59
|
+
* TypedArray can be {@link Buffer}, will avoid copy
|
|
60
|
+
*/ ArrayBuffers.asView = asView;
|
|
61
|
+
function toString(source, encoding = 'utf8') {
|
|
104
62
|
// 'ascii' 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex'
|
|
105
|
-
if (typeof
|
|
63
|
+
if (typeof source === 'string') {
|
|
106
64
|
switch(encoding){
|
|
107
65
|
case 'base64':
|
|
108
|
-
return btoa(
|
|
66
|
+
return btoa(source);
|
|
109
67
|
case 'utf-8':
|
|
110
68
|
case 'utf8':
|
|
111
|
-
return
|
|
69
|
+
return source;
|
|
112
70
|
default:
|
|
113
71
|
throw new Error(`[ArrayBuffers.toString] Unsupported encoding for string: ${encoding}`);
|
|
114
72
|
}
|
|
115
73
|
}
|
|
116
|
-
|
|
117
|
-
|
|
74
|
+
let u8 = asView(Uint8Array, source);
|
|
75
|
+
if (isNativeBufferAllowed()) {
|
|
76
|
+
return Buffer.from(u8).toString(encoding);
|
|
118
77
|
}
|
|
119
78
|
// reference
|
|
120
79
|
// https://github.com/feross/buffer/blob/master/index.js
|
|
121
80
|
switch(encoding){
|
|
122
81
|
case 'hex':
|
|
123
82
|
{
|
|
124
|
-
const view = ArrayBuffers.asView(Uint8Array, buf);
|
|
125
83
|
return [
|
|
126
|
-
...
|
|
84
|
+
...u8
|
|
127
85
|
].map((b)=>hexLookupTable[b]).join('');
|
|
128
86
|
}
|
|
129
87
|
case 'base64':
|
|
130
88
|
{
|
|
131
|
-
return encodeArrayBufferToBase64(
|
|
89
|
+
return encodeArrayBufferToBase64(u8);
|
|
132
90
|
}
|
|
133
91
|
case 'utf8':
|
|
134
92
|
// falls through
|
|
135
93
|
case 'utf-8':
|
|
136
|
-
return new TextDecoder().decode(
|
|
94
|
+
return new TextDecoder().decode(source);
|
|
137
95
|
case 'ascii':
|
|
138
96
|
{
|
|
139
|
-
|
|
140
|
-
return String.fromCharCode(...view.map((v)=>v & 0x7f));
|
|
97
|
+
return String.fromCharCode(...u8.map((v)=>v & 0x7f));
|
|
141
98
|
}
|
|
142
99
|
case 'latin1':
|
|
143
100
|
// falls through
|
|
144
101
|
case 'binary':
|
|
145
102
|
{
|
|
146
|
-
|
|
147
|
-
return String.fromCharCode(...view);
|
|
103
|
+
return String.fromCharCode(...u8);
|
|
148
104
|
}
|
|
149
105
|
case 'ucs2':
|
|
150
106
|
// falls through
|
|
@@ -153,109 +109,90 @@ export class ArrayBuffers {
|
|
|
153
109
|
// falls through
|
|
154
110
|
case 'utf16le':
|
|
155
111
|
{
|
|
156
|
-
const view = ArrayBuffers.asView(Uint8Array, buf);
|
|
157
112
|
let res = '';
|
|
158
113
|
// If length is odd, the last 8 bits must be ignored (same as node.js)
|
|
159
|
-
for(let i = 0; i <
|
|
160
|
-
res += String.fromCharCode(
|
|
114
|
+
for(let i = 0; i < u8.length - 1; i += 2){
|
|
115
|
+
res += String.fromCharCode(u8[i] + u8[i + 1] * 256);
|
|
161
116
|
}
|
|
162
117
|
return res;
|
|
163
118
|
}
|
|
164
119
|
default:
|
|
165
120
|
throw new Error(`[ArrayBuffers.toString] Unknown encoding: ${encoding}`);
|
|
166
121
|
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* toString convert the given {@link BufferSource} to string
|
|
125
|
+
*/ ArrayBuffers.toString = toString;
|
|
126
|
+
function normalizeEncoding(encoding) {
|
|
127
|
+
switch(encoding?.toLowerCase()){
|
|
128
|
+
case 'utf-8':
|
|
129
|
+
case 'utf8':
|
|
130
|
+
return 'utf8';
|
|
131
|
+
case 'utf-16le':
|
|
132
|
+
case 'ucs2':
|
|
133
|
+
case 'ucs-2':
|
|
134
|
+
return 'utf16le';
|
|
135
|
+
case 'hex':
|
|
136
|
+
case 'ascii':
|
|
137
|
+
case 'latin1':
|
|
138
|
+
case 'binary':
|
|
139
|
+
case 'base64':
|
|
140
|
+
case 'utf16le':
|
|
141
|
+
return encoding;
|
|
142
|
+
default:
|
|
143
|
+
return undefined;
|
|
179
144
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
145
|
+
}
|
|
146
|
+
function isEncoding(v) {
|
|
147
|
+
return normalizeEncoding(v) !== undefined;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Returns true if encoding is the name of a supported character encoding, or false otherwise.
|
|
151
|
+
*/ ArrayBuffers.isEncoding = isEncoding;
|
|
152
|
+
function toJSON(v, reviver) {
|
|
153
|
+
return JSON.parse(toString(v), reviver);
|
|
154
|
+
}
|
|
155
|
+
ArrayBuffers.toJSON = toJSON;
|
|
156
|
+
function from(src, encoding = 'utf8', view) {
|
|
157
|
+
if (!src) {
|
|
158
|
+
return new (view || ArrayBuffer)(0);
|
|
185
159
|
}
|
|
186
|
-
if (
|
|
187
|
-
return
|
|
160
|
+
if (isBufferSource(src)) {
|
|
161
|
+
return view ? asView(view, src) : src;
|
|
188
162
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
163
|
+
// Array<number> | Iterable<number>
|
|
164
|
+
if (typeof src !== 'string' && isIterable(src) || Array.isArray(src)) {
|
|
165
|
+
return (view || Uint8Array).from(src);
|
|
166
|
+
}
|
|
167
|
+
if (view) {
|
|
168
|
+
return asView(view, from(src, encoding));
|
|
169
|
+
}
|
|
170
|
+
if (typeof src === 'string') {
|
|
171
|
+
// is string
|
|
172
|
+
if (isNativeBufferAllowed()) {
|
|
173
|
+
return Buffer.from(src, encoding);
|
|
192
174
|
}
|
|
193
175
|
switch(encoding){
|
|
194
176
|
case 'utf-8':
|
|
195
177
|
// falls through
|
|
196
178
|
case 'utf8':
|
|
197
|
-
return new TextEncoder().encode(
|
|
179
|
+
return new TextEncoder().encode(src).buffer;
|
|
198
180
|
case 'base64':
|
|
199
181
|
// replaceAll need higher version of nodejs
|
|
200
|
-
return decodeBase64ToArrayBuffer(v.replace(/[^0-9a-zA-Z=+/_]/g, ''));
|
|
182
|
+
// return decodeBase64ToArrayBuffer(v.replace(/[^0-9a-zA-Z=+/_]/g, ''));
|
|
183
|
+
return fromBase64(src);
|
|
201
184
|
case 'hex':
|
|
202
|
-
return new Uint8Array(v.match(/.{1,2}/g)
|
|
185
|
+
// return new Uint8Array(v.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16))).buffer;
|
|
186
|
+
return fromHex(src);
|
|
203
187
|
default:
|
|
204
|
-
throw new Error(`
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (v instanceof ArrayBuffer) {
|
|
208
|
-
return v;
|
|
209
|
-
}
|
|
210
|
-
// lost length
|
|
211
|
-
if (ArrayBuffer.isView(v) || isBuffer(v)) {
|
|
212
|
-
if (v.byteOffset !== 0) {
|
|
213
|
-
// return v.buffer.slice(v.byteOffset, v.byteOffset + v.byteLength)
|
|
214
|
-
throw new Error('ArrayBuffers.from do not support view with offset');
|
|
188
|
+
throw new Error(`ArrayBuffers.from unsupported encoding: ${encoding}`);
|
|
215
189
|
}
|
|
216
|
-
return v.buffer;
|
|
217
|
-
}
|
|
218
|
-
if (Array.isArray(v)) {
|
|
219
|
-
return new Uint8Array(v);
|
|
220
190
|
}
|
|
221
|
-
const type = classOf(
|
|
191
|
+
const type = classOf(src);
|
|
222
192
|
throw new TypeError(`ArrayBuffers.from unsupported type ${type}`);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
case 'hex':
|
|
227
|
-
case 'utf8':
|
|
228
|
-
case 'utf-8':
|
|
229
|
-
case 'ascii':
|
|
230
|
-
case 'latin1':
|
|
231
|
-
case 'binary':
|
|
232
|
-
case 'base64':
|
|
233
|
-
case 'ucs2':
|
|
234
|
-
case 'ucs-2':
|
|
235
|
-
case 'utf16le':
|
|
236
|
-
// case 'utf-16le':
|
|
237
|
-
return true;
|
|
238
|
-
default:
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
// static truncate = (a: ArrayBufferLike, len?: number) => {
|
|
243
|
-
// if (len === 0) {
|
|
244
|
-
// return new ArrayBuffer(0);
|
|
245
|
-
// }
|
|
246
|
-
// if (!len) {
|
|
247
|
-
// return a;
|
|
248
|
-
// }
|
|
249
|
-
// if (a.byteLength > len) {
|
|
250
|
-
// return a.slice(0, len);
|
|
251
|
-
// } else if (a.byteLength < len) {
|
|
252
|
-
// let b = new Uint8Array(len);
|
|
253
|
-
// b.set(new Uint8Array(a));
|
|
254
|
-
// return b;
|
|
255
|
-
// }
|
|
256
|
-
// return a;
|
|
257
|
-
// };
|
|
258
|
-
static concat = (buffers, result, offset = 0)=>{
|
|
193
|
+
}
|
|
194
|
+
ArrayBuffers.from = from;
|
|
195
|
+
function concat(buffers, result, offset = 0) {
|
|
259
196
|
// https://stackoverflow.com/questions/10786128/appending-arraybuffers
|
|
260
197
|
const length = buffers.reduce((a, b)=>a + b.byteLength, 0);
|
|
261
198
|
const r = result ? new Uint8Array(result) : new Uint8Array(length);
|
|
@@ -273,8 +210,109 @@ export class ArrayBuffers {
|
|
|
273
210
|
offset += buffer.byteLength;
|
|
274
211
|
}
|
|
275
212
|
return r.buffer;
|
|
276
|
-
}
|
|
277
|
-
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* concat the given {@link BufferSource} to a new {@link ArrayBuffer}
|
|
216
|
+
*/ ArrayBuffers.concat = concat;
|
|
217
|
+
function fromBase64(v) {
|
|
218
|
+
if ('fromBase64' in Uint8Array) {
|
|
219
|
+
return Uint8Array.fromBase64(v);
|
|
220
|
+
}
|
|
221
|
+
if (isNativeBufferAllowed()) {
|
|
222
|
+
return Buffer.from(v, 'base64');
|
|
223
|
+
}
|
|
224
|
+
return decodeBase64ToUint8Array(v.replace(/[^0-9a-zA-Z=+/_]/g, ''));
|
|
225
|
+
}
|
|
226
|
+
ArrayBuffers.fromBase64 = fromBase64;
|
|
227
|
+
function fromHex(v) {
|
|
228
|
+
if ('fromHex' in Uint8Array) {
|
|
229
|
+
return Uint8Array.fromHex(v);
|
|
230
|
+
}
|
|
231
|
+
if (isNativeBufferAllowed()) {
|
|
232
|
+
return Buffer.from(v, 'hex');
|
|
233
|
+
}
|
|
234
|
+
return new Uint8Array(v.match(/.{1,2}/g).map((byte)=>parseInt(byte, 16)));
|
|
235
|
+
}
|
|
236
|
+
ArrayBuffers.fromHex = fromHex;
|
|
237
|
+
function toBase64(source) {
|
|
238
|
+
if (typeof source === 'string') {
|
|
239
|
+
source = new TextEncoder().encode(source);
|
|
240
|
+
}
|
|
241
|
+
if ('toBase64' in Uint8Array.prototype) {
|
|
242
|
+
return toUint8Array(source).toBase64();
|
|
243
|
+
}
|
|
244
|
+
if (isNativeBufferAllowed()) {
|
|
245
|
+
return Buffer.from(asView(Uint8Array, source)).toString('base64');
|
|
246
|
+
}
|
|
247
|
+
return encodeArrayBufferToBase64(toArrayBuffer(source));
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* toBase64 convert the given {@link BufferSource} to base64 string
|
|
251
|
+
* @param source if string, will be encoded as utf8
|
|
252
|
+
*/ ArrayBuffers.toBase64 = toBase64;
|
|
253
|
+
function toHex(v) {
|
|
254
|
+
if ('toHex' in Uint8Array.prototype) {
|
|
255
|
+
return toUint8Array(v).toHex();
|
|
256
|
+
}
|
|
257
|
+
if (isNativeBufferAllowed()) {
|
|
258
|
+
return Buffer.from(asView(Uint8Array, v)).toString('hex');
|
|
259
|
+
}
|
|
260
|
+
return toString(v, 'hex');
|
|
261
|
+
}
|
|
262
|
+
ArrayBuffers.toHex = toHex;
|
|
263
|
+
function resize(v, newByteLength, maxByteLength) {
|
|
264
|
+
if (newByteLength === undefined || newByteLength === null) {
|
|
265
|
+
return v;
|
|
266
|
+
}
|
|
267
|
+
// Chrome 111, Nodejs 20
|
|
268
|
+
if ('resize' in v && typeof v.resize === 'function') {
|
|
269
|
+
if ('resizable' in v && v.resizable) {
|
|
270
|
+
if ('maxByteLength' in v && typeof v.maxByteLength === 'number' && v.maxByteLength >= newByteLength) {
|
|
271
|
+
v.resize(newByteLength);
|
|
272
|
+
return v;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const old = v;
|
|
277
|
+
const newBuf = new ArrayBuffer(newByteLength, {
|
|
278
|
+
maxByteLength: maxByteLength
|
|
279
|
+
});
|
|
280
|
+
const oldView = new Uint8Array(old);
|
|
281
|
+
const newView = new Uint8Array(newBuf);
|
|
282
|
+
newView.set(oldView);
|
|
283
|
+
return newBuf;
|
|
284
|
+
}
|
|
285
|
+
ArrayBuffers.resize = resize;
|
|
286
|
+
function toArrayBuffer(v) {
|
|
287
|
+
if (v instanceof ArrayBuffer) {
|
|
288
|
+
return v;
|
|
289
|
+
}
|
|
290
|
+
if (ArrayBuffer.isView(v)) {
|
|
291
|
+
if (v.byteOffset > 0) {
|
|
292
|
+
throw new Error('ArrayBuffers.toArrayBuffer do not support view with offset');
|
|
293
|
+
}
|
|
294
|
+
return v.buffer;
|
|
295
|
+
}
|
|
296
|
+
throw new Error(`ArrayBuffers.toArrayBuffer unsupported type ${classOf(v)}`);
|
|
297
|
+
}
|
|
298
|
+
ArrayBuffers.toArrayBuffer = toArrayBuffer;
|
|
299
|
+
function toUint8Array(v) {
|
|
300
|
+
return asView(Uint8Array, v);
|
|
301
|
+
}
|
|
302
|
+
ArrayBuffers.toUint8Array = toUint8Array;
|
|
303
|
+
function alloc(size, fill, encoding) {
|
|
304
|
+
if (fill !== undefined) {
|
|
305
|
+
if (typeof fill === 'number') {
|
|
306
|
+
return new Uint8Array(size).fill(fill);
|
|
307
|
+
}
|
|
308
|
+
// as cast
|
|
309
|
+
// https://stackoverflow.com/questions/73994091
|
|
310
|
+
return asView(Uint8Array, from(fill, encoding)).slice(0, size);
|
|
311
|
+
}
|
|
312
|
+
return new ArrayBuffer(size);
|
|
313
|
+
}
|
|
314
|
+
ArrayBuffers.alloc = alloc;
|
|
315
|
+
})(ArrayBuffers || (ArrayBuffers = {}));
|
|
278
316
|
const hexLookupTable = function() {
|
|
279
317
|
const alphabet = '0123456789abcdef';
|
|
280
318
|
const table = new Array(256);
|
|
@@ -286,5 +324,11 @@ const hexLookupTable = function() {
|
|
|
286
324
|
}
|
|
287
325
|
return table;
|
|
288
326
|
}();
|
|
327
|
+
function isIterable(obj) {
|
|
328
|
+
return typeof obj?.[Symbol.iterator] === 'function';
|
|
329
|
+
}
|
|
330
|
+
function isBufferSource(v) {
|
|
331
|
+
return ArrayBuffer.isView(v) || v instanceof ArrayBuffer;
|
|
332
|
+
}
|
|
289
333
|
|
|
290
334
|
//# sourceMappingURL=ArrayBuffers.js.map
|