@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
package/lib/strings/camelCase.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// https://github.com/sindresorhus/camelcase/blob/master/index.js
|
|
2
2
|
function preserveCamelCase(string) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
for(
|
|
7
|
-
|
|
3
|
+
var isLastCharLower = false;
|
|
4
|
+
var isLastCharUpper = false;
|
|
5
|
+
var isLastLastCharUpper = false;
|
|
6
|
+
for(var i = 0; i < string.length; i++){
|
|
7
|
+
var character = string[i];
|
|
8
8
|
if (isLastCharLower && /[a-zA-Z]/.test(character) && character.toUpperCase() === character) {
|
|
9
9
|
string = string.slice(0, i) + '-' + string.slice(i);
|
|
10
10
|
isLastCharLower = false;
|
|
@@ -29,15 +29,22 @@ export function pascalCase(input) {
|
|
|
29
29
|
pascalCase: true
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
export function camelCase(input
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
export function camelCase(input) {
|
|
33
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
|
|
34
|
+
pascalCase: false
|
|
35
|
+
};
|
|
35
36
|
if (!(typeof input === 'string' || Array.isArray(input))) {
|
|
36
37
|
throw new TypeError('Expected the input to be `string | string[]`');
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
var postProcess = function(x) {
|
|
40
|
+
return options.pascalCase ? x.charAt(0).toUpperCase() + x.slice(1) : x;
|
|
41
|
+
};
|
|
39
42
|
if (Array.isArray(input)) {
|
|
40
|
-
input = input.map((x)
|
|
43
|
+
input = input.map(function(x) {
|
|
44
|
+
return x.trim();
|
|
45
|
+
}).filter(function(x) {
|
|
46
|
+
return x.length;
|
|
47
|
+
}).join('-');
|
|
41
48
|
} else {
|
|
42
49
|
input = input.trim();
|
|
43
50
|
}
|
|
@@ -47,12 +54,14 @@ export function camelCase(input, options = {
|
|
|
47
54
|
if (input.length === 1) {
|
|
48
55
|
return options.pascalCase ? input.toUpperCase() : input.toLowerCase();
|
|
49
56
|
}
|
|
50
|
-
|
|
57
|
+
var hasUpperCase = input !== input.toLowerCase();
|
|
51
58
|
if (hasUpperCase) {
|
|
52
59
|
input = preserveCamelCase(input);
|
|
53
60
|
}
|
|
54
|
-
input = input.replace(/^[_.\- ]+/, '').toLowerCase().replace(/[_.\- ]+(\w|$)/g, (_, p1)
|
|
61
|
+
input = input.replace(/^[_.\- ]+/, '').toLowerCase().replace(/[_.\- ]+(\w|$)/g, function(_, p1) {
|
|
62
|
+
return p1.toUpperCase();
|
|
63
|
+
}).replace(/\d+(\w|$)/g, function(m) {
|
|
64
|
+
return m.toUpperCase();
|
|
65
|
+
});
|
|
55
66
|
return postProcess(input);
|
|
56
67
|
}
|
|
57
|
-
|
|
58
|
-
//# sourceMappingURL=camelCase.js.map
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const thresh = si ? 1000 : 1024;
|
|
12
|
-
if (Math.abs(bytes) < thresh) {
|
|
13
|
-
return `${bytes} B`;
|
|
1
|
+
export function formatBytes(bytes) {
|
|
2
|
+
var optionsOrSi = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false, dp = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 1;
|
|
3
|
+
var options;
|
|
4
|
+
if (typeof optionsOrSi === 'boolean') {
|
|
5
|
+
options = {
|
|
6
|
+
si: optionsOrSi,
|
|
7
|
+
dp: dp
|
|
8
|
+
};
|
|
9
|
+
} else {
|
|
10
|
+
options = optionsOrSi || {};
|
|
14
11
|
}
|
|
15
|
-
|
|
12
|
+
var _options_si = options.si, si = _options_si === void 0 ? false : _options_si, tmp = options.dp, decimalPlaces = tmp === void 0 ? 1 : tmp, forceUnit = options.unit;
|
|
13
|
+
var thresh = si ? 1000 : 1024;
|
|
14
|
+
var units = si ? [
|
|
16
15
|
'kB',
|
|
17
16
|
'MB',
|
|
18
17
|
'GB',
|
|
@@ -31,13 +30,23 @@
|
|
|
31
30
|
'ZiB',
|
|
32
31
|
'YiB'
|
|
33
32
|
];
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
if (Math.abs(bytes) < thresh && !forceUnit) {
|
|
34
|
+
return "".concat(bytes, " B");
|
|
35
|
+
}
|
|
36
|
+
if (forceUnit && forceUnit !== 'B') {
|
|
37
|
+
var unitIndex = units.findIndex(function(u) {
|
|
38
|
+
return u.toLowerCase() === forceUnit.toLowerCase();
|
|
39
|
+
});
|
|
40
|
+
if (unitIndex !== -1) {
|
|
41
|
+
var value = bytes / Math.pow(thresh, unitIndex + 1);
|
|
42
|
+
return "".concat(value.toFixed(decimalPlaces), " ").concat(units[unitIndex]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
var u = -1;
|
|
46
|
+
var r = Math.pow(10, decimalPlaces);
|
|
36
47
|
do {
|
|
37
48
|
bytes /= thresh;
|
|
38
49
|
++u;
|
|
39
|
-
}while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1)
|
|
40
|
-
return bytes.toFixed(
|
|
50
|
+
}while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
|
|
51
|
+
return "".concat(bytes.toFixed(decimalPlaces), " ").concat(units[u]);
|
|
41
52
|
}
|
|
42
|
-
|
|
43
|
-
//# sourceMappingURL=formatBytes.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var UnitMultipliers = {
|
|
2
|
+
B: 1,
|
|
3
|
+
// SI
|
|
4
|
+
K: 1000,
|
|
5
|
+
KB: 1000,
|
|
6
|
+
M: Math.pow(1000, 2),
|
|
7
|
+
MB: Math.pow(1000, 2),
|
|
8
|
+
G: Math.pow(1000, 3),
|
|
9
|
+
GB: Math.pow(1000, 3),
|
|
10
|
+
T: Math.pow(1000, 4),
|
|
11
|
+
TB: Math.pow(1000, 4),
|
|
12
|
+
P: Math.pow(1000, 5),
|
|
13
|
+
PB: Math.pow(1000, 5),
|
|
14
|
+
E: Math.pow(1000, 6),
|
|
15
|
+
EB: Math.pow(1000, 6),
|
|
16
|
+
Z: Math.pow(1000, 7),
|
|
17
|
+
ZB: Math.pow(1000, 7),
|
|
18
|
+
Y: Math.pow(1000, 8),
|
|
19
|
+
YB: Math.pow(1000, 8),
|
|
20
|
+
// IEC
|
|
21
|
+
KIB: 1024,
|
|
22
|
+
MIB: Math.pow(1024, 2),
|
|
23
|
+
GIB: Math.pow(1024, 3),
|
|
24
|
+
TIB: Math.pow(1024, 4),
|
|
25
|
+
PIB: Math.pow(1024, 5),
|
|
26
|
+
EIB: Math.pow(1024, 6),
|
|
27
|
+
ZIB: Math.pow(1024, 7),
|
|
28
|
+
YIB: Math.pow(1024, 8)
|
|
29
|
+
};
|
|
30
|
+
export function parseBytes(str) {
|
|
31
|
+
if (typeof str !== 'string' || str.length === 0) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
var match = str.trim().match(/^([\d.]+)\s*([a-z]+)?$/i);
|
|
35
|
+
if (!match) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
var value = parseFloat(match[1]);
|
|
39
|
+
var unit = (match[2] || 'B').toUpperCase();
|
|
40
|
+
var multiplier = UnitMultipliers[unit];
|
|
41
|
+
// Handle cases like G -> GB
|
|
42
|
+
if (multiplier === undefined && unit.length === 1 && unit !== 'B') {
|
|
43
|
+
unit += 'B';
|
|
44
|
+
multiplier = UnitMultipliers[unit];
|
|
45
|
+
}
|
|
46
|
+
if (isNaN(value) || multiplier === undefined) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
value: value,
|
|
51
|
+
unit: match[2] || 'B',
|
|
52
|
+
bytes: value * multiplier
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { get } from
|
|
1
|
+
import { get } from "../objects/get.js";
|
|
2
2
|
/**
|
|
3
3
|
* render template like js template string
|
|
4
4
|
*
|
|
@@ -7,26 +7,31 @@ import { get } from '../objects/get.js';
|
|
|
7
7
|
* // 'My name is wener'
|
|
8
8
|
*
|
|
9
9
|
* @param match `js` for `${name}`, common for `{{name}}`
|
|
10
|
-
*/ export function renderTemplate(template, data
|
|
11
|
-
|
|
10
|
+
*/ export function renderTemplate(template, data) {
|
|
11
|
+
var match = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "js";
|
|
12
|
+
var getter;
|
|
12
13
|
if (!data) {
|
|
13
14
|
// todo warning in dev
|
|
14
|
-
getter = ()
|
|
15
|
-
|
|
15
|
+
getter = function () {
|
|
16
|
+
return "";
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
else if (typeof data === "function") {
|
|
16
20
|
getter = data;
|
|
17
|
-
} else {
|
|
18
|
-
getter = (v)=>get(data, v);
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
else {
|
|
23
|
+
getter = function (v) {
|
|
24
|
+
return get(data, v);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (typeof match === "string") {
|
|
21
28
|
match = Matches[match] || Matches.js;
|
|
22
29
|
}
|
|
23
|
-
return template.replace(match, (_, g)
|
|
30
|
+
return template.replace(match, function (_, g) {
|
|
24
31
|
return getter(g.trim());
|
|
25
32
|
});
|
|
26
33
|
}
|
|
27
|
-
|
|
34
|
+
var Matches = {
|
|
28
35
|
js: /\${(.*?)}/g,
|
|
29
36
|
common: /{{(.*?)}}/g
|
|
30
37
|
};
|
|
31
|
-
|
|
32
|
-
//# sourceMappingURL=renderTemplate.js.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/* eslint no-template-curly-in-string:0 */ function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length)
|
|
3
|
+
len = arr.length;
|
|
4
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
5
|
+
arr2[i] = arr[i];
|
|
6
|
+
return arr2;
|
|
7
|
+
}
|
|
8
|
+
function _array_with_holes(arr) {
|
|
9
|
+
if (Array.isArray(arr))
|
|
10
|
+
return arr;
|
|
11
|
+
}
|
|
12
|
+
function _iterable_to_array_limit(arr, i) {
|
|
13
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
14
|
+
if (_i == null)
|
|
15
|
+
return;
|
|
16
|
+
var _arr = [];
|
|
17
|
+
var _n = true;
|
|
18
|
+
var _d = false;
|
|
19
|
+
var _s, _e;
|
|
20
|
+
try {
|
|
21
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
22
|
+
_arr.push(_s.value);
|
|
23
|
+
if (i && _arr.length === i)
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
_d = true;
|
|
29
|
+
_e = err;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
try {
|
|
33
|
+
if (!_n && _i["return"] != null)
|
|
34
|
+
_i["return"]();
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
if (_d)
|
|
38
|
+
throw _e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return _arr;
|
|
42
|
+
}
|
|
43
|
+
function _non_iterable_rest() {
|
|
44
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
45
|
+
}
|
|
46
|
+
function _sliced_to_array(arr, i) {
|
|
47
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
48
|
+
}
|
|
49
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
50
|
+
if (!o)
|
|
51
|
+
return;
|
|
52
|
+
if (typeof o === "string")
|
|
53
|
+
return _array_like_to_array(o, minLen);
|
|
54
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
55
|
+
if (n === "Object" && o.constructor)
|
|
56
|
+
n = o.constructor.name;
|
|
57
|
+
if (n === "Map" || n === "Set")
|
|
58
|
+
return Array.from(n);
|
|
59
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
60
|
+
return _array_like_to_array(o, minLen);
|
|
61
|
+
}
|
|
62
|
+
import { expect, test } from "vitest";
|
|
63
|
+
import { renderTemplate } from "./renderTemplate.js";
|
|
64
|
+
test("renderTemplate", function () {
|
|
65
|
+
var obj = {
|
|
66
|
+
name: "wener",
|
|
67
|
+
authors: [
|
|
68
|
+
{
|
|
69
|
+
name: "wener"
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
};
|
|
73
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
74
|
+
try {
|
|
75
|
+
for (var _iterator = Object.entries({
|
|
76
|
+
"My name is ${name}": "My name is wener",
|
|
77
|
+
"My name is ${ authors[0].name }": "My name is wener"
|
|
78
|
+
})[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
79
|
+
var _step_value = _sliced_to_array(_step.value, 2), k = _step_value[0], v = _step_value[1];
|
|
80
|
+
expect(renderTemplate(k, obj)).toBe(v);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
_didIteratorError = true;
|
|
85
|
+
_iteratorError = err;
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
try {
|
|
89
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
90
|
+
_iterator.return();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
if (_didIteratorError) {
|
|
95
|
+
throw _iteratorError;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
expect(renderTemplate("My name is ${name}", function (v) {
|
|
100
|
+
return v;
|
|
101
|
+
})).toBe("My name is name");
|
|
102
|
+
expect(renderTemplate("My name is ${name}", obj, "common")).toBe("My name is ${name}");
|
|
103
|
+
expect(renderTemplate("My name is {{name}}", obj, "common")).toBe("My name is wener");
|
|
104
|
+
});
|
package/lib/typedoc.js
CHANGED
package/lib/types.d.js
CHANGED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length)
|
|
3
|
+
len = arr.length;
|
|
4
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
5
|
+
arr2[i] = arr[i];
|
|
6
|
+
return arr2;
|
|
7
|
+
}
|
|
8
|
+
function _array_with_holes(arr) {
|
|
9
|
+
if (Array.isArray(arr))
|
|
10
|
+
return arr;
|
|
11
|
+
}
|
|
12
|
+
function _iterable_to_array_limit(arr, i) {
|
|
13
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
14
|
+
if (_i == null)
|
|
15
|
+
return;
|
|
16
|
+
var _arr = [];
|
|
17
|
+
var _n = true;
|
|
18
|
+
var _d = false;
|
|
19
|
+
var _s, _e;
|
|
20
|
+
try {
|
|
21
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
22
|
+
_arr.push(_s.value);
|
|
23
|
+
if (i && _arr.length === i)
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
_d = true;
|
|
29
|
+
_e = err;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
try {
|
|
33
|
+
if (!_n && _i["return"] != null)
|
|
34
|
+
_i["return"]();
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
if (_d)
|
|
38
|
+
throw _e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return _arr;
|
|
42
|
+
}
|
|
43
|
+
function _non_iterable_rest() {
|
|
44
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
45
|
+
}
|
|
46
|
+
function _sliced_to_array(arr, i) {
|
|
47
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
48
|
+
}
|
|
49
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
50
|
+
if (!o)
|
|
51
|
+
return;
|
|
52
|
+
if (typeof o === "string")
|
|
53
|
+
return _array_like_to_array(o, minLen);
|
|
54
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
55
|
+
if (n === "Object" && o.constructor)
|
|
56
|
+
n = o.constructor.name;
|
|
57
|
+
if (n === "Map" || n === "Set")
|
|
58
|
+
return Array.from(n);
|
|
59
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
60
|
+
return _array_like_to_array(o, minLen);
|
|
61
|
+
}
|
|
62
|
+
import { expect, test } from "vitest";
|
|
63
|
+
import { randomUUID } from "../web/randomUUID.js";
|
|
64
|
+
import { isUUID } from "./isUUID.js";
|
|
65
|
+
test("isUUID", function () {
|
|
66
|
+
for (var _i = 0, _iter = [
|
|
67
|
+
[
|
|
68
|
+
undefined,
|
|
69
|
+
false
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
null,
|
|
73
|
+
false
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
"",
|
|
77
|
+
false
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
randomUUID(),
|
|
81
|
+
true
|
|
82
|
+
]
|
|
83
|
+
]; _i < _iter.length; _i++) {
|
|
84
|
+
var _iter__i = _sliced_to_array(_iter[_i], 2), a = _iter__i[0], b = _iter__i[1];
|
|
85
|
+
expect(isUUID(a), "".concat(a, " -> ").concat(b)).toEqual(b);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
+
function _instanceof(left, right) {
|
|
2
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
3
|
+
return !!right[Symbol.hasInstance](left);
|
|
4
|
+
} else {
|
|
5
|
+
return left instanceof right;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
1
8
|
export function parseTimestamp(raw) {
|
|
2
9
|
if (!raw) {
|
|
3
10
|
return undefined;
|
|
4
11
|
}
|
|
5
|
-
if (raw
|
|
12
|
+
if (_instanceof(raw, Date)) {
|
|
6
13
|
return raw;
|
|
7
14
|
}
|
|
8
15
|
if (typeof raw === 'string' && /^[0-9.]+$/.test(raw)) {
|
|
9
|
-
|
|
10
|
-
|
|
16
|
+
var n = parseFloat(raw);
|
|
17
|
+
var len = Math.floor(n).toString().length;
|
|
11
18
|
/*
|
|
12
19
|
最常见的是 10 位和 13 位
|
|
13
20
|
9999999999 - 10*9 - 1970-04-26
|
|
@@ -18,12 +25,10 @@ export function parseTimestamp(raw) {
|
|
|
18
25
|
}
|
|
19
26
|
return new Date(n);
|
|
20
27
|
} else if (typeof raw === 'string') {
|
|
21
|
-
|
|
28
|
+
var date = new Date(raw);
|
|
22
29
|
if (!isNaN(+date)) {
|
|
23
30
|
return date;
|
|
24
31
|
}
|
|
25
32
|
}
|
|
26
|
-
throw new Error(
|
|
33
|
+
throw new Error('parseTimestamp: invalid "'.concat(raw, '"'));
|
|
27
34
|
}
|
|
28
|
-
|
|
29
|
-
//# sourceMappingURL=parseTimestamp.js.map
|
package/lib/web/getGlobalThis.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var _this = this;
|
|
1
2
|
/**
|
|
2
3
|
* isomorphic globalThis
|
|
3
4
|
*
|
|
@@ -7,13 +8,11 @@
|
|
|
7
8
|
*
|
|
8
9
|
* @see https://caniuse.com/#search=globalThis
|
|
9
10
|
* @see https://v8.dev/features/globalthis
|
|
10
|
-
*/ export
|
|
11
|
+
*/ export var getGlobalThis = function() {
|
|
11
12
|
if (typeof globalThis !== 'undefined') return globalThis;
|
|
12
13
|
if (typeof self !== 'undefined') return self;
|
|
13
14
|
if (typeof window !== 'undefined') return window;
|
|
14
15
|
if (typeof global !== 'undefined') return global;
|
|
15
|
-
if (typeof
|
|
16
|
+
if (typeof _this !== 'undefined') return _this;
|
|
16
17
|
throw new Error('Unable to locate global `this`');
|
|
17
18
|
};
|
|
18
|
-
|
|
19
|
-
//# sourceMappingURL=getGlobalThis.js.map
|
|
@@ -1,36 +1,44 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
function _instanceof(left, right) {
|
|
3
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
4
|
+
return !!right[Symbol.hasInstance](left);
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
return left instanceof right;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
var _globalThis_crypto_getRandomValues, _globalThis_crypto, _globalThis_msCrypto_getRandomValues, _globalThis_msCrypto;
|
|
11
|
+
import { getNodeCrypto } from "../crypto/getNodeCrypto.js";
|
|
12
|
+
import { getGlobalThis } from "./getGlobalThis.js";
|
|
13
|
+
var globalThis = getGlobalThis();
|
|
5
14
|
// chrome 11+, safari 5+, nodejs 17.4+
|
|
6
15
|
// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
|
|
7
|
-
export
|
|
8
|
-
throw new Error(
|
|
9
|
-
}
|
|
16
|
+
export var getRandomValues = ((_globalThis_crypto = globalThis.crypto) === null || _globalThis_crypto === void 0 ? void 0 : (_globalThis_crypto_getRandomValues = _globalThis_crypto.getRandomValues) === null || _globalThis_crypto_getRandomValues === void 0 ? void 0 : _globalThis_crypto_getRandomValues.bind(globalThis.crypto)) || ((_globalThis_msCrypto = globalThis.msCrypto) === null || _globalThis_msCrypto === void 0 ? void 0 : (_globalThis_msCrypto_getRandomValues = _globalThis_msCrypto.getRandomValues) === null || _globalThis_msCrypto_getRandomValues === void 0 ? void 0 : _globalThis_msCrypto_getRandomValues.bind(globalThis.msCrypto)) || function () {
|
|
17
|
+
throw new Error("[getRandomValues]: No secure random number generator available.");
|
|
18
|
+
};
|
|
10
19
|
function _getRandomValues(buf) {
|
|
11
|
-
|
|
20
|
+
var nodeCrypto = getNodeCrypto();
|
|
12
21
|
// avoid type error
|
|
13
|
-
|
|
14
|
-
if (wc
|
|
15
|
-
|
|
22
|
+
var wc = nodeCrypto === null || nodeCrypto === void 0 ? void 0 : nodeCrypto.webcrypto;
|
|
23
|
+
if (wc === null || wc === void 0 ? void 0 : wc.getRandomValues) {
|
|
24
|
+
var _wc_getRandomValues;
|
|
25
|
+
getRandomValues = (_wc_getRandomValues = wc.getRandomValues) === null || _wc_getRandomValues === void 0 ? void 0 : _wc_getRandomValues.bind(nodeCrypto === null || nodeCrypto === void 0 ? void 0 : nodeCrypto.webcrypto);
|
|
16
26
|
return wc.getRandomValues(buf);
|
|
17
27
|
}
|
|
18
|
-
if (nodeCrypto
|
|
19
|
-
if (!(buf
|
|
20
|
-
throw new TypeError(
|
|
28
|
+
if (nodeCrypto === null || nodeCrypto === void 0 ? void 0 : nodeCrypto.randomBytes) {
|
|
29
|
+
if (!_instanceof(buf, Uint8Array)) {
|
|
30
|
+
throw new TypeError("expected Uint8Array");
|
|
21
31
|
}
|
|
22
32
|
if (buf.length > 65536) {
|
|
23
|
-
|
|
33
|
+
var e = new Error();
|
|
24
34
|
e.code = 22;
|
|
25
|
-
e.message =
|
|
26
|
-
e.name =
|
|
35
|
+
e.message = "Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (".concat(buf.length, ") exceeds the number of bytes of entropy available via this API (65536).");
|
|
36
|
+
e.name = "QuotaExceededError";
|
|
27
37
|
throw e;
|
|
28
38
|
}
|
|
29
|
-
|
|
39
|
+
var bytes = nodeCrypto.randomBytes(buf.length);
|
|
30
40
|
buf.set(bytes);
|
|
31
41
|
return buf;
|
|
32
42
|
}
|
|
33
|
-
throw new Error(
|
|
43
|
+
throw new Error("[getRandomValues]: No secure random number generator available.");
|
|
34
44
|
}
|
|
35
|
-
|
|
36
|
-
//# sourceMappingURL=getRandomValues.js.map
|
package/lib/web/randomUUID.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var _globalThis_crypto_randomUUID, _globalThis_crypto;
|
|
2
|
+
import { getGlobalThis } from "./getGlobalThis.js";
|
|
3
|
+
var globalThis = getGlobalThis();
|
|
3
4
|
/**
|
|
4
5
|
* generate random UUIDv4
|
|
5
|
-
*/ export
|
|
6
|
+
*/ export var randomUUID = ((_globalThis_crypto = globalThis.crypto) === null || _globalThis_crypto === void 0 ? void 0 : (_globalThis_crypto_randomUUID = _globalThis_crypto.randomUUID) === null || _globalThis_crypto_randomUUID === void 0 ? void 0 : _globalThis_crypto_randomUUID.bind(globalThis.crypto)) || _randomUUID;
|
|
6
7
|
/**
|
|
7
8
|
* @internal
|
|
8
9
|
*/ export function _randomUUID() {
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
11
|
+
var r = Math.random() * 16 | 0;
|
|
12
|
+
var v = c === "x" ? r : r & 3 | 8;
|
|
12
13
|
return v.toString(16);
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=randomUUID.js.map
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
// for safari
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export var requestIdleCallback = globalThis.requestIdleCallback || function(callback, options) {
|
|
3
|
+
var start = Date.now();
|
|
4
|
+
var deadline = {
|
|
5
5
|
didTimeout: false,
|
|
6
|
-
timeRemaining: ()
|
|
6
|
+
timeRemaining: function() {
|
|
7
|
+
return Math.max(0, 50 - (Date.now() - start));
|
|
8
|
+
}
|
|
7
9
|
};
|
|
8
10
|
// skip options?.timeout
|
|
9
|
-
return setTimeout(()
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
return setTimeout(function() {
|
|
12
|
+
return callback(deadline);
|
|
13
|
+
}, 1);
|
|
14
|
+
};
|
|
15
|
+
export var cancelIdleCallback = globalThis.cancelIdleCallback || function(id) {
|
|
16
|
+
return clearTimeout(id);
|
|
17
|
+
};
|