@wener/utils 1.1.50 → 1.1.53
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 +58 -8
- package/lib/arrays/arrayFromAsync.js +254 -6
- package/lib/asyncs/AsyncInterval.js +145 -9
- package/lib/asyncs/MaybePromise.js +0 -2
- package/lib/asyncs/Promises.js +95 -48
- package/lib/asyncs/createAsyncIterator.js +313 -23
- package/lib/asyncs/createLazyPromise.js +72 -31
- package/lib/asyncs/createLazyPromise.test.js +367 -0
- package/lib/asyncs/firstOfAsyncIterator.js +6 -6
- package/lib/asyncs/generatorOfStream.js +125 -14
- package/lib/asyncs/isIterator.js +1 -3
- package/lib/asyncs/isPromise.js +2 -4
- package/lib/asyncs/isThenable.js +0 -2
- package/lib/asyncs/nextOfAsyncIterator.js +15 -9
- package/lib/asyncs/promiseOfCallback.js +2 -4
- package/lib/asyncs/timeout.js +122 -13
- package/lib/browsers/copy.js +7 -8
- package/lib/browsers/download.js +215 -40
- package/lib/browsers/getFileFromDataTransfer.js +17 -14
- package/lib/browsers/loaders.js +251 -18
- package/lib/crypto/base.js +3 -3
- package/lib/crypto/getNodeCrypto.js +3 -5
- package/lib/crypto/hashing.js +236 -30
- package/lib/crypto/hashing.test.js +323 -0
- package/lib/crypto/md5.bench.js +11 -11
- package/lib/crypto/md5.d.js +0 -2
- package/lib/crypto/md5.js +0 -2
- package/lib/crypto/md5.test.js +7 -0
- package/lib/crypto/pem/pem.js +197 -35
- package/lib/crypto/pem/pem.test.js +104 -0
- package/lib/crypto/randomUUIDv7.js +0 -2
- package/lib/crypto/ulid.js +84 -48
- package/lib/crypto/ulid.test.js +115 -0
- package/lib/emitter/types.js +0 -2
- package/lib/errors/DetailError.js +297 -0
- package/lib/errors/Errors.js +2 -202
- package/lib/errors/Errors.mod.js +206 -0
- package/lib/errors/Errors.test.js +24 -0
- package/lib/fetch/HttpStatus.js +1 -3
- package/lib/fetch/createFetchWith.js +188 -19
- package/lib/fetch/createFetchWithLogging.js +17 -16
- package/lib/fetch/createFetchWithRetry.js +40 -24
- package/lib/fetch/dumpRequest.js +467 -41
- package/lib/fetch/dumpRequest.test.js +384 -0
- package/lib/fetch/dumpResponse.js +271 -16
- package/lib/fetch/dumpResponse.test.js +393 -0
- package/lib/fetch/http.types.js +0 -2
- package/lib/fetch/index.js +5 -7
- package/lib/fetch/isTextContentType.js +5 -0
- package/lib/fetch/resolveRequest.js +7 -0
- package/lib/fetch/types.js +0 -2
- package/lib/i18n/createTranslate.js +40 -20
- package/lib/i18n/createTranslate.test.js +177 -0
- package/lib/index.js +75 -75
- package/lib/io/AbstractEncoding.js +0 -2
- package/lib/io/ArrayBuffer.test-d.js +4 -6
- package/lib/io/ArrayBuffers.base64.test.js +60 -0
- package/lib/io/ArrayBuffers.js +2 -334
- package/lib/io/ArrayBuffers.mod.js +531 -0
- package/lib/io/ArrayBuffers.test.js +77 -0
- package/lib/io/Buffer.js +190 -20
- package/lib/io/Buffer.test.js +22 -0
- package/lib/io/ByteBuffer.js +752 -441
- package/lib/io/ByteBuffer.test.js +184 -0
- package/lib/io/base64.js +17 -19
- package/lib/io/dump.js +16 -16
- package/lib/io/isBuffer.js +2 -3
- package/lib/io/isBuffer.test.js +8 -0
- package/lib/io/isTransferable.js +16 -8
- package/lib/io/isTransferable.test.js +17 -0
- package/lib/io/parseDataUri.js +288 -40
- package/lib/io/parseDataUri.test.js +286 -0
- package/lib/io/types.js +1 -0
- package/lib/langs/AsyncCloser.js +276 -0
- package/lib/langs/Closer.js +100 -0
- package/lib/langs/MaybeFunction.js +38 -5
- package/lib/langs/classOf.js +0 -2
- package/lib/langs/deepEqual.js +82 -22
- package/lib/langs/deepEqual.test.js +11 -0
- package/lib/langs/deepFreeze.js +28 -9
- package/lib/langs/getGlobalStates.js +19 -7
- package/lib/langs/getObjectId.js +4 -6
- package/lib/langs/ifPresent.js +3 -0
- package/lib/langs/isClass.js +0 -2
- package/lib/langs/isDefined.js +0 -2
- package/lib/langs/isEmptyObject.js +1 -3
- package/lib/langs/isFunction.js +0 -2
- package/lib/langs/isNil.js +3 -0
- package/lib/langs/isPlainObject.js +2 -4
- package/lib/langs/langs.test.js +126 -0
- package/lib/langs/memoize.js +11 -7
- package/lib/langs/mixin.js +7 -4
- package/lib/langs/mixin.test.js +135 -0
- package/lib/langs/parseBoolean.js +11 -8
- package/lib/langs/shallowClone.js +5 -3
- package/lib/langs/shallowEqual.js +8 -6
- package/lib/libs/ms.js +28 -26
- package/lib/libs/ms.test.js +301 -0
- package/lib/logger/const.js +15 -0
- package/lib/logger/index.js +1 -0
- package/lib/logger/types.js +1 -0
- package/lib/maths/clamp.js +81 -12
- package/lib/maths/clamp.test.js +186 -0
- package/lib/maths/createRandom.test.js +36 -0
- package/lib/maths/random.js +162 -13
- package/lib/modules/isModule.js +0 -2
- package/lib/modules/parseModuleId.js +14 -15
- package/lib/modules/parseModuleId.test.js +153 -0
- package/lib/objects/computeIfAbsent.js +8 -3
- package/lib/objects/get.js +26 -8
- package/lib/objects/get.test-d.js +23 -25
- package/lib/objects/merge/index.js +1 -3
- package/lib/objects/merge/isMergeableObject.js +5 -3
- package/lib/objects/merge/merge.js +82 -26
- package/lib/objects/merge/merge.test.js +1397 -0
- package/lib/objects/parseObjectPath.js +47 -15
- package/lib/objects/parseObjectPath.test.js +138 -0
- package/lib/objects/set.js +25 -19
- package/lib/objects/set.test.js +522 -0
- package/lib/schema/typebox/index.js +2 -3
- package/lib/schema/typebox/typebox.js +6 -6
- package/lib/scripts/getGenerateContext.js +386 -76
- package/lib/server/crypto/md5.js +0 -2
- package/lib/server/fetch/createFetchWithProxy.js +2 -4
- package/lib/server/fetch/createFetchWithProxyByNodeFetch.js +258 -31
- package/lib/server/fetch/createFetchWithProxyByUndici.js +307 -49
- package/lib/server/getPackageDir.js +2 -3
- package/lib/server/index.js +5 -7
- package/lib/server/jsdom.js +1 -3
- package/lib/server/node-fetch.js +2 -4
- package/lib/server/polyfill/polyfillBrowser.js +163 -9
- package/lib/server/polyfill/polyfillBrowser.test.js +164 -0
- package/lib/server/polyfill/polyfillCrypto.js +157 -9
- package/lib/server/polyfill/polyfillFetch.js +13 -13
- package/lib/server/polyfill/polyfillJsDom.js +264 -58
- package/lib/server/polyfill/polyfillWebSocket.js +11 -11
- package/lib/server/ws.js +1 -3
- package/lib/strings/bytes.test.js +327 -0
- package/lib/strings/camelCase.js +23 -14
- package/lib/strings/formatBytes.js +29 -20
- package/lib/strings/parseBytes.js +54 -0
- package/lib/strings/renderTemplate.js +17 -12
- package/lib/strings/renderTemplate.test.js +104 -0
- package/lib/typedoc.js +2 -4
- package/lib/types.d.js +0 -2
- package/lib/validations/asserts.js +0 -2
- package/lib/validations/isUUID.js +0 -2
- package/lib/validations/isUUID.test.js +87 -0
- package/lib/validations/parseTimestamp.js +12 -7
- package/lib/validations/parseTimestamp.test.js +6 -0
- package/lib/{runtime → web}/getGlobalThis.js +3 -4
- package/lib/web/getRandomValues.js +44 -0
- package/lib/web/randomUUID.js +15 -0
- package/lib/web/requestIdleCallback.js +17 -0
- package/lib/{runtime → web}/structuredClone.js +35 -28
- package/lib/web/structuredClone.test.js +81 -0
- package/package.json +10 -18
- package/src/arrays/MaybeArray.ts +22 -22
- package/src/arrays/arrayFromAsync.ts +3 -3
- package/src/asyncs/AsyncInterval.ts +8 -8
- package/src/asyncs/Promises.ts +51 -51
- package/src/asyncs/createAsyncIterator.ts +34 -34
- package/src/asyncs/createLazyPromise.test.ts +73 -73
- package/src/asyncs/createLazyPromise.ts +68 -73
- package/src/asyncs/firstOfAsyncIterator.ts +5 -5
- package/src/asyncs/generatorOfStream.ts +12 -12
- package/src/asyncs/isIterator.ts +1 -1
- package/src/asyncs/isThenable.ts +2 -2
- package/src/asyncs/nextOfAsyncIterator.ts +20 -20
- package/src/asyncs/promiseOfCallback.ts +13 -13
- package/src/asyncs/timeout.ts +23 -23
- package/src/browsers/copy.ts +48 -48
- package/src/browsers/download.ts +38 -36
- package/src/browsers/getFileFromDataTransfer.ts +35 -35
- package/src/browsers/loaders.ts +49 -49
- package/src/crypto/base.ts +3 -3
- package/src/crypto/getNodeCrypto.ts +3 -3
- package/src/crypto/hashing.test.ts +34 -48
- package/src/crypto/hashing.ts +67 -67
- package/src/crypto/md5.bench.ts +20 -24
- package/src/crypto/md5.test.ts +3 -3
- package/src/crypto/pem/pem.test.ts +26 -42
- package/src/crypto/pem/pem.ts +65 -65
- package/src/crypto/ulid.test.ts +32 -32
- package/src/crypto/ulid.ts +117 -117
- package/src/emitter/types.ts +6 -6
- package/src/errors/DetailError.ts +151 -0
- package/src/errors/Errors.mod.ts +104 -0
- package/src/errors/Errors.test.ts +15 -15
- package/src/errors/Errors.ts +1 -247
- package/src/fetch/HttpStatus.ts +77 -77
- package/src/fetch/createFetchWith.ts +27 -27
- package/src/fetch/createFetchWithLogging.ts +13 -16
- package/src/fetch/createFetchWithRetry.ts +80 -80
- package/src/fetch/dumpRequest.test.ts +176 -0
- package/src/fetch/dumpRequest.ts +149 -52
- package/src/fetch/dumpResponse.test.ts +160 -0
- package/src/fetch/dumpResponse.ts +48 -20
- package/src/fetch/http.types.ts +35 -35
- package/src/fetch/isTextContentType.ts +12 -0
- package/src/fetch/resolveRequest.ts +1 -0
- package/src/fetch/types.ts +2 -2
- package/src/i18n/createTranslate.test.ts +90 -113
- package/src/i18n/createTranslate.ts +55 -55
- package/src/index.ts +26 -27
- package/src/io/AbstractEncoding.ts +12 -12
- package/src/io/ArrayBuffer.test-d.ts +1 -1
- package/src/io/ArrayBuffers.base64.test.ts +52 -52
- package/src/io/ArrayBuffers.mod.ts +670 -0
- package/src/io/ArrayBuffers.test.ts +14 -14
- package/src/io/ArrayBuffers.ts +1 -446
- package/src/io/Buffer.test.ts +17 -17
- package/src/io/Buffer.ts +17 -17
- package/src/io/ByteBuffer.test.ts +37 -37
- package/src/io/ByteBuffer.ts +574 -566
- package/src/io/base64.ts +46 -44
- package/src/io/dump.ts +22 -22
- package/src/io/isBuffer.test.ts +2 -2
- package/src/io/isBuffer.ts +1 -1
- package/src/io/isTransferable.test.ts +4 -4
- package/src/io/isTransferable.ts +30 -30
- package/src/io/parseDataUri.test.ts +22 -27
- package/src/io/parseDataUri.ts +57 -57
- package/src/io/types.ts +13 -0
- package/src/langs/AsyncCloser.ts +45 -0
- package/src/langs/Closer.ts +39 -0
- package/src/langs/MaybeFunction.ts +5 -5
- package/src/langs/classOf.ts +1 -1
- package/src/langs/deepEqual.test.ts +1 -12
- package/src/langs/deepEqual.ts +82 -82
- package/src/langs/deepFreeze.ts +11 -11
- package/src/langs/getGlobalStates.ts +21 -11
- package/src/langs/getObjectId.ts +10 -13
- package/src/langs/ifPresent.ts +3 -0
- package/src/langs/isClass.ts +1 -1
- package/src/langs/isDefined.ts +1 -1
- package/src/langs/isEmptyObject.ts +1 -1
- package/src/langs/isFunction.ts +1 -1
- package/src/langs/isNil.ts +3 -0
- package/src/langs/isPlainObject.ts +4 -4
- package/src/langs/langs.test.ts +18 -18
- package/src/langs/memoize.ts +21 -21
- package/src/langs/mixin.test.ts +22 -26
- package/src/langs/mixin.ts +6 -9
- package/src/langs/parseBoolean.ts +30 -26
- package/src/langs/shallowClone.ts +11 -11
- package/src/langs/shallowEqual.ts +19 -19
- package/src/libs/ms.test.ts +274 -274
- package/src/libs/ms.ts +137 -137
- package/src/logger/const.ts +18 -0
- package/src/logger/index.ts +2 -0
- package/src/logger/types.ts +10 -0
- package/src/maths/clamp.test.ts +18 -18
- package/src/maths/clamp.ts +17 -17
- package/src/maths/createRandom.test.ts +12 -0
- package/src/maths/random.ts +50 -14
- package/src/modules/isModule.ts +4 -4
- package/src/modules/parseModuleId.test.ts +61 -68
- package/src/modules/parseModuleId.ts +29 -43
- package/src/objects/computeIfAbsent.ts +10 -10
- package/src/objects/get.test-d.ts +33 -51
- package/src/objects/get.ts +31 -31
- package/src/objects/merge/isMergeableObject.ts +5 -5
- package/src/objects/merge/merge.test.ts +658 -880
- package/src/objects/merge/merge.ts +84 -84
- package/src/objects/parseObjectPath.test.ts +13 -13
- package/src/objects/parseObjectPath.ts +25 -25
- package/src/objects/set.test.ts +271 -366
- package/src/objects/set.ts +36 -36
- package/src/schema/typebox/typebox.ts +20 -26
- package/src/scripts/getGenerateContext.ts +82 -80
- package/src/server/crypto/md5.ts +1 -1
- package/src/server/fetch/createFetchWithProxyByNodeFetch.ts +30 -33
- package/src/server/fetch/createFetchWithProxyByUndici.ts +64 -70
- package/src/server/getPackageDir.ts +7 -7
- package/src/server/polyfill/polyfillBrowser.test.ts +10 -10
- package/src/server/polyfill/polyfillBrowser.ts +3 -3
- package/src/server/polyfill/polyfillCrypto.ts +7 -7
- package/src/server/polyfill/polyfillFetch.ts +11 -21
- package/src/server/polyfill/polyfillJsDom.ts +60 -72
- package/src/server/polyfill/polyfillWebSocket.ts +15 -15
- package/src/strings/bytes.test.ts +69 -0
- package/src/strings/camelCase.ts +58 -63
- package/src/strings/formatBytes.ts +50 -29
- package/src/strings/parseBytes.ts +66 -0
- package/src/strings/renderTemplate.test.ts +10 -17
- package/src/strings/renderTemplate.ts +19 -22
- package/src/types.d.ts +9 -9
- package/src/validations/asserts.ts +8 -8
- package/src/validations/isUUID.test.ts +9 -9
- package/src/validations/isUUID.ts +1 -1
- package/src/validations/parseTimestamp.test.ts +2 -2
- package/src/validations/parseTimestamp.ts +21 -21
- package/src/{runtime → web}/getGlobalThis.ts +6 -6
- package/src/web/getRandomValues.ts +41 -0
- package/src/web/randomUUID.ts +19 -0
- package/src/web/requestIdleCallback.ts +11 -0
- package/src/{runtime → web}/structuredClone.test.ts +8 -8
- package/src/web/structuredClone.ts +88 -0
- package/tsconfig.json +35 -34
- package/lib/arrays/MaybeArray.js.map +0 -1
- package/lib/arrays/arrayFromAsync.js.map +0 -1
- package/lib/asyncs/AsyncInterval.js.map +0 -1
- package/lib/asyncs/MaybePromise.js.map +0 -1
- package/lib/asyncs/Promises.js.map +0 -1
- package/lib/asyncs/createAsyncIterator.js.map +0 -1
- package/lib/asyncs/createLazyPromise.js.map +0 -1
- package/lib/asyncs/firstOfAsyncIterator.js.map +0 -1
- package/lib/asyncs/generatorOfStream.js.map +0 -1
- package/lib/asyncs/isIterator.js.map +0 -1
- package/lib/asyncs/isPromise.js.map +0 -1
- package/lib/asyncs/isThenable.js.map +0 -1
- package/lib/asyncs/nextOfAsyncIterator.js.map +0 -1
- package/lib/asyncs/promiseOfCallback.js.map +0 -1
- package/lib/asyncs/timeout.js.map +0 -1
- package/lib/browsers/copy.js.map +0 -1
- package/lib/browsers/download.js.map +0 -1
- package/lib/browsers/getFileFromDataTransfer.js.map +0 -1
- package/lib/browsers/loaders.js.map +0 -1
- package/lib/cn/division/DivisionCode.js +0 -209
- package/lib/cn/division/DivisionCode.js.map +0 -1
- package/lib/cn/division/binarySearch.js +0 -27
- package/lib/cn/division/binarySearch.js.map +0 -1
- package/lib/cn/formatChineseAmount.js +0 -77
- package/lib/cn/formatChineseAmount.js.map +0 -1
- package/lib/cn/id/Mod11.js +0 -43
- package/lib/cn/id/Mod11.js.map +0 -1
- package/lib/cn/id/ResidentIdNumber.js +0 -98
- package/lib/cn/id/ResidentIdNumber.js.map +0 -1
- package/lib/cn/id/types.js +0 -8
- package/lib/cn/id/types.js.map +0 -1
- package/lib/cn/index.js +0 -14
- package/lib/cn/index.js.map +0 -1
- package/lib/cn/parseChineseNumber.js +0 -94
- package/lib/cn/parseChineseNumber.js.map +0 -1
- package/lib/cn/pinyin/cartesianProduct.js +0 -22
- package/lib/cn/pinyin/cartesianProduct.js.map +0 -1
- package/lib/cn/pinyin/data.json +0 -413
- package/lib/cn/pinyin/loader.js +0 -15
- package/lib/cn/pinyin/loader.js.map +0 -1
- package/lib/cn/pinyin/preload.js +0 -4
- package/lib/cn/pinyin/preload.js.map +0 -1
- package/lib/cn/pinyin/toPinyinPure.js +0 -32
- package/lib/cn/pinyin/toPinyinPure.js.map +0 -1
- package/lib/cn/pinyin/transform.js +0 -14
- package/lib/cn/pinyin/transform.js.map +0 -1
- package/lib/cn/types.js +0 -3
- package/lib/cn/types.js.map +0 -1
- package/lib/cn/uscc/Mod31.js +0 -49
- package/lib/cn/uscc/Mod31.js.map +0 -1
- package/lib/cn/uscc/USCC.js +0 -94
- package/lib/cn/uscc/USCC.js.map +0 -1
- package/lib/cn/uscc/isUSCC.js +0 -8
- package/lib/cn/uscc/isUSCC.js.map +0 -1
- package/lib/crypto/base.js.map +0 -1
- package/lib/crypto/getNodeCrypto.js.map +0 -1
- package/lib/crypto/getRandomValues.js +0 -36
- package/lib/crypto/getRandomValues.js.map +0 -1
- package/lib/crypto/hashing.js.map +0 -1
- package/lib/crypto/md5.bench.js.map +0 -1
- package/lib/crypto/md5.d.js.map +0 -1
- package/lib/crypto/md5.js.map +0 -1
- package/lib/crypto/pem/pem.js.map +0 -1
- package/lib/crypto/randomUUID.js +0 -16
- package/lib/crypto/randomUUID.js.map +0 -1
- package/lib/crypto/randomUUIDv7.js.map +0 -1
- package/lib/crypto/ulid.js.map +0 -1
- package/lib/emitter/types.js.map +0 -1
- package/lib/errors/Errors.js.map +0 -1
- package/lib/fetch/HttpStatus.js.map +0 -1
- package/lib/fetch/createFetchWith.js.map +0 -1
- package/lib/fetch/createFetchWithLogging.js.map +0 -1
- package/lib/fetch/createFetchWithRetry.js.map +0 -1
- package/lib/fetch/dumpRequest.js.map +0 -1
- package/lib/fetch/dumpResponse.js.map +0 -1
- package/lib/fetch/http.types.js.map +0 -1
- package/lib/fetch/index.js.map +0 -1
- package/lib/fetch/types.js.map +0 -1
- package/lib/i18n/createTranslate.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/io/AbstractEncoding.js.map +0 -1
- package/lib/io/ArrayBuffer.test-d.js.map +0 -1
- package/lib/io/ArrayBuffers.js.map +0 -1
- package/lib/io/Buffer.js.map +0 -1
- package/lib/io/ByteBuffer.js.map +0 -1
- package/lib/io/base64.js.map +0 -1
- package/lib/io/dump.js.map +0 -1
- package/lib/io/isBuffer.js.map +0 -1
- package/lib/io/isTransferable.js.map +0 -1
- package/lib/io/parseDataUri.js.map +0 -1
- package/lib/langs/MaybeFunction.js.map +0 -1
- package/lib/langs/classOf.js.map +0 -1
- package/lib/langs/deepEqual.js.map +0 -1
- package/lib/langs/deepFreeze.js.map +0 -1
- package/lib/langs/getGlobalStates.js.map +0 -1
- package/lib/langs/getObjectId.js.map +0 -1
- package/lib/langs/isClass.js.map +0 -1
- package/lib/langs/isDefined.js.map +0 -1
- package/lib/langs/isEmptyObject.js.map +0 -1
- package/lib/langs/isFunction.js.map +0 -1
- package/lib/langs/isNullish.js +0 -5
- package/lib/langs/isNullish.js.map +0 -1
- package/lib/langs/isPlainObject.js.map +0 -1
- package/lib/langs/memoize.js.map +0 -1
- package/lib/langs/mixin.js.map +0 -1
- package/lib/langs/parseBoolean.js.map +0 -1
- package/lib/langs/shallowClone.js.map +0 -1
- package/lib/langs/shallowEqual.js.map +0 -1
- package/lib/libs/ms.js.map +0 -1
- package/lib/logging/Logger.js +0 -5
- package/lib/logging/Logger.js.map +0 -1
- package/lib/logging/createChildLogger.js +0 -16
- package/lib/logging/createChildLogger.js.map +0 -1
- package/lib/logging/createLogger.js +0 -63
- package/lib/logging/createLogger.js.map +0 -1
- package/lib/logging/createNoopLogger.js +0 -13
- package/lib/logging/createNoopLogger.js.map +0 -1
- package/lib/logging/slog.js +0 -143
- package/lib/logging/slog.js.map +0 -1
- package/lib/maths/clamp.js.map +0 -1
- package/lib/maths/random.js.map +0 -1
- package/lib/mitt/index.js +0 -77
- package/lib/mitt/index.js.map +0 -1
- package/lib/modules/isModule.js.map +0 -1
- package/lib/modules/parseModuleId.js.map +0 -1
- package/lib/objects/computeIfAbsent.js.map +0 -1
- package/lib/objects/get.js.map +0 -1
- package/lib/objects/get.test-d.js.map +0 -1
- package/lib/objects/merge/index.js.map +0 -1
- package/lib/objects/merge/isMergeableObject.js.map +0 -1
- package/lib/objects/merge/merge.js.map +0 -1
- package/lib/objects/parseObjectPath.js.map +0 -1
- package/lib/objects/set.js.map +0 -1
- package/lib/runtime/AsyncCloser.js +0 -40
- package/lib/runtime/AsyncCloser.js.map +0 -1
- package/lib/runtime/Closer.js +0 -34
- package/lib/runtime/Closer.js.map +0 -1
- package/lib/runtime/getGlobalThis.js.map +0 -1
- package/lib/runtime/structuredClone.js.map +0 -1
- package/lib/schema/typebox/index.js.map +0 -1
- package/lib/schema/typebox/typebox.js.map +0 -1
- package/lib/scripts/getGenerateContext.js.map +0 -1
- package/lib/server/crypto/md5.js.map +0 -1
- package/lib/server/fetch/createFetchWithProxy.js.map +0 -1
- package/lib/server/fetch/createFetchWithProxyByNodeFetch.js.map +0 -1
- package/lib/server/fetch/createFetchWithProxyByUndici.js.map +0 -1
- package/lib/server/getPackageDir.js.map +0 -1
- package/lib/server/index.js.map +0 -1
- package/lib/server/jsdom.js.map +0 -1
- package/lib/server/node-fetch.js.map +0 -1
- package/lib/server/polyfill/polyfillBrowser.js.map +0 -1
- package/lib/server/polyfill/polyfillCrypto.js.map +0 -1
- package/lib/server/polyfill/polyfillFetch.js.map +0 -1
- package/lib/server/polyfill/polyfillJsDom.js.map +0 -1
- package/lib/server/polyfill/polyfillWebSocket.js.map +0 -1
- package/lib/server/ws.js.map +0 -1
- package/lib/strings/camelCase.js.map +0 -1
- package/lib/strings/formatBytes.js.map +0 -1
- package/lib/strings/renderTemplate.js.map +0 -1
- package/lib/typedoc.js.map +0 -1
- package/lib/types.d.js.map +0 -1
- package/lib/validations/asserts.js.map +0 -1
- package/lib/validations/isUUID.js.map +0 -1
- package/lib/validations/parseTimestamp.js.map +0 -1
- package/src/cn/README.md +0 -3
- package/src/cn/division/DivisionCode.ts +0 -155
- package/src/cn/division/binarySearch.test.ts +0 -64
- package/src/cn/division/binarySearch.ts +0 -25
- package/src/cn/division/division.test.ts +0 -6
- package/src/cn/formatChineseAmount.ts +0 -61
- package/src/cn/id/Mod11.ts +0 -26
- package/src/cn/id/ResidentIdNumber.ts +0 -126
- package/src/cn/id/id.test.ts +0 -20
- package/src/cn/id/types.ts +0 -26
- package/src/cn/index.ts +0 -17
- package/src/cn/parseChineseNumber.test.ts +0 -159
- package/src/cn/parseChineseNumber.ts +0 -97
- package/src/cn/pinyin/cartesianProduct.test.ts +0 -64
- package/src/cn/pinyin/cartesianProduct.ts +0 -24
- package/src/cn/pinyin/data.json +0 -413
- package/src/cn/pinyin/loader.ts +0 -12
- package/src/cn/pinyin/preload.ts +0 -3
- package/src/cn/pinyin/toPinyin.test.ts +0 -12
- package/src/cn/pinyin/toPinyinPure.ts +0 -43
- package/src/cn/pinyin/transform.ts +0 -12
- package/src/cn/scripts/gen.test.ts +0 -131
- package/src/cn/types.ts +0 -11
- package/src/cn/uscc/Mod31.ts +0 -38
- package/src/cn/uscc/USCC.ts +0 -94
- package/src/cn/uscc/isUSCC.ts +0 -8
- package/src/cn/uscc/uscc.test.ts +0 -16
- package/src/crypto/getRandomValues.ts +0 -41
- package/src/crypto/randomUUID.ts +0 -19
- package/src/langs/isNullish.ts +0 -3
- package/src/logging/Logger.ts +0 -25
- package/src/logging/createChildLogger.ts +0 -16
- package/src/logging/createLogger.ts +0 -50
- package/src/logging/createNoopLogger.ts +0 -13
- package/src/logging/logger.test.ts +0 -36
- package/src/logging/slog.test.ts +0 -8
- package/src/logging/slog.ts +0 -221
- package/src/mitt/README.md +0 -1
- package/src/mitt/index.ts +0 -114
- package/src/runtime/AsyncCloser.ts +0 -45
- package/src/runtime/Closer.ts +0 -39
- package/src/runtime/structuredClone.ts +0 -88
|
@@ -2,157 +2,134 @@ import { assert, test } from 'vitest';
|
|
|
2
2
|
import { createTranslate } from './createTranslate';
|
|
3
3
|
|
|
4
4
|
test('exports', () => {
|
|
5
|
-
|
|
5
|
+
assert.equal(typeof createTranslate, 'function', 'exports a function');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
let out = createTranslate();
|
|
8
|
+
assert.equal(typeof out, 'object', 'returns an object');
|
|
9
|
+
assert.equal(typeof out.t, 'function', '~> has "t" function');
|
|
10
|
+
assert.equal(typeof out.dict, 'function', '~> has "dict" function');
|
|
11
|
+
assert.equal(typeof out.locale, 'function', '~> has "locale" function');
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
test('usage', () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
let ctx = createTranslate({
|
|
16
|
+
en: { hello: 'Hello, {{name}}!' },
|
|
17
|
+
es: { hello: 'Hola {{name}}!' },
|
|
18
|
+
pt: { foo: 'foo {{name}}~!' },
|
|
19
|
+
});
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
assert.deepEqual(ctx.dict('en'), { hello: 'Hello, {{name}}!' });
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
assert.equal(ctx.dict('foobar'), undefined);
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
let foo = ctx.t('hello');
|
|
26
|
+
assert.equal(foo, '', '~> "" w/o locale');
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
assert.equal(ctx.locale('en'), 'en', '>>> ctx.locale()');
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
assert.equal(ctx.locale(), 'en');
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
let bar = ctx.t('hello');
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
assert.notEqual(bar, '', '(en) found "hello" key');
|
|
35
|
+
assert.equal(bar, 'Hello, !', '~> interpolations empty if missing param');
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
let baz = ctx.t('hello', { name: 'world' });
|
|
38
|
+
assert.equal(baz, 'Hello, world!', '~> interpolations successful');
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
let bat = ctx.t('hello', { name: 'world' }, 'es');
|
|
41
|
+
assert.notEqual(bat, '', '(es) found "hello" key');
|
|
42
|
+
assert.equal(bat, 'Hola world!', '~> success');
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
assert.equal(ctx.t('hello', { name: 'world' }, 'pt'), '', '(pt) did NOT find "hello" key');
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
assert.equal(ctx.dict('pt', { hello: 'Oí {{name}}!' }), undefined, '>>> ctx.set()');
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
let quz = ctx.t('hello', { name: 'world' }, 'pt');
|
|
49
|
+
assert.notEqual(quz, '', '(pt) found "hello" key');
|
|
50
|
+
assert.equal(quz, 'Oí world!', '~> success');
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
let qut = ctx.t('foo', { name: 'bar' }, 'pt');
|
|
53
|
+
assert.notEqual(qut, '', '(pt) found "foo" key');
|
|
54
|
+
assert.equal(qut, 'foo bar~!', '~> success');
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
assert.equal(ctx.locale('es'), 'es', '>>> ctx.locale()');
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
assert.equal(ctx.locale(), 'es');
|
|
59
|
+
assert.equal(ctx.locale(''), 'es');
|
|
60
|
+
assert.equal(ctx.locale(false as any), 'es');
|
|
61
|
+
assert.equal(ctx.locale(null as any), 'es');
|
|
62
|
+
assert.equal(ctx.locale(0 as any), 'es');
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
let qux = ctx.t('hello', { name: 'default' });
|
|
65
|
+
assert.notEqual(qux, '', '(es) found "hello" key');
|
|
66
|
+
assert.equal(qux, 'Hola default!', '~> success');
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
assert.equal(ctx.t('hello', { name: 'world' }, 'de'), '', '(de) did NOT find "hello" key');
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
assert.equal(ctx.dict('de', { hello: 'Hallo {{name}}!' }), undefined, '>>> ctx.set(de)');
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
let qar = ctx.t('hello', { name: 'world' }, 'de');
|
|
73
|
+
assert.notEqual(qar, '', '(de) found "hello" key');
|
|
74
|
+
assert.equal(qar, 'Hallo world!', '~> success');
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
test('functional', () => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
let ctx = createTranslate({
|
|
79
|
+
en: {
|
|
80
|
+
hello(value: string) {
|
|
81
|
+
return `hello ${value || 'stranger'}~!`;
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
ctx.locale('en');
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
let foo = ctx.t('hello');
|
|
89
|
+
assert.equal(foo, 'hello stranger~!', '~> called function w/o param');
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
let bar = ctx.t('hello', 'world' as any);
|
|
92
|
+
assert.equal(bar, 'hello world~!', '~> called function w/ param (string)');
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
let baz = ctx.t('hello', [1, 2, 3]);
|
|
95
|
+
assert.equal(baz, 'hello 1,2,3~!', '~> called function w/ param (array)');
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
test('nested', () => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
assert.equal(ctx.t('fruits.apple'), 'apple', '(en) fruits.apple');
|
|
118
|
-
assert.equal(ctx.t('fruits.orange'), 'orange', '(en) fruits.orange');
|
|
119
|
-
assert.equal(ctx.t(['fruits', 'grape']), 'grape', '(en) ["fruits","grape"]');
|
|
120
|
-
assert.equal(ctx.t('fruits.404'), '', '(en) fruits.404 ~> ""');
|
|
121
|
-
assert.equal(ctx.t('error.404'), '', '(en) error.404 ~> ""');
|
|
122
|
-
|
|
123
|
-
ctx.locale('es');
|
|
124
|
-
assert.equal(ctx.t('fruits.apple'), 'manzana', '(es) fruits.apple');
|
|
125
|
-
assert.equal(ctx.t('fruits.orange'), 'naranja', '(es) fruits.orange');
|
|
126
|
-
assert.equal(ctx.t(['fruits', 'grape']), 'uva', '(es) ["fruits","grape"]');
|
|
127
|
-
assert.equal(ctx.t('fruits.404'), '', '(es) fruits.404 ~> ""');
|
|
128
|
-
assert.equal(ctx.t('error.404'), '', '(es) error.404 ~> ""');
|
|
99
|
+
let ctx = createTranslate({
|
|
100
|
+
en: { fruits: { apple: 'apple', orange: 'orange', grape: 'grape' } },
|
|
101
|
+
es: { fruits: { apple: 'manzana', orange: 'naranja', grape: 'uva' } },
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
ctx.locale('en');
|
|
105
|
+
assert.equal(ctx.t('fruits.apple'), 'apple', '(en) fruits.apple');
|
|
106
|
+
assert.equal(ctx.t('fruits.orange'), 'orange', '(en) fruits.orange');
|
|
107
|
+
assert.equal(ctx.t(['fruits', 'grape']), 'grape', '(en) ["fruits","grape"]');
|
|
108
|
+
assert.equal(ctx.t('fruits.404'), '', '(en) fruits.404 ~> ""');
|
|
109
|
+
assert.equal(ctx.t('error.404'), '', '(en) error.404 ~> ""');
|
|
110
|
+
|
|
111
|
+
ctx.locale('es');
|
|
112
|
+
assert.equal(ctx.t('fruits.apple'), 'manzana', '(es) fruits.apple');
|
|
113
|
+
assert.equal(ctx.t('fruits.orange'), 'naranja', '(es) fruits.orange');
|
|
114
|
+
assert.equal(ctx.t(['fruits', 'grape']), 'uva', '(es) ["fruits","grape"]');
|
|
115
|
+
assert.equal(ctx.t('fruits.404'), '', '(es) fruits.404 ~> ""');
|
|
116
|
+
assert.equal(ctx.t('error.404'), '', '(es) error.404 ~> ""');
|
|
129
117
|
});
|
|
130
118
|
|
|
131
119
|
test('arrays', () => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
ctx.locale('en');
|
|
144
|
-
|
|
145
|
-
assert.equal(ctx.t('foo', [1, 2, 3]), '1 + 2 = 3', '~> foo');
|
|
146
|
-
|
|
147
|
-
assert.equal(ctx.t('bar.0.baz', { colors: ['red', 'blue'] }), 'roses are red, violets are blue', '~> bar.0.baz');
|
|
120
|
+
let ctx = createTranslate({
|
|
121
|
+
en: { foo: '{{0}} + {{1}} = {{2}}', bar: [{ baz: 'roses are {{colors.0}}, violets are {{colors.1}}' }] },
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
ctx.locale('en');
|
|
125
|
+
|
|
126
|
+
assert.equal(ctx.t('foo', [1, 2, 3]), '1 + 2 = 3', '~> foo');
|
|
127
|
+
|
|
128
|
+
assert.equal(ctx.t('bar.0.baz', { colors: ['red', 'blue'] }), 'roses are red, violets are blue', '~> bar.0.baz');
|
|
148
129
|
});
|
|
149
130
|
|
|
150
131
|
test('invalid value', () => {
|
|
151
|
-
|
|
152
|
-
en: {
|
|
153
|
-
foo: ['bar'],
|
|
154
|
-
},
|
|
155
|
-
});
|
|
132
|
+
let ctx = createTranslate({ en: { foo: ['bar'] } });
|
|
156
133
|
|
|
157
|
-
|
|
134
|
+
assert.deepEqual(ctx.t('foo', null as never, 'en'), ['bar'] as any);
|
|
158
135
|
});
|
|
@@ -3,67 +3,67 @@ import type { ObjectPathLike } from '../objects/parseObjectPath';
|
|
|
3
3
|
import { renderTemplate } from '../strings/renderTemplate';
|
|
4
4
|
|
|
5
5
|
export interface Translate<T extends object> {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/** Get/Set the language key */
|
|
7
|
+
locale(lang?: string): string;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/** Define the dict of translations for a language */
|
|
10
|
+
dict(lang: string, dict: T): void;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/** Get the dict of translations for a language */
|
|
13
|
+
dict(lang: string): T;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/** Retrieve a translation segment for the current language */
|
|
16
|
+
t<X extends Record<string, any> | any[]>(key: ObjectPathLike, params?: X, lang?: string): string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function createTranslate<T extends object>(obj?: Record<string, T>): Translate<T> {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
let locale = '';
|
|
21
|
+
const tree = obj || {};
|
|
22
|
+
// en-US -> en-US,en
|
|
23
|
+
const keyOfDict = (s: string | string[]) => {
|
|
24
|
+
if (Array.isArray(s)) {
|
|
25
|
+
return s;
|
|
26
|
+
}
|
|
27
|
+
const sp = s.split(/[_-]/);
|
|
28
|
+
if (sp.length > 1) {
|
|
29
|
+
return [s, sp[0]];
|
|
30
|
+
}
|
|
31
|
+
return [s];
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
locale(lang) {
|
|
35
|
+
return (locale = lang || locale);
|
|
36
|
+
},
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
dict: ((lang, dict?) => {
|
|
39
|
+
if (dict) {
|
|
40
|
+
tree[lang] = Object.assign(tree[lang] || {}, dict);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
return tree[lang];
|
|
44
|
+
}) as Translate<T>['dict'],
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
46
|
+
t(key, params, lang) {
|
|
47
|
+
let val: any;
|
|
48
|
+
for (const k of keyOfDict(lang || locale)) {
|
|
49
|
+
val = get(tree[k], key, '');
|
|
50
|
+
if (val) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (process.env.NODE_ENV === 'development') {
|
|
55
|
+
if (val == null) {
|
|
56
|
+
console.error(
|
|
57
|
+
`[Translate] Missing the "${[].concat(key as any).join('.')}" key within the "${
|
|
58
|
+
lang || locale
|
|
59
|
+
}" dictionary`,
|
|
60
|
+
);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (typeof val === 'function') return val(params);
|
|
65
|
+
if (typeof val === 'string') return renderTemplate(val, params, 'common');
|
|
66
|
+
return val;
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
69
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { Promises } from './asyncs/Promises';
|
|
|
2
2
|
|
|
3
3
|
// arrays
|
|
4
4
|
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
firstOfMaybeArray,
|
|
6
|
+
lastOfMaybeArray,
|
|
7
|
+
arrayOfMaybeArray,
|
|
8
|
+
objectOfMaybeArray,
|
|
9
|
+
type MaybeArray,
|
|
10
10
|
} from './arrays/MaybeArray';
|
|
11
11
|
export { arrayFromAsync } from './arrays/arrayFromAsync';
|
|
12
12
|
|
|
@@ -33,6 +33,7 @@ export const isPromise = Promises.isPromise;
|
|
|
33
33
|
export { timeout, TimeoutError } from './asyncs/timeout';
|
|
34
34
|
|
|
35
35
|
// langs
|
|
36
|
+
export { isNil } from './langs/isNil';
|
|
36
37
|
export { shallowEqual } from './langs/shallowEqual';
|
|
37
38
|
export { deepEqual } from './langs/deepEqual';
|
|
38
39
|
export { deepFreeze } from './langs/deepFreeze';
|
|
@@ -42,6 +43,7 @@ export { isClass } from './langs/isClass';
|
|
|
42
43
|
export { isDefined } from './langs/isDefined';
|
|
43
44
|
export { isEmptyObject } from './langs/isEmptyObject';
|
|
44
45
|
export { isPlainObject } from './langs/isPlainObject';
|
|
46
|
+
export { ifPresent } from './langs/ifPresent';
|
|
45
47
|
export { parseBoolean } from './langs/parseBoolean';
|
|
46
48
|
export { maybeFunction, type MaybeFunction } from './langs/MaybeFunction';
|
|
47
49
|
export { memoize } from './langs/memoize';
|
|
@@ -50,8 +52,8 @@ export type { MixinFunction, MixinInstance, MixinReturnValue } from './langs/mix
|
|
|
50
52
|
export { getObjectId } from './langs/getObjectId';
|
|
51
53
|
export { getGlobalStates, setGlobalStates } from './langs/getGlobalStates';
|
|
52
54
|
|
|
53
|
-
export { AsyncCloser } from './
|
|
54
|
-
export { Closer } from './
|
|
55
|
+
export { AsyncCloser } from './langs/AsyncCloser';
|
|
56
|
+
export { Closer } from './langs/Closer';
|
|
55
57
|
|
|
56
58
|
export { isUUID } from './validations/isUUID';
|
|
57
59
|
export { parseTimestamp } from './validations/parseTimestamp';
|
|
@@ -60,16 +62,11 @@ export { parseTimestamp } from './validations/parseTimestamp';
|
|
|
60
62
|
export { parseModuleId, type ParsedModuleId } from './modules/parseModuleId';
|
|
61
63
|
export { isModule, type Module } from './modules/isModule';
|
|
62
64
|
|
|
63
|
-
// logging
|
|
64
|
-
export { type Logger, type LogLevel } from './logging/Logger';
|
|
65
|
-
export { createLogger } from './logging/createLogger';
|
|
66
|
-
export { createNoopLogger } from './logging/createNoopLogger';
|
|
67
|
-
export { createChildLogger } from './logging/createChildLogger';
|
|
68
|
-
|
|
69
65
|
// strings
|
|
70
66
|
export { pascalCase, camelCase } from './strings/camelCase';
|
|
71
67
|
export { renderTemplate } from './strings/renderTemplate';
|
|
72
68
|
export { formatBytes } from './strings/formatBytes';
|
|
69
|
+
export { parseBytes } from './strings/parseBytes';
|
|
73
70
|
|
|
74
71
|
// i18n
|
|
75
72
|
export { createTranslate } from './i18n/createTranslate';
|
|
@@ -81,6 +78,7 @@ export { ArrayBuffers } from './io/ArrayBuffers';
|
|
|
81
78
|
export { ByteBuffer } from './io/ByteBuffer';
|
|
82
79
|
export { fromHexDump, toHexDump } from './io/dump';
|
|
83
80
|
export { Buffer } from './io/Buffer';
|
|
81
|
+
export { type Bytes } from './io/types';
|
|
84
82
|
export { parseDataUri, type ParsedDataUri } from './io/parseDataUri';
|
|
85
83
|
export type { AbstractEncoding } from './io/AbstractEncoding';
|
|
86
84
|
|
|
@@ -89,14 +87,14 @@ export { copy } from './browsers/copy';
|
|
|
89
87
|
export { download } from './browsers/download';
|
|
90
88
|
export { loadScripts, loadStyles } from './browsers/loaders';
|
|
91
89
|
export { getFileFromDataTransfer } from './browsers/getFileFromDataTransfer';
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
export {
|
|
95
|
-
export {
|
|
90
|
+
// web & spec
|
|
91
|
+
export { requestIdleCallback, cancelIdleCallback } from './web/requestIdleCallback';
|
|
92
|
+
export { randomUUID } from './web/randomUUID';
|
|
93
|
+
export { getRandomValues } from './web/getRandomValues';
|
|
94
|
+
export { getGlobalThis } from './web/getGlobalThis';
|
|
95
|
+
export { structuredClone } from './web/structuredClone';
|
|
96
96
|
|
|
97
97
|
// crypto
|
|
98
|
-
export { randomUUID } from './crypto/randomUUID';
|
|
99
|
-
export { getRandomValues } from './crypto/getRandomValues';
|
|
100
98
|
export { sha1, sha256, sha384, sha512, hmac, type DigestOptions } from './crypto/hashing';
|
|
101
99
|
export { md5 } from './crypto/md5';
|
|
102
100
|
export { hex } from './crypto/base';
|
|
@@ -109,20 +107,21 @@ export { clamp } from './maths/clamp';
|
|
|
109
107
|
|
|
110
108
|
// network
|
|
111
109
|
export {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
110
|
+
type FetchLike,
|
|
111
|
+
createFetchWith,
|
|
112
|
+
createFetchWithLogging,
|
|
113
|
+
dumpResponse,
|
|
114
|
+
dumpRequest,
|
|
115
|
+
createFetchWithRetry,
|
|
116
|
+
type FetchWithRetryOptions,
|
|
119
117
|
} from './fetch';
|
|
120
118
|
|
|
121
119
|
// bundled
|
|
122
120
|
export { default as ms } from './libs/ms';
|
|
123
121
|
|
|
124
122
|
// error
|
|
125
|
-
export { Errors
|
|
123
|
+
export { Errors } from './errors/Errors';
|
|
124
|
+
export { DetailError, type ErrorDetail, type ErrorDetailInit } from './errors/DetailError';
|
|
126
125
|
// http
|
|
127
126
|
export { getHttpStatusText, isRetryableHttpStatus } from './fetch/HttpStatus';
|
|
128
127
|
|
|
@@ -4,18 +4,18 @@
|
|
|
4
4
|
* @see https://github.com/mafintosh/abstract-encoding
|
|
5
5
|
*/
|
|
6
6
|
export interface AbstractEncoding<T> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
/**
|
|
8
|
+
* encode a value to a buffer
|
|
9
|
+
*/
|
|
10
|
+
encode(data: T, buffer?: ArrayBuffer, offset?: number): BufferSource;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
/**
|
|
13
|
+
* decode data from buffer
|
|
14
|
+
*/
|
|
15
|
+
decode(buffer: BufferSource, start?: number, end?: number): T;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
/**
|
|
18
|
+
* byteLength of data
|
|
19
|
+
*/
|
|
20
|
+
byteLength?: (data: T) => number;
|
|
21
21
|
}
|
|
@@ -2,5 +2,5 @@ import { expectTypeOf, test } from 'vitest';
|
|
|
2
2
|
import { ArrayBuffers } from './ArrayBuffers';
|
|
3
3
|
|
|
4
4
|
test('my types work properly', () => {
|
|
5
|
-
|
|
5
|
+
expectTypeOf(ArrayBuffers.asView(Buffer, new Uint8Array())).toExtend<Buffer>();
|
|
6
6
|
});
|