@wener/utils 1.1.51 → 1.1.54
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 +136 -137
- 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 -76
- 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 +396 -171
- 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 +270 -34
- package/lib/langs/Closer.js +95 -29
- 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 +14 -10
- package/lib/langs/getObjectId.js +4 -6
- package/lib/langs/ifPresent.js +0 -2
- 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/parseDate.js +20 -0
- 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 -77
- 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/web/getGlobalThis.js +3 -4
- package/lib/web/getRandomValues.js +28 -20
- package/lib/web/randomUUID.js +7 -8
- package/lib/web/requestIdleCallback.js +13 -9
- package/lib/web/structuredClone.js +35 -28
- package/lib/web/structuredClone.test.js +81 -0
- package/package.json +9 -14
- 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 +33 -33
- 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 +2 -2
- package/src/crypto/hashing.test.ts +33 -47
- 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 +31 -31
- package/src/crypto/ulid.ts +116 -116
- package/src/emitter/types.ts +6 -6
- package/src/errors/DetailError.ts +151 -0
- package/src/errors/Errors.test.ts +15 -15
- package/src/errors/Errors.ts +97 -238
- package/src/fetch/HttpStatus.ts +77 -77
- package/src/fetch/createFetchWith.ts +25 -25
- package/src/fetch/createFetchWithLogging.ts +12 -15
- package/src/fetch/createFetchWithRetry.ts +79 -79
- 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 -26
- 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.test.ts +14 -14
- package/src/io/ArrayBuffers.ts +645 -415
- 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 +29 -29
- 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 +34 -34
- package/src/langs/Closer.ts +28 -28
- 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 +16 -16
- package/src/langs/getObjectId.ts +10 -13
- package/src/langs/ifPresent.ts +2 -2
- 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/parseDate.ts +13 -0
- 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 +79 -79
- package/src/server/crypto/md5.ts +1 -1
- package/src/server/fetch/createFetchWithProxyByNodeFetch.ts +28 -31
- package/src/server/fetch/createFetchWithProxyByUndici.ts +63 -69
- 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 +6 -6
- package/src/server/polyfill/polyfillFetch.ts +11 -21
- package/src/server/polyfill/polyfillJsDom.ts +59 -71
- package/src/server/polyfill/polyfillWebSocket.ts +14 -14
- 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 +8 -8
- package/src/validations/isUUID.ts +1 -1
- package/src/validations/parseTimestamp.test.ts +2 -2
- package/src/validations/parseTimestamp.ts +21 -21
- package/src/web/getGlobalThis.ts +6 -6
- package/src/web/getRandomValues.ts +29 -29
- package/src/web/randomUUID.ts +5 -5
- package/src/web/requestIdleCallback.ts +7 -10
- package/src/web/structuredClone.test.ts +8 -8
- package/src/web/structuredClone.ts +62 -62
- package/tsconfig.json +26 -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 -215
- 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/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/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/AsyncCloser.js.map +0 -1
- package/lib/langs/Closer.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/ifPresent.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/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/lib/web/getGlobalThis.js.map +0 -1
- package/lib/web/getRandomValues.js.map +0 -1
- package/lib/web/randomUUID.js.map +0 -1
- package/lib/web/requestIdleCallback.js.map +0 -1
- package/lib/web/structuredClone.js.map +0 -1
- package/src/cn/README.md +0 -3
- package/src/cn/division/DivisionCode.ts +0 -173
- 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 -22
- 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/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
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
function _type_of(obj) {
|
|
2
|
+
"@swc/helpers - typeof";
|
|
3
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
4
|
+
}
|
|
5
|
+
import { assert, test } from "vitest";
|
|
6
|
+
import { createTranslate } from "./createTranslate.js";
|
|
7
|
+
test("exports", function () {
|
|
8
|
+
assert.equal(typeof createTranslate === "undefined" ? "undefined" : _type_of(createTranslate), "function", "exports a function");
|
|
9
|
+
var out = createTranslate();
|
|
10
|
+
assert.equal(typeof out === "undefined" ? "undefined" : _type_of(out), "object", "returns an object");
|
|
11
|
+
assert.equal(_type_of(out.t), "function", "~> has \"t\" function");
|
|
12
|
+
assert.equal(_type_of(out.dict), "function", "~> has \"dict\" function");
|
|
13
|
+
assert.equal(_type_of(out.locale), "function", "~> has \"locale\" function");
|
|
14
|
+
});
|
|
15
|
+
test("usage", function () {
|
|
16
|
+
var ctx = createTranslate({
|
|
17
|
+
en: {
|
|
18
|
+
hello: "Hello, {{name}}!"
|
|
19
|
+
},
|
|
20
|
+
es: {
|
|
21
|
+
hello: "Hola {{name}}!"
|
|
22
|
+
},
|
|
23
|
+
pt: {
|
|
24
|
+
foo: "foo {{name}}~!"
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
assert.deepEqual(ctx.dict("en"), {
|
|
28
|
+
hello: "Hello, {{name}}!"
|
|
29
|
+
});
|
|
30
|
+
assert.equal(ctx.dict("foobar"), undefined);
|
|
31
|
+
var foo = ctx.t("hello");
|
|
32
|
+
assert.equal(foo, "", "~> \"\" w/o locale");
|
|
33
|
+
assert.equal(ctx.locale("en"), "en", ">>> ctx.locale()");
|
|
34
|
+
assert.equal(ctx.locale(), "en");
|
|
35
|
+
var bar = ctx.t("hello");
|
|
36
|
+
assert.notEqual(bar, "", "(en) found \"hello\" key");
|
|
37
|
+
assert.equal(bar, "Hello, !", "~> interpolations empty if missing param");
|
|
38
|
+
var baz = ctx.t("hello", {
|
|
39
|
+
name: "world"
|
|
40
|
+
});
|
|
41
|
+
assert.equal(baz, "Hello, world!", "~> interpolations successful");
|
|
42
|
+
var bat = ctx.t("hello", {
|
|
43
|
+
name: "world"
|
|
44
|
+
}, "es");
|
|
45
|
+
assert.notEqual(bat, "", "(es) found \"hello\" key");
|
|
46
|
+
assert.equal(bat, "Hola world!", "~> success");
|
|
47
|
+
assert.equal(ctx.t("hello", {
|
|
48
|
+
name: "world"
|
|
49
|
+
}, "pt"), "", "(pt) did NOT find \"hello\" key");
|
|
50
|
+
assert.equal(ctx.dict("pt", {
|
|
51
|
+
hello: "O\u00ED {{name}}!"
|
|
52
|
+
}), undefined, ">>> ctx.set()");
|
|
53
|
+
var quz = ctx.t("hello", {
|
|
54
|
+
name: "world"
|
|
55
|
+
}, "pt");
|
|
56
|
+
assert.notEqual(quz, "", "(pt) found \"hello\" key");
|
|
57
|
+
assert.equal(quz, "O\u00ED world!", "~> success");
|
|
58
|
+
var qut = ctx.t("foo", {
|
|
59
|
+
name: "bar"
|
|
60
|
+
}, "pt");
|
|
61
|
+
assert.notEqual(qut, "", "(pt) found \"foo\" key");
|
|
62
|
+
assert.equal(qut, "foo bar~!", "~> success");
|
|
63
|
+
assert.equal(ctx.locale("es"), "es", ">>> ctx.locale()");
|
|
64
|
+
assert.equal(ctx.locale(), "es");
|
|
65
|
+
assert.equal(ctx.locale(""), "es");
|
|
66
|
+
assert.equal(ctx.locale(false), "es");
|
|
67
|
+
assert.equal(ctx.locale(null), "es");
|
|
68
|
+
assert.equal(ctx.locale(0), "es");
|
|
69
|
+
var qux = ctx.t("hello", {
|
|
70
|
+
name: "default"
|
|
71
|
+
});
|
|
72
|
+
assert.notEqual(qux, "", "(es) found \"hello\" key");
|
|
73
|
+
assert.equal(qux, "Hola default!", "~> success");
|
|
74
|
+
assert.equal(ctx.t("hello", {
|
|
75
|
+
name: "world"
|
|
76
|
+
}, "de"), "", "(de) did NOT find \"hello\" key");
|
|
77
|
+
assert.equal(ctx.dict("de", {
|
|
78
|
+
hello: "Hallo {{name}}!"
|
|
79
|
+
}), undefined, ">>> ctx.set(de)");
|
|
80
|
+
var qar = ctx.t("hello", {
|
|
81
|
+
name: "world"
|
|
82
|
+
}, "de");
|
|
83
|
+
assert.notEqual(qar, "", "(de) found \"hello\" key");
|
|
84
|
+
assert.equal(qar, "Hallo world!", "~> success");
|
|
85
|
+
});
|
|
86
|
+
test("functional", function () {
|
|
87
|
+
var ctx = createTranslate({
|
|
88
|
+
en: {
|
|
89
|
+
hello: function hello(value) {
|
|
90
|
+
return "hello ".concat(value || "stranger", "~!");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
ctx.locale("en");
|
|
95
|
+
var foo = ctx.t("hello");
|
|
96
|
+
assert.equal(foo, "hello stranger~!", "~> called function w/o param");
|
|
97
|
+
var bar = ctx.t("hello", "world");
|
|
98
|
+
assert.equal(bar, "hello world~!", "~> called function w/ param (string)");
|
|
99
|
+
var baz = ctx.t("hello", [
|
|
100
|
+
1,
|
|
101
|
+
2,
|
|
102
|
+
3
|
|
103
|
+
]);
|
|
104
|
+
assert.equal(baz, "hello 1,2,3~!", "~> called function w/ param (array)");
|
|
105
|
+
});
|
|
106
|
+
test("nested", function () {
|
|
107
|
+
var ctx = createTranslate({
|
|
108
|
+
en: {
|
|
109
|
+
fruits: {
|
|
110
|
+
apple: "apple",
|
|
111
|
+
orange: "orange",
|
|
112
|
+
grape: "grape"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
es: {
|
|
116
|
+
fruits: {
|
|
117
|
+
apple: "manzana",
|
|
118
|
+
orange: "naranja",
|
|
119
|
+
grape: "uva"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
ctx.locale("en");
|
|
124
|
+
assert.equal(ctx.t("fruits.apple"), "apple", "(en) fruits.apple");
|
|
125
|
+
assert.equal(ctx.t("fruits.orange"), "orange", "(en) fruits.orange");
|
|
126
|
+
assert.equal(ctx.t([
|
|
127
|
+
"fruits",
|
|
128
|
+
"grape"
|
|
129
|
+
]), "grape", "(en) [\"fruits\",\"grape\"]");
|
|
130
|
+
assert.equal(ctx.t("fruits.404"), "", "(en) fruits.404 ~> \"\"");
|
|
131
|
+
assert.equal(ctx.t("error.404"), "", "(en) error.404 ~> \"\"");
|
|
132
|
+
ctx.locale("es");
|
|
133
|
+
assert.equal(ctx.t("fruits.apple"), "manzana", "(es) fruits.apple");
|
|
134
|
+
assert.equal(ctx.t("fruits.orange"), "naranja", "(es) fruits.orange");
|
|
135
|
+
assert.equal(ctx.t([
|
|
136
|
+
"fruits",
|
|
137
|
+
"grape"
|
|
138
|
+
]), "uva", "(es) [\"fruits\",\"grape\"]");
|
|
139
|
+
assert.equal(ctx.t("fruits.404"), "", "(es) fruits.404 ~> \"\"");
|
|
140
|
+
assert.equal(ctx.t("error.404"), "", "(es) error.404 ~> \"\"");
|
|
141
|
+
});
|
|
142
|
+
test("arrays", function () {
|
|
143
|
+
var ctx = createTranslate({
|
|
144
|
+
en: {
|
|
145
|
+
foo: "{{0}} + {{1}} = {{2}}",
|
|
146
|
+
bar: [
|
|
147
|
+
{
|
|
148
|
+
baz: "roses are {{colors.0}}, violets are {{colors.1}}"
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
ctx.locale("en");
|
|
154
|
+
assert.equal(ctx.t("foo", [
|
|
155
|
+
1,
|
|
156
|
+
2,
|
|
157
|
+
3
|
|
158
|
+
]), "1 + 2 = 3", "~> foo");
|
|
159
|
+
assert.equal(ctx.t("bar.0.baz", {
|
|
160
|
+
colors: [
|
|
161
|
+
"red",
|
|
162
|
+
"blue"
|
|
163
|
+
]
|
|
164
|
+
}), "roses are red, violets are blue", "~> bar.0.baz");
|
|
165
|
+
});
|
|
166
|
+
test("invalid value", function () {
|
|
167
|
+
var ctx = createTranslate({
|
|
168
|
+
en: {
|
|
169
|
+
foo: [
|
|
170
|
+
"bar"
|
|
171
|
+
]
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
assert.deepEqual(ctx.t("foo", null, "en"), [
|
|
175
|
+
"bar"
|
|
176
|
+
]);
|
|
177
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -1,93 +1,92 @@
|
|
|
1
|
-
import { Promises } from
|
|
1
|
+
import { Promises } from "./asyncs/Promises.js";
|
|
2
2
|
// arrays
|
|
3
|
-
export { firstOfMaybeArray, lastOfMaybeArray, arrayOfMaybeArray, objectOfMaybeArray } from
|
|
4
|
-
export { arrayFromAsync } from
|
|
3
|
+
export { firstOfMaybeArray, lastOfMaybeArray, arrayOfMaybeArray, objectOfMaybeArray } from "./arrays/MaybeArray.js";
|
|
4
|
+
export { arrayFromAsync } from "./arrays/arrayFromAsync.js";
|
|
5
5
|
// object
|
|
6
|
-
export { get } from
|
|
7
|
-
export { set } from
|
|
8
|
-
export { parseObjectPath } from
|
|
9
|
-
export { computeIfAbsent } from
|
|
10
|
-
export { merge } from
|
|
6
|
+
export { get } from "./objects/get.js";
|
|
7
|
+
export { set } from "./objects/set.js";
|
|
8
|
+
export { parseObjectPath } from "./objects/parseObjectPath.js";
|
|
9
|
+
export { computeIfAbsent } from "./objects/computeIfAbsent.js";
|
|
10
|
+
export { merge } from "./objects/merge/index.js";
|
|
11
11
|
// async
|
|
12
|
-
export { createLazyPromise } from
|
|
13
|
-
export { setAsyncInterval, clearAsyncInterval } from
|
|
12
|
+
export { createLazyPromise } from "./asyncs/createLazyPromise.js";
|
|
13
|
+
export { setAsyncInterval, clearAsyncInterval } from "./asyncs/AsyncInterval.js";
|
|
14
14
|
// async - iterator
|
|
15
|
-
export { createAsyncIterator } from
|
|
16
|
-
export { firstOfAsyncIterator } from
|
|
17
|
-
export { nextOfAsyncIterator } from
|
|
18
|
-
export { isIterator } from
|
|
19
|
-
export { Promises } from
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export { timeout, TimeoutError } from
|
|
15
|
+
export { createAsyncIterator } from "./asyncs/createAsyncIterator.js";
|
|
16
|
+
export { firstOfAsyncIterator } from "./asyncs/firstOfAsyncIterator.js";
|
|
17
|
+
export { nextOfAsyncIterator } from "./asyncs/nextOfAsyncIterator.js";
|
|
18
|
+
export { isIterator } from "./asyncs/isIterator.js";
|
|
19
|
+
export { Promises } from "./asyncs/Promises.js";
|
|
20
|
+
export var sleep = Promises.sleep;
|
|
21
|
+
export var isPromise = Promises.isPromise;
|
|
22
|
+
export { timeout, TimeoutError } from "./asyncs/timeout.js";
|
|
23
23
|
// langs
|
|
24
|
-
export {
|
|
25
|
-
export { deepEqual } from
|
|
26
|
-
export { deepFreeze } from
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
export { maybeFunction } from
|
|
36
|
-
export { memoize } from
|
|
37
|
-
export { mixin } from
|
|
38
|
-
export {
|
|
39
|
-
export {
|
|
40
|
-
export {
|
|
41
|
-
export {
|
|
42
|
-
export {
|
|
43
|
-
export {
|
|
24
|
+
export { classOf } from "./langs/classOf.js";
|
|
25
|
+
export { deepEqual } from "./langs/deepEqual.js";
|
|
26
|
+
export { deepFreeze } from "./langs/deepFreeze.js";
|
|
27
|
+
export { getGlobalStates, setGlobalStates } from "./langs/getGlobalStates.js";
|
|
28
|
+
export { getObjectId } from "./langs/getObjectId.js";
|
|
29
|
+
export { ifPresent } from "./langs/ifPresent.js";
|
|
30
|
+
export { isClass } from "./langs/isClass.js";
|
|
31
|
+
export { isDefined } from "./langs/isDefined.js";
|
|
32
|
+
export { isEmptyObject } from "./langs/isEmptyObject.js";
|
|
33
|
+
export { isNil } from "./langs/isNil.js";
|
|
34
|
+
export { isPlainObject } from "./langs/isPlainObject.js";
|
|
35
|
+
export { maybeFunction } from "./langs/MaybeFunction.js";
|
|
36
|
+
export { memoize } from "./langs/memoize.js";
|
|
37
|
+
export { mixin } from "./langs/mixin.js";
|
|
38
|
+
export { parseBoolean } from "./langs/parseBoolean.js";
|
|
39
|
+
export { parseDate } from "./langs/parseDate.js";
|
|
40
|
+
export { shallowClone } from "./langs/shallowClone.js";
|
|
41
|
+
export { shallowEqual } from "./langs/shallowEqual.js";
|
|
42
|
+
export { AsyncCloser } from "./langs/AsyncCloser.js";
|
|
43
|
+
export { Closer } from "./langs/Closer.js";
|
|
44
|
+
export { isUUID } from "./validations/isUUID.js";
|
|
45
|
+
export { parseTimestamp } from "./validations/parseTimestamp.js";
|
|
44
46
|
// modules
|
|
45
|
-
export { parseModuleId } from
|
|
46
|
-
export { isModule } from
|
|
47
|
-
export { createLogger } from './logging/createLogger.js';
|
|
48
|
-
export { createNoopLogger } from './logging/createNoopLogger.js';
|
|
49
|
-
export { createChildLogger } from './logging/createChildLogger.js';
|
|
47
|
+
export { parseModuleId } from "./modules/parseModuleId.js";
|
|
48
|
+
export { isModule } from "./modules/isModule.js";
|
|
50
49
|
// strings
|
|
51
|
-
export { pascalCase, camelCase } from
|
|
52
|
-
export { renderTemplate } from
|
|
53
|
-
export { formatBytes } from
|
|
50
|
+
export { pascalCase, camelCase } from "./strings/camelCase.js";
|
|
51
|
+
export { renderTemplate } from "./strings/renderTemplate.js";
|
|
52
|
+
export { formatBytes } from "./strings/formatBytes.js";
|
|
53
|
+
export { parseBytes } from "./strings/parseBytes.js";
|
|
54
54
|
// i18n
|
|
55
|
-
export { createTranslate } from
|
|
55
|
+
export { createTranslate } from "./i18n/createTranslate.js";
|
|
56
56
|
// io
|
|
57
|
-
export { isBuffer } from
|
|
58
|
-
export { isTransferable } from
|
|
59
|
-
export { ArrayBuffers } from
|
|
60
|
-
export { ByteBuffer } from
|
|
61
|
-
export { fromHexDump, toHexDump } from
|
|
62
|
-
export { Buffer } from
|
|
63
|
-
export { parseDataUri } from
|
|
57
|
+
export { isBuffer } from "./io/isBuffer.js";
|
|
58
|
+
export { isTransferable } from "./io/isTransferable.js";
|
|
59
|
+
export { ArrayBuffers } from "./io/ArrayBuffers.js";
|
|
60
|
+
export { ByteBuffer } from "./io/ByteBuffer.js";
|
|
61
|
+
export { fromHexDump, toHexDump } from "./io/dump.js";
|
|
62
|
+
export { Buffer } from "./io/Buffer.js";
|
|
63
|
+
export { parseDataUri } from "./io/parseDataUri.js";
|
|
64
64
|
// browser
|
|
65
|
-
export { copy } from
|
|
66
|
-
export { download } from
|
|
67
|
-
export { loadScripts, loadStyles } from
|
|
68
|
-
export { getFileFromDataTransfer } from
|
|
65
|
+
export { copy } from "./browsers/copy.js";
|
|
66
|
+
export { download } from "./browsers/download.js";
|
|
67
|
+
export { loadScripts, loadStyles } from "./browsers/loaders.js";
|
|
68
|
+
export { getFileFromDataTransfer } from "./browsers/getFileFromDataTransfer.js";
|
|
69
69
|
// web & spec
|
|
70
|
-
export { requestIdleCallback, cancelIdleCallback } from
|
|
71
|
-
export { randomUUID } from
|
|
72
|
-
export { getRandomValues } from
|
|
73
|
-
export { getGlobalThis } from
|
|
74
|
-
export { structuredClone } from
|
|
70
|
+
export { requestIdleCallback, cancelIdleCallback } from "./web/requestIdleCallback.js";
|
|
71
|
+
export { randomUUID } from "./web/randomUUID.js";
|
|
72
|
+
export { getRandomValues } from "./web/getRandomValues.js";
|
|
73
|
+
export { getGlobalThis } from "./web/getGlobalThis.js";
|
|
74
|
+
export { structuredClone } from "./web/structuredClone.js";
|
|
75
75
|
// crypto
|
|
76
|
-
export { sha1, sha256, sha384, sha512, hmac } from
|
|
77
|
-
export { md5 } from
|
|
78
|
-
export { hex } from
|
|
79
|
-
export { isULID, createULID, ulid, parseULID } from
|
|
80
|
-
export { PEM } from
|
|
76
|
+
export { sha1, sha256, sha384, sha512, hmac } from "./crypto/hashing.js";
|
|
77
|
+
export { md5 } from "./crypto/md5.js";
|
|
78
|
+
export { hex } from "./crypto/base.js";
|
|
79
|
+
export { isULID, createULID, ulid, parseULID } from "./crypto/ulid.js";
|
|
80
|
+
export { PEM } from "./crypto/pem/pem.js";
|
|
81
81
|
// math
|
|
82
|
-
export { createRandom } from
|
|
83
|
-
export { clamp } from
|
|
82
|
+
export { createRandom } from "./maths/random.js";
|
|
83
|
+
export { clamp } from "./maths/clamp.js";
|
|
84
84
|
// network
|
|
85
|
-
export { createFetchWith, createFetchWithLogging, dumpResponse, dumpRequest, createFetchWithRetry } from
|
|
85
|
+
export { createFetchWith, createFetchWithLogging, dumpResponse, dumpRequest, createFetchWithRetry } from "./fetch/index.js";
|
|
86
86
|
// bundled
|
|
87
|
-
export { default as ms } from
|
|
87
|
+
export { default as ms } from "./libs/ms.js";
|
|
88
88
|
// error
|
|
89
|
-
export { Errors
|
|
89
|
+
export { Errors } from "./errors/Errors.js";
|
|
90
|
+
export { DetailError } from "./errors/DetailError.js";
|
|
90
91
|
// http
|
|
91
|
-
export { getHttpStatusText, isRetryableHttpStatus } from
|
|
92
|
-
|
|
93
|
-
//# sourceMappingURL=index.js.map
|
|
92
|
+
export { getHttpStatusText, isRetryableHttpStatus } from "./fetch/HttpStatus.js";
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { expectTypeOf, test } from
|
|
2
|
-
import { ArrayBuffers } from
|
|
3
|
-
test(
|
|
4
|
-
expectTypeOf(ArrayBuffers.asView(Buffer, new Uint8Array())).
|
|
1
|
+
import { expectTypeOf, test } from "vitest";
|
|
2
|
+
import { ArrayBuffers } from "./ArrayBuffers.js";
|
|
3
|
+
test("my types work properly", function () {
|
|
4
|
+
expectTypeOf(ArrayBuffers.asView(Buffer, new Uint8Array())).toExtend();
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
//# sourceMappingURL=ArrayBuffer.test-d.js.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { assert, beforeAll, expect, test } from "vitest";
|
|
2
|
+
import { ArrayBuffers } from "./ArrayBuffers.js";
|
|
3
|
+
beforeAll(function () {
|
|
4
|
+
expect(ArrayBuffers.isNativeBufferAvailable()).toBeTruthy();
|
|
5
|
+
ArrayBuffers.setNativeBufferAllowed(false);
|
|
6
|
+
});
|
|
7
|
+
test("base64: ignore whitespace", function () {
|
|
8
|
+
var text = "\n YW9ldQ== ";
|
|
9
|
+
var buf = ArrayBuffers.from(text, "base64");
|
|
10
|
+
expect(ArrayBuffers.toString(buf)).toBe("aoeu");
|
|
11
|
+
});
|
|
12
|
+
test("base64: strings without padding", function () {
|
|
13
|
+
expect(ArrayBuffers.toString(ArrayBuffers.from("YW9ldQ", "base64"))).toBe("aoeu");
|
|
14
|
+
});
|
|
15
|
+
test("base64: newline in utf8 -- should not be an issue", function () {
|
|
16
|
+
assert.equal(ArrayBuffers.toString(ArrayBuffers.from("LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK", "base64"), "utf8"), "---\ntitle: Three dashes marks the spot\ntags:\n");
|
|
17
|
+
});
|
|
18
|
+
test("base64: newline in base64 -- should get stripped", function () {
|
|
19
|
+
assert.equal(ArrayBuffers.toString(ArrayBuffers.from("LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK\nICAtIHlhbWwKICAtIGZyb250LW1hdHRlcgogIC0gZGFzaGVzCmV4cGFuZWQt", "base64"), "utf8"), "---\ntitle: Three dashes marks the spot\ntags:\n - yaml\n - front-matter\n - dashes\nexpaned-");
|
|
20
|
+
});
|
|
21
|
+
test("base64: tab characters in base64 - should get stripped", function () {
|
|
22
|
+
assert.equal(ArrayBuffers.toString(ArrayBuffers.from("LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK\t\t\t\tICAtIHlhbWwKICAtIGZyb250LW1hdHRlcgogIC0gZGFzaGVzCmV4cGFuZWQt", "base64"), "utf8"), "---\ntitle: Three dashes marks the spot\ntags:\n - yaml\n - front-matter\n - dashes\nexpaned-");
|
|
23
|
+
});
|
|
24
|
+
test("base64: invalid non-alphanumeric characters -- should be stripped", function () {
|
|
25
|
+
expect(ArrayBuffers.toString(ArrayBuffers.from("!\"#$%&'()*,.:;<=>?@[\\]^`{|}~", "base64"), "utf8")).toBe("");
|
|
26
|
+
});
|
|
27
|
+
test("base64: high byte", function () {
|
|
28
|
+
var highByte = ArrayBuffers.from([
|
|
29
|
+
128
|
|
30
|
+
]);
|
|
31
|
+
assert.deepEqual(ArrayBuffers.alloc(1, ArrayBuffers.toString(highByte, "base64"), "base64"), highByte);
|
|
32
|
+
});
|
|
33
|
+
test("fromBase64", function () {
|
|
34
|
+
var text = "aoeu";
|
|
35
|
+
var buf = ArrayBuffers.from(text, "utf8", Uint8Array);
|
|
36
|
+
expect(ArrayBuffers.fromBase64(ArrayBuffers.toBase64(buf))).toEqual(buf);
|
|
37
|
+
});
|
|
38
|
+
test("fromHex", function () {
|
|
39
|
+
var text = "aoeu";
|
|
40
|
+
var buf = ArrayBuffers.from(text, "utf8", Uint8Array);
|
|
41
|
+
expect(ArrayBuffers.fromHex(ArrayBuffers.toHex(buf))).toEqual(buf);
|
|
42
|
+
});
|
|
43
|
+
test("toHex", function () {
|
|
44
|
+
var text = "aoeu";
|
|
45
|
+
var buf = ArrayBuffers.from(text, "utf8", Uint8Array);
|
|
46
|
+
expect(ArrayBuffers.toHex(buf)).toEqual("616f6575");
|
|
47
|
+
});
|
|
48
|
+
test("toBase64", function () {
|
|
49
|
+
var text = "aoeu";
|
|
50
|
+
var buf = ArrayBuffers.from(text, "utf8", Uint8Array);
|
|
51
|
+
expect(ArrayBuffers.toBase64(buf)).toEqual("YW9ldQ==");
|
|
52
|
+
});
|
|
53
|
+
test("base64: utf8 string", function () {
|
|
54
|
+
var text = "\u4F60\u597D";
|
|
55
|
+
// latin1 only
|
|
56
|
+
expect(function () {
|
|
57
|
+
return btoa(text);
|
|
58
|
+
}).toThrow("Invalid character");
|
|
59
|
+
expect(ArrayBuffers.toBase64(text)).toEqual("5L2g5aW9");
|
|
60
|
+
});
|