umt 2.12.2 → 2.13.0
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/README.md +60 -0
- package/module/Array/arraysJoin.js +1 -1
- package/module/Array/arraysJoin.js.map +1 -1
- package/module/Array/chunk.js +1 -2
- package/module/Array/chunk.js.map +1 -1
- package/module/Array/generateNumberArray.js +13 -3
- package/module/Array/generateNumberArray.js.map +1 -1
- package/module/Array/getArraysDiff.js +5 -1
- package/module/Array/getArraysDiff.js.map +1 -1
- package/module/Array/mergeSort.js +45 -18
- package/module/Array/mergeSort.js.map +1 -1
- package/module/Array/pop.js +2 -1
- package/module/Array/pop.js.map +1 -1
- package/module/Array/randomSelect.js +8 -0
- package/module/Array/randomSelect.js.map +1 -1
- package/module/Array/sortingHelpers/rangeValidator.js +3 -2
- package/module/Array/sortingHelpers/rangeValidator.js.map +1 -1
- package/module/Array/timSort.js +25 -23
- package/module/Array/timSort.js.map +1 -1
- package/module/Array/ultraNumberSort.js +206 -133
- package/module/Array/ultraNumberSort.js.map +1 -1
- package/module/Async/defer.d.ts +18 -0
- package/module/Async/defer.js +19 -0
- package/module/Async/defer.js.map +1 -0
- package/module/Async/index.d.ts +4 -0
- package/module/Async/index.js +5 -0
- package/module/Async/index.js.map +1 -0
- package/module/Async/parallel.d.ts +10 -0
- package/module/Async/parallel.js +44 -0
- package/module/Async/parallel.js.map +1 -0
- package/module/Async/sleep.d.ts +8 -0
- package/module/Async/sleep.js +11 -0
- package/module/Async/sleep.js.map +1 -0
- package/module/Async/timeout.d.ts +10 -0
- package/module/Async/timeout.js +22 -0
- package/module/Async/timeout.js.map +1 -0
- package/module/Color/cmykToRgba.js +6 -7
- package/module/Color/cmykToRgba.js.map +1 -1
- package/module/Color/hexaToRgba.js +1 -8
- package/module/Color/hexaToRgba.js.map +1 -1
- package/module/Color/hslaToRgba.d.ts +0 -1
- package/module/Color/hslaToRgba.js +7 -22
- package/module/Color/hslaToRgba.js.map +1 -1
- package/module/Color/rgbaToCmyk.js +0 -11
- package/module/Color/rgbaToCmyk.js.map +1 -1
- package/module/Color/rgbaToHexA.js +2 -15
- package/module/Color/rgbaToHexA.js.map +1 -1
- package/module/Color/rgbaToHsla.d.ts +0 -1
- package/module/Color/rgbaToHsla.js +0 -12
- package/module/Color/rgbaToHsla.js.map +1 -1
- package/module/Crypto/constants.d.ts +2 -0
- package/module/Crypto/constants.js +3 -0
- package/module/Crypto/constants.js.map +1 -0
- package/module/Crypto/decodeBase32.js +2 -4
- package/module/Crypto/decodeBase32.js.map +1 -1
- package/module/Crypto/decodeBase58.js +2 -4
- package/module/Crypto/decodeBase58.js.map +1 -1
- package/module/Crypto/encodeBase32.js +2 -1
- package/module/Crypto/encodeBase32.js.map +1 -1
- package/module/Crypto/encodeBase58.js +2 -1
- package/module/Crypto/encodeBase58.js.map +1 -1
- package/module/DataStructure/index.d.ts +2 -0
- package/module/DataStructure/index.js +2 -0
- package/module/DataStructure/index.js.map +1 -1
- package/module/DataStructure/lruCache.d.ts +139 -0
- package/module/DataStructure/lruCache.js +172 -0
- package/module/DataStructure/lruCache.js.map +1 -0
- package/module/DataStructure/ttlCache.d.ts +139 -0
- package/module/DataStructure/ttlCache.js +172 -0
- package/module/DataStructure/ttlCache.js.map +1 -0
- package/module/Error/flatMapResult.d.ts +23 -0
- package/module/Error/flatMapResult.js +28 -0
- package/module/Error/flatMapResult.js.map +1 -0
- package/module/Error/index.d.ts +3 -0
- package/module/Error/index.js +3 -0
- package/module/Error/index.js.map +1 -1
- package/module/Error/mapResult.d.ts +21 -0
- package/module/Error/mapResult.js +27 -0
- package/module/Error/mapResult.js.map +1 -0
- package/module/Error/matchResult.d.ts +25 -0
- package/module/Error/matchResult.js +27 -0
- package/module/Error/matchResult.js.map +1 -0
- package/module/Error/safeExecute.d.ts +16 -3
- package/module/Error/safeExecute.js +5 -2
- package/module/Error/safeExecute.js.map +1 -1
- package/module/Function/debounce.d.ts +38 -0
- package/module/Function/debounce.js +67 -0
- package/module/Function/debounce.js.map +1 -0
- package/module/Function/index.d.ts +4 -0
- package/module/Function/index.js +4 -0
- package/module/Function/index.js.map +1 -1
- package/module/Function/memoize.d.ts +36 -0
- package/module/Function/memoize.js +54 -0
- package/module/Function/memoize.js.map +1 -0
- package/module/Function/once.d.ts +18 -0
- package/module/Function/once.js +29 -0
- package/module/Function/once.js.map +1 -0
- package/module/Function/throttle.d.ts +25 -0
- package/module/Function/throttle.js +55 -0
- package/module/Function/throttle.js.map +1 -0
- package/module/IP/cidrToLong.d.ts +0 -1
- package/module/IP/cidrToLong.js +0 -4
- package/module/IP/cidrToLong.js.map +1 -1
- package/module/IP/cidrToSubnetMask.d.ts +0 -1
- package/module/IP/cidrToSubnetMask.js +0 -1
- package/module/IP/cidrToSubnetMask.js.map +1 -1
- package/module/IP/getNetworkAddress.d.ts +0 -1
- package/module/IP/getNetworkAddress.js +2 -32
- package/module/IP/getNetworkAddress.js.map +1 -1
- package/module/IP/ipToBinaryString.d.ts +0 -1
- package/module/IP/ipToBinaryString.js +2 -25
- package/module/IP/ipToBinaryString.js.map +1 -1
- package/module/IP/ipToLong.d.ts +0 -1
- package/module/IP/ipToLong.js +0 -1
- package/module/IP/ipToLong.js.map +1 -1
- package/module/IP/isInRange.d.ts +0 -1
- package/module/IP/isInRange.js +5 -28
- package/module/IP/isInRange.js.map +1 -1
- package/module/IP/isPrivateIp.d.ts +0 -1
- package/module/IP/isPrivateIp.js +1 -10
- package/module/IP/isPrivateIp.js.map +1 -1
- package/module/IP/longToIp.d.ts +0 -1
- package/module/IP/longToIp.js +0 -8
- package/module/IP/longToIp.js.map +1 -1
- package/module/IP/subnetMaskToCidr.d.ts +0 -1
- package/module/IP/subnetMaskToCidr.js +2 -23
- package/module/IP/subnetMaskToCidr.js.map +1 -1
- package/module/Iterator/index.d.ts +3 -0
- package/module/Iterator/index.js +4 -0
- package/module/Iterator/index.js.map +1 -0
- package/module/Iterator/lazyFilter.d.ts +10 -0
- package/module/Iterator/lazyFilter.js +19 -0
- package/module/Iterator/lazyFilter.js.map +1 -0
- package/module/Iterator/lazyMap.d.ts +10 -0
- package/module/Iterator/lazyMap.js +17 -0
- package/module/Iterator/lazyMap.js.map +1 -0
- package/module/Iterator/lazyTake.d.ts +10 -0
- package/module/Iterator/lazyTake.js +20 -0
- package/module/Iterator/lazyTake.js.map +1 -0
- package/module/Math/addition.js +20 -4
- package/module/Math/addition.js.map +1 -1
- package/module/Math/average.js +3 -3
- package/module/Math/average.js.map +1 -1
- package/module/Math/bitwise.js +1 -1
- package/module/Math/bitwise.js.map +1 -1
- package/module/Math/calculator/core.js +2 -1
- package/module/Math/calculator/core.js.map +1 -1
- package/module/Math/calculator/literalExpression.js +1 -1
- package/module/Math/clamp.d.ts +16 -0
- package/module/Math/clamp.js +19 -0
- package/module/Math/clamp.js.map +1 -0
- package/module/Math/correlationCoefficient.js +0 -3
- package/module/Math/correlationCoefficient.js.map +1 -1
- package/module/Math/inRange.d.ts +19 -0
- package/module/Math/inRange.js +24 -0
- package/module/Math/inRange.js.map +1 -0
- package/module/Math/index.d.ts +3 -0
- package/module/Math/index.js +3 -0
- package/module/Math/index.js.map +1 -1
- package/module/Math/median.js +2 -2
- package/module/Math/median.js.map +1 -1
- package/module/Math/nCr.js +2 -4
- package/module/Math/nCr.js.map +1 -1
- package/module/Math/percentile.js +2 -5
- package/module/Math/percentile.js.map +1 -1
- package/module/Math/primeFactorization.js +1 -1
- package/module/Math/primeFactorization.js.map +1 -1
- package/module/Math/sumPrecise.d.ts +14 -0
- package/module/Math/sumPrecise.js +27 -0
- package/module/Math/sumPrecise.js.map +1 -0
- package/module/Math/uuidv7.js +56 -22
- package/module/Math/uuidv7.js.map +1 -1
- package/module/Number/formatNumber.d.ts +42 -0
- package/module/Number/formatNumber.js +44 -0
- package/module/Number/formatNumber.js.map +1 -0
- package/module/Number/index.d.ts +3 -0
- package/module/Number/index.js +4 -0
- package/module/Number/index.js.map +1 -0
- package/module/Number/toOrdinal.d.ts +20 -0
- package/module/Number/toOrdinal.js +37 -0
- package/module/Number/toOrdinal.js.map +1 -0
- package/module/Number/toPercentage.d.ts +20 -0
- package/module/Number/toPercentage.js +27 -0
- package/module/Number/toPercentage.js.map +1 -0
- package/module/Object/deepClone.d.ts +15 -0
- package/module/Object/deepClone.js +62 -0
- package/module/Object/deepClone.js.map +1 -0
- package/module/Object/getObjectsCommon.d.ts +23 -0
- package/module/Object/getObjectsCommon.js +60 -0
- package/module/Object/getObjectsCommon.js.map +1 -0
- package/module/Object/getObjectsDiff.d.ts +25 -0
- package/module/Object/getObjectsDiff.js +79 -0
- package/module/Object/getObjectsDiff.js.map +1 -0
- package/module/Object/index.d.ts +6 -0
- package/module/Object/index.js +6 -0
- package/module/Object/index.js.map +1 -1
- package/module/Object/isPlainObject.d.ts +16 -0
- package/module/Object/isPlainObject.js +32 -0
- package/module/Object/isPlainObject.js.map +1 -0
- package/module/Object/mapKeys.d.ts +15 -0
- package/module/Object/mapKeys.js +28 -0
- package/module/Object/mapKeys.js.map +1 -0
- package/module/Object/mapValues.d.ts +15 -0
- package/module/Object/mapValues.js +27 -0
- package/module/Object/mapValues.js.map +1 -0
- package/module/Object/mergeDeep.js +4 -9
- package/module/Object/mergeDeep.js.map +1 -1
- package/module/Object/omit.d.ts +1 -1
- package/module/Object/omit.js.map +1 -1
- package/module/Object/pickDeep.js +6 -1
- package/module/Object/pickDeep.js.map +1 -1
- package/module/Predicate/every.d.ts +14 -0
- package/module/Predicate/every.js +22 -0
- package/module/Predicate/every.js.map +1 -0
- package/module/Predicate/index.d.ts +6 -0
- package/module/Predicate/index.js +7 -0
- package/module/Predicate/index.js.map +1 -0
- package/module/Predicate/isNotNullish.d.ts +11 -0
- package/module/Predicate/isNotNullish.js +12 -0
- package/module/Predicate/isNotNullish.js.map +1 -0
- package/module/Predicate/isNullish.d.ts +11 -0
- package/module/Predicate/isNullish.js +12 -0
- package/module/Predicate/isNullish.js.map +1 -0
- package/module/Predicate/matches.d.ts +11 -0
- package/module/Predicate/matches.js +20 -0
- package/module/Predicate/matches.js.map +1 -0
- package/module/Predicate/not.d.ts +10 -0
- package/module/Predicate/not.js +11 -0
- package/module/Predicate/not.js.map +1 -0
- package/module/Predicate/some.d.ts +15 -0
- package/module/Predicate/some.js +23 -0
- package/module/Predicate/some.js.map +1 -0
- package/module/String/camelCase.js +2 -2
- package/module/String/camelCase.js.map +1 -1
- package/module/String/escapeHtml.js +1 -1
- package/module/String/formatString/getValue.js +1 -1
- package/module/String/formatString/getValue.js.map +1 -1
- package/module/String/fromBase64.d.ts +0 -1
- package/module/String/fromBase64.js +1 -9
- package/module/String/fromBase64.js.map +1 -1
- package/module/String/fuzzySearch.js +74 -6
- package/module/String/fuzzySearch.js.map +1 -1
- package/module/String/kebabCase.js +1 -1
- package/module/String/kebabCase.js.map +1 -1
- package/module/String/levenshteinDistance.js +1 -2
- package/module/String/levenshteinDistance.js.map +1 -1
- package/module/String/randomString.js +23 -2
- package/module/String/randomString.js.map +1 -1
- package/module/String/reverseString.js +1 -1
- package/module/String/reverseString.js.map +1 -1
- package/module/String/slugify.js +1 -1
- package/module/String/toHalfWidth.js +2 -2
- package/module/String/toHalfWidth.js.map +1 -1
- package/module/String/truncate.js +0 -3
- package/module/String/truncate.js.map +1 -1
- package/module/String/unescapeHtml.js +1 -1
- package/module/String/unescapeHtml.js.map +1 -1
- package/module/Time/convertTime.js +4 -3
- package/module/Time/convertTime.js.map +1 -1
- package/module/Tool/escapeRegExp.d.ts +8 -0
- package/module/Tool/escapeRegExp.js +11 -0
- package/module/Tool/escapeRegExp.js.map +1 -0
- package/module/Tool/index.d.ts +1 -0
- package/module/Tool/index.js +1 -0
- package/module/Tool/index.js.map +1 -1
- package/module/URL/buildUrl.d.ts +17 -0
- package/module/URL/buildUrl.js +24 -0
- package/module/URL/buildUrl.js.map +1 -0
- package/module/URL/index.d.ts +4 -0
- package/module/URL/index.js +5 -0
- package/module/URL/index.js.map +1 -0
- package/module/URL/isAbsoluteUrl.d.ts +20 -0
- package/module/URL/isAbsoluteUrl.js +23 -0
- package/module/URL/isAbsoluteUrl.js.map +1 -0
- package/module/URL/joinPath.d.ts +24 -0
- package/module/URL/joinPath.js +43 -0
- package/module/URL/joinPath.js.map +1 -0
- package/module/URL/parseQueryString.d.ts +22 -0
- package/module/URL/parseQueryString.js +34 -0
- package/module/URL/parseQueryString.js.map +1 -0
- package/module/Validate/parseEmail.js +5 -5
- package/module/Validate/parseEmail.js.map +1 -1
- package/module/es5/Array/arraysJoin.js +1 -1
- package/module/es5/Array/chunk.js +3 -2
- package/module/es5/Array/generateNumberArray.js +21 -3
- package/module/es5/Array/getArraysDiff.js +5 -3
- package/module/es5/Array/mergeSort.js +51 -19
- package/module/es5/Array/pop.js +2 -7
- package/module/es5/Array/randomSelect.js +8 -0
- package/module/es5/Array/sortingHelpers/rangeValidator.js +3 -2
- package/module/es5/Array/timSort.js +25 -23
- package/module/es5/Array/ultraNumberSort.js +221 -207
- package/module/es5/Async/defer.d.ts +18 -0
- package/module/es5/Async/defer.js +32 -0
- package/module/es5/Async/index.d.ts +4 -0
- package/module/es5/Async/index.js +49 -0
- package/module/es5/Async/parallel.d.ts +10 -0
- package/module/es5/Async/parallel.js +48 -0
- package/module/es5/Async/sleep.d.ts +8 -0
- package/module/es5/Async/sleep.js +18 -0
- package/module/es5/Async/timeout.d.ts +10 -0
- package/module/es5/Async/timeout.js +29 -0
- package/module/es5/Color/cmykToRgba.js +6 -7
- package/module/es5/Color/hexaToRgba.js +7 -5
- package/module/es5/Color/hslaToRgba.d.ts +0 -1
- package/module/es5/Color/hslaToRgba.js +7 -22
- package/module/es5/Color/rgbaToCmyk.js +0 -4
- package/module/es5/Color/rgbaToHexA.js +2 -6
- package/module/es5/Color/rgbaToHsla.d.ts +0 -1
- package/module/es5/Color/rgbaToHsla.js +0 -5
- package/module/es5/Crypto/constants.d.ts +2 -0
- package/module/es5/Crypto/constants.js +8 -0
- package/module/es5/Crypto/decodeBase32.js +2 -4
- package/module/es5/Crypto/decodeBase58.js +2 -4
- package/module/es5/Crypto/encodeBase32.js +2 -1
- package/module/es5/Crypto/encodeBase58.js +2 -1
- package/module/es5/DataStructure/index.d.ts +2 -0
- package/module/es5/DataStructure/index.js +22 -0
- package/module/es5/DataStructure/lruCache.d.ts +139 -0
- package/module/es5/DataStructure/lruCache.js +205 -0
- package/module/es5/DataStructure/ttlCache.d.ts +139 -0
- package/module/es5/DataStructure/ttlCache.js +211 -0
- package/module/es5/Error/flatMapResult.d.ts +23 -0
- package/module/es5/Error/flatMapResult.js +33 -0
- package/module/es5/Error/index.d.ts +3 -0
- package/module/es5/Error/index.js +33 -0
- package/module/es5/Error/mapResult.d.ts +21 -0
- package/module/es5/Error/mapResult.js +32 -0
- package/module/es5/Error/matchResult.d.ts +25 -0
- package/module/es5/Error/matchResult.js +32 -0
- package/module/es5/Error/safeExecute.d.ts +16 -3
- package/module/es5/Error/safeExecute.js +3 -3
- package/module/es5/Function/debounce.d.ts +38 -0
- package/module/es5/Function/debounce.js +88 -0
- package/module/es5/Function/index.d.ts +4 -0
- package/module/es5/Function/index.js +44 -0
- package/module/es5/Function/memoize.d.ts +36 -0
- package/module/es5/Function/memoize.js +73 -0
- package/module/es5/Function/once.d.ts +18 -0
- package/module/es5/Function/once.js +37 -0
- package/module/es5/Function/throttle.d.ts +25 -0
- package/module/es5/Function/throttle.js +69 -0
- package/module/es5/IP/cidrToLong.d.ts +0 -1
- package/module/es5/IP/cidrToLong.js +0 -4
- package/module/es5/IP/cidrToSubnetMask.d.ts +0 -1
- package/module/es5/IP/cidrToSubnetMask.js +0 -1
- package/module/es5/IP/getNetworkAddress.d.ts +0 -1
- package/module/es5/IP/getNetworkAddress.js +2 -31
- package/module/es5/IP/ipToBinaryString.d.ts +0 -1
- package/module/es5/IP/ipToBinaryString.js +1 -40
- package/module/es5/IP/ipToLong.d.ts +0 -1
- package/module/es5/IP/ipToLong.js +0 -1
- package/module/es5/IP/isInRange.d.ts +0 -1
- package/module/es5/IP/isInRange.js +5 -29
- package/module/es5/IP/isPrivateIp.d.ts +0 -1
- package/module/es5/IP/isPrivateIp.js +3 -12
- package/module/es5/IP/longToIp.d.ts +0 -1
- package/module/es5/IP/longToIp.js +0 -6
- package/module/es5/IP/subnetMaskToCidr.d.ts +0 -1
- package/module/es5/IP/subnetMaskToCidr.js +2 -26
- package/module/es5/Iterator/index.d.ts +3 -0
- package/module/es5/Iterator/index.js +38 -0
- package/module/es5/Iterator/lazyFilter.d.ts +10 -0
- package/module/es5/Iterator/lazyFilter.js +63 -0
- package/module/es5/Iterator/lazyMap.d.ts +10 -0
- package/module/es5/Iterator/lazyMap.js +59 -0
- package/module/es5/Iterator/lazyTake.d.ts +10 -0
- package/module/es5/Iterator/lazyTake.js +65 -0
- package/module/es5/Math/addition.js +24 -14
- package/module/es5/Math/average.js +3 -5
- package/module/es5/Math/bitwise.js +1 -1
- package/module/es5/Math/calculator/core.js +2 -1
- package/module/es5/Math/calculator/literalExpression.js +1 -1
- package/module/es5/Math/clamp.d.ts +16 -0
- package/module/es5/Math/clamp.js +24 -0
- package/module/es5/Math/correlationCoefficient.js +0 -3
- package/module/es5/Math/inRange.d.ts +19 -0
- package/module/es5/Math/inRange.js +29 -0
- package/module/es5/Math/index.d.ts +3 -0
- package/module/es5/Math/index.js +33 -0
- package/module/es5/Math/median.js +2 -2
- package/module/es5/Math/nCr.js +2 -4
- package/module/es5/Math/percentile.js +2 -11
- package/module/es5/Math/primeFactorization.js +1 -1
- package/module/es5/Math/sumPrecise.d.ts +14 -0
- package/module/es5/Math/sumPrecise.js +41 -0
- package/module/es5/Math/uuidv7.js +25 -40
- package/module/es5/Number/formatNumber.d.ts +42 -0
- package/module/es5/Number/formatNumber.js +58 -0
- package/module/es5/Number/index.d.ts +3 -0
- package/module/es5/Number/index.js +38 -0
- package/module/es5/Number/toOrdinal.d.ts +20 -0
- package/module/es5/Number/toOrdinal.js +42 -0
- package/module/es5/Number/toPercentage.d.ts +20 -0
- package/module/es5/Number/toPercentage.js +33 -0
- package/module/es5/Object/deepClone.d.ts +15 -0
- package/module/es5/Object/deepClone.js +107 -0
- package/module/es5/Object/getObjectsCommon.d.ts +23 -0
- package/module/es5/Object/getObjectsCommon.js +92 -0
- package/module/es5/Object/getObjectsDiff.d.ts +25 -0
- package/module/es5/Object/getObjectsDiff.js +146 -0
- package/module/es5/Object/index.d.ts +6 -0
- package/module/es5/Object/index.js +66 -0
- package/module/es5/Object/isPlainObject.d.ts +16 -0
- package/module/es5/Object/isPlainObject.js +39 -0
- package/module/es5/Object/mapKeys.d.ts +15 -0
- package/module/es5/Object/mapKeys.js +33 -0
- package/module/es5/Object/mapValues.d.ts +15 -0
- package/module/es5/Object/mapValues.js +32 -0
- package/module/es5/Object/mergeDeep.js +7 -10
- package/module/es5/Object/omit.d.ts +1 -1
- package/module/es5/Object/pickDeep.js +4 -6
- package/module/es5/Predicate/every.d.ts +14 -0
- package/module/es5/Predicate/every.js +33 -0
- package/module/es5/Predicate/index.d.ts +6 -0
- package/module/es5/Predicate/index.js +71 -0
- package/module/es5/Predicate/isNotNullish.d.ts +11 -0
- package/module/es5/Predicate/isNotNullish.js +19 -0
- package/module/es5/Predicate/isNullish.d.ts +11 -0
- package/module/es5/Predicate/isNullish.js +19 -0
- package/module/es5/Predicate/matches.d.ts +11 -0
- package/module/es5/Predicate/matches.js +28 -0
- package/module/es5/Predicate/not.d.ts +10 -0
- package/module/es5/Predicate/not.js +20 -0
- package/module/es5/Predicate/some.d.ts +15 -0
- package/module/es5/Predicate/some.js +34 -0
- package/module/es5/String/camelCase.js +2 -2
- package/module/es5/String/escapeHtml.js +1 -1
- package/module/es5/String/formatString/getValue.js +1 -1
- package/module/es5/String/fromBase64.d.ts +0 -1
- package/module/es5/String/fromBase64.js +9 -8
- package/module/es5/String/fuzzySearch.js +84 -9
- package/module/es5/String/kebabCase.js +1 -1
- package/module/es5/String/levenshteinDistance.js +3 -2
- package/module/es5/String/randomString.js +24 -2
- package/module/es5/String/reverseString.js +7 -1
- package/module/es5/String/slugify.js +1 -1
- package/module/es5/String/toHalfWidth.js +2 -2
- package/module/es5/String/truncate.js +0 -3
- package/module/es5/String/unescapeHtml.js +1 -1
- package/module/es5/Time/convertTime.js +4 -3
- package/module/es5/Tool/escapeRegExp.d.ts +8 -0
- package/module/es5/Tool/escapeRegExp.js +18 -0
- package/module/es5/Tool/index.d.ts +1 -0
- package/module/es5/Tool/index.js +11 -0
- package/module/es5/URL/buildUrl.d.ts +17 -0
- package/module/es5/URL/buildUrl.js +31 -0
- package/module/es5/URL/index.d.ts +4 -0
- package/module/es5/URL/index.js +49 -0
- package/module/es5/URL/isAbsoluteUrl.d.ts +20 -0
- package/module/es5/URL/isAbsoluteUrl.js +28 -0
- package/module/es5/URL/joinPath.d.ts +24 -0
- package/module/es5/URL/joinPath.js +48 -0
- package/module/es5/URL/parseQueryString.d.ts +22 -0
- package/module/es5/URL/parseQueryString.js +57 -0
- package/module/es5/Validate/parseEmail.js +5 -5
- package/module/es5/index.d.ts +25 -20
- package/module/es5/index.js +135 -80
- package/module/es5/tsconfig.tsbuildinfo +1 -1
- package/module/index.d.ts +25 -20
- package/module/index.js +25 -20
- package/module/index.js.map +1 -1
- package/package.json +43 -17
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Least Recently Used (LRU) cache implementation
|
|
3
|
+
* using a Map for O(1) get/set operations.
|
|
4
|
+
*
|
|
5
|
+
* When the cache exceeds its capacity, the least recently used
|
|
6
|
+
* entry is evicted.
|
|
7
|
+
*
|
|
8
|
+
* ## Features
|
|
9
|
+
* - **get(key)**: Retrieve a value (moves it to most recently used)
|
|
10
|
+
* - **set(key, value)**: Insert or update a value
|
|
11
|
+
* - **has(key)**: Check if a key exists
|
|
12
|
+
* - **delete(key)**: Remove a specific entry
|
|
13
|
+
* - **clear()**: Remove all entries
|
|
14
|
+
* - **size**: Get the number of entries
|
|
15
|
+
*
|
|
16
|
+
* ## Time Complexity
|
|
17
|
+
* - get: O(1)
|
|
18
|
+
* - set: O(1)
|
|
19
|
+
* - has: O(1)
|
|
20
|
+
* - delete: O(1)
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const cache = new LRUCache<string, number>(3);
|
|
25
|
+
* cache.set("a", 1);
|
|
26
|
+
* cache.set("b", 2);
|
|
27
|
+
* cache.set("c", 3);
|
|
28
|
+
*
|
|
29
|
+
* cache.get("a"); // 1 (moves "a" to most recently used)
|
|
30
|
+
* cache.set("d", 4); // evicts "b" (least recently used)
|
|
31
|
+
*
|
|
32
|
+
* cache.has("b"); // false
|
|
33
|
+
* cache.get("a"); // 1
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @template K - The type of cache keys
|
|
37
|
+
* @template V - The type of cache values
|
|
38
|
+
*/
|
|
39
|
+
export class LRUCache {
|
|
40
|
+
capacity;
|
|
41
|
+
map = new Map();
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new LRUCache instance.
|
|
44
|
+
* @param capacity - The maximum number of entries the cache can hold
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const cache = new LRUCache<string, number>(100);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
constructor(capacity) {
|
|
52
|
+
this.capacity = capacity;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns the number of entries in the cache.
|
|
56
|
+
* @returns The current number of cached entries
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const cache = new LRUCache<string, number>(10);
|
|
61
|
+
* cache.set("a", 1);
|
|
62
|
+
* console.log(cache.size); // 1
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
get size() {
|
|
66
|
+
return this.map.size;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves a value by key and marks it as most recently used.
|
|
70
|
+
* @param key - The key to look up
|
|
71
|
+
* @returns The value if found, or undefined if not in cache
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const cache = new LRUCache<string, number>(10);
|
|
76
|
+
* cache.set("a", 1);
|
|
77
|
+
* cache.get("a"); // 1
|
|
78
|
+
* cache.get("b"); // undefined
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
get(key) {
|
|
82
|
+
const value = this.map.get(key);
|
|
83
|
+
if (value === undefined && !this.map.has(key)) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
// Refresh key: delete and re-insert
|
|
87
|
+
this.map.delete(key);
|
|
88
|
+
this.map.set(key, value);
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Inserts or updates a key-value pair.
|
|
93
|
+
* If the cache is at capacity, the least recently used entry is evicted.
|
|
94
|
+
* @param key - The key to set
|
|
95
|
+
* @param value - The value to associate with the key
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const cache = new LRUCache<string, number>(2);
|
|
100
|
+
* cache.set("a", 1);
|
|
101
|
+
* cache.set("b", 2);
|
|
102
|
+
* cache.set("c", 3); // evicts "a"
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
set(key, value) {
|
|
106
|
+
if (this.map.has(key)) {
|
|
107
|
+
this.map.delete(key);
|
|
108
|
+
}
|
|
109
|
+
else if (this.map.size >= this.capacity) {
|
|
110
|
+
this.evict();
|
|
111
|
+
}
|
|
112
|
+
this.map.set(key, value);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Checks whether a key exists in the cache.
|
|
116
|
+
* Does not affect the recently-used order.
|
|
117
|
+
* @param key - The key to check
|
|
118
|
+
* @returns True if the key exists in the cache
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const cache = new LRUCache<string, number>(10);
|
|
123
|
+
* cache.set("a", 1);
|
|
124
|
+
* cache.has("a"); // true
|
|
125
|
+
* cache.has("b"); // false
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
has(key) {
|
|
129
|
+
return this.map.has(key);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Removes an entry from the cache by key.
|
|
133
|
+
* @param key - The key to remove
|
|
134
|
+
* @returns True if the entry was found and removed
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const cache = new LRUCache<string, number>(10);
|
|
139
|
+
* cache.set("a", 1);
|
|
140
|
+
* cache.delete("a"); // true
|
|
141
|
+
* cache.delete("b"); // false
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
delete(key) {
|
|
145
|
+
return this.map.delete(key);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Removes all entries from the cache.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const cache = new LRUCache<string, number>(10);
|
|
153
|
+
* cache.set("a", 1);
|
|
154
|
+
* cache.set("b", 2);
|
|
155
|
+
* cache.clear();
|
|
156
|
+
* console.log(cache.size); // 0
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
clear() {
|
|
160
|
+
this.map.clear();
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Evicts the least recently used entry (first inserted).
|
|
164
|
+
*/
|
|
165
|
+
evict() {
|
|
166
|
+
const iterator = this.map.keys().next();
|
|
167
|
+
if (!iterator.done) {
|
|
168
|
+
this.map.delete(iterator.value);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=lruCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lruCache.js","sourceRoot":"","sources":["../../src/DataStructure/lruCache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,OAAO,QAAQ;IACX,QAAQ,CAAS;IACjB,GAAG,GAAG,IAAI,GAAG,EAAQ,CAAC;IAE9B;;;;;;;;OAQG;IACH,YAAY,QAAgB;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;;;;;;OAUG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,GAAM;QACR,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9C,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,oCAAoC;QACpC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAU,CAAC,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAC,GAAM,EAAE,KAAQ;QAClB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;aAAM,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1C,IAAI,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAC,GAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,GAAM;QACX,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;IAED;;OAEG;IACK,KAAK;QACX,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;QACxC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for TTLCache.
|
|
3
|
+
*/
|
|
4
|
+
export interface TTLCacheOptions {
|
|
5
|
+
/** Default time-to-live in milliseconds for cache entries */
|
|
6
|
+
defaultTTL: number;
|
|
7
|
+
/** Optional maximum number of entries */
|
|
8
|
+
maxSize?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A time-to-live (TTL) cache that automatically expires entries
|
|
12
|
+
* after a configured duration.
|
|
13
|
+
*
|
|
14
|
+
* Uses lazy deletion: expired entries are only removed
|
|
15
|
+
* when accessed via get() or has().
|
|
16
|
+
*
|
|
17
|
+
* ## Features
|
|
18
|
+
* - **get(key)**: Retrieve a value (returns undefined if expired)
|
|
19
|
+
* - **set(key, value, ttl?)**: Insert with optional per-entry TTL
|
|
20
|
+
* - **has(key)**: Check if a non-expired key exists
|
|
21
|
+
* - **delete(key)**: Remove a specific entry
|
|
22
|
+
* - **clear()**: Remove all entries
|
|
23
|
+
* - **size**: Get the number of entries (including expired)
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
28
|
+
* cache.set("a", 1);
|
|
29
|
+
* cache.get("a"); // 1
|
|
30
|
+
*
|
|
31
|
+
* // After 5 seconds...
|
|
32
|
+
* cache.get("a"); // undefined (expired)
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @template K - The type of cache keys
|
|
36
|
+
* @template V - The type of cache values
|
|
37
|
+
*/
|
|
38
|
+
export declare class TTLCache<K, V> {
|
|
39
|
+
private defaultTTL;
|
|
40
|
+
private maxSize;
|
|
41
|
+
private map;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new TTLCache instance.
|
|
44
|
+
* @param options - Configuration options for the cache
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const cache = new TTLCache<string, number>({
|
|
49
|
+
* defaultTTL: 60000,
|
|
50
|
+
* maxSize: 1000,
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
constructor(options: TTLCacheOptions);
|
|
55
|
+
/**
|
|
56
|
+
* Returns the number of entries in the cache
|
|
57
|
+
* (including potentially expired entries).
|
|
58
|
+
* @returns The current number of entries
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
63
|
+
* cache.set("a", 1);
|
|
64
|
+
* console.log(cache.size); // 1
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
get size(): number;
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves a value by key. Returns undefined if the key
|
|
70
|
+
* does not exist or has expired.
|
|
71
|
+
* @param key - The key to look up
|
|
72
|
+
* @returns The value if found and not expired, or undefined
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
77
|
+
* cache.set("a", 1);
|
|
78
|
+
* cache.get("a"); // 1
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
get(key: K): V | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Inserts or updates a key-value pair with an optional TTL override.
|
|
84
|
+
* If maxSize is configured and the cache is full, the oldest entry
|
|
85
|
+
* is removed.
|
|
86
|
+
* @param key - The key to set
|
|
87
|
+
* @param value - The value to cache
|
|
88
|
+
* @param ttl - Optional TTL in milliseconds (overrides defaultTTL)
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
93
|
+
* cache.set("a", 1);
|
|
94
|
+
* cache.set("b", 2, 10000); // custom 10s TTL
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
set(key: K, value: V, ttl?: number): void;
|
|
98
|
+
/**
|
|
99
|
+
* Checks whether a non-expired key exists in the cache.
|
|
100
|
+
* Removes the entry if it has expired.
|
|
101
|
+
* @param key - The key to check
|
|
102
|
+
* @returns True if the key exists and has not expired
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
107
|
+
* cache.set("a", 1);
|
|
108
|
+
* cache.has("a"); // true
|
|
109
|
+
* cache.has("b"); // false
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
has(key: K): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Removes an entry from the cache by key.
|
|
115
|
+
* @param key - The key to remove
|
|
116
|
+
* @returns True if the entry was found and removed
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
121
|
+
* cache.set("a", 1);
|
|
122
|
+
* cache.delete("a"); // true
|
|
123
|
+
* cache.delete("b"); // false
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
delete(key: K): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Removes all entries from the cache.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
133
|
+
* cache.set("a", 1);
|
|
134
|
+
* cache.clear();
|
|
135
|
+
* console.log(cache.size); // 0
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
clear(): void;
|
|
139
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A time-to-live (TTL) cache that automatically expires entries
|
|
3
|
+
* after a configured duration.
|
|
4
|
+
*
|
|
5
|
+
* Uses lazy deletion: expired entries are only removed
|
|
6
|
+
* when accessed via get() or has().
|
|
7
|
+
*
|
|
8
|
+
* ## Features
|
|
9
|
+
* - **get(key)**: Retrieve a value (returns undefined if expired)
|
|
10
|
+
* - **set(key, value, ttl?)**: Insert with optional per-entry TTL
|
|
11
|
+
* - **has(key)**: Check if a non-expired key exists
|
|
12
|
+
* - **delete(key)**: Remove a specific entry
|
|
13
|
+
* - **clear()**: Remove all entries
|
|
14
|
+
* - **size**: Get the number of entries (including expired)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
19
|
+
* cache.set("a", 1);
|
|
20
|
+
* cache.get("a"); // 1
|
|
21
|
+
*
|
|
22
|
+
* // After 5 seconds...
|
|
23
|
+
* cache.get("a"); // undefined (expired)
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @template K - The type of cache keys
|
|
27
|
+
* @template V - The type of cache values
|
|
28
|
+
*/
|
|
29
|
+
export class TTLCache {
|
|
30
|
+
defaultTTL;
|
|
31
|
+
maxSize;
|
|
32
|
+
map = new Map();
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new TTLCache instance.
|
|
35
|
+
* @param options - Configuration options for the cache
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const cache = new TTLCache<string, number>({
|
|
40
|
+
* defaultTTL: 60000,
|
|
41
|
+
* maxSize: 1000,
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
constructor(options) {
|
|
46
|
+
this.defaultTTL = options.defaultTTL;
|
|
47
|
+
this.maxSize = options.maxSize;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns the number of entries in the cache
|
|
51
|
+
* (including potentially expired entries).
|
|
52
|
+
* @returns The current number of entries
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
57
|
+
* cache.set("a", 1);
|
|
58
|
+
* console.log(cache.size); // 1
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
get size() {
|
|
62
|
+
return this.map.size;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Retrieves a value by key. Returns undefined if the key
|
|
66
|
+
* does not exist or has expired.
|
|
67
|
+
* @param key - The key to look up
|
|
68
|
+
* @returns The value if found and not expired, or undefined
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
73
|
+
* cache.set("a", 1);
|
|
74
|
+
* cache.get("a"); // 1
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
get(key) {
|
|
78
|
+
const entry = this.map.get(key);
|
|
79
|
+
if (entry === undefined) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (Date.now() >= entry.expiresAt) {
|
|
83
|
+
this.map.delete(key);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
return entry.value;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Inserts or updates a key-value pair with an optional TTL override.
|
|
90
|
+
* If maxSize is configured and the cache is full, the oldest entry
|
|
91
|
+
* is removed.
|
|
92
|
+
* @param key - The key to set
|
|
93
|
+
* @param value - The value to cache
|
|
94
|
+
* @param ttl - Optional TTL in milliseconds (overrides defaultTTL)
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
99
|
+
* cache.set("a", 1);
|
|
100
|
+
* cache.set("b", 2, 10000); // custom 10s TTL
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
set(key, value, ttl) {
|
|
104
|
+
const effectiveTTL = ttl ?? this.defaultTTL;
|
|
105
|
+
const expiresAt = Date.now() + effectiveTTL;
|
|
106
|
+
if (this.map.has(key)) {
|
|
107
|
+
this.map.set(key, { value, expiresAt });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (this.maxSize !== undefined && this.map.size >= this.maxSize) {
|
|
111
|
+
const firstKey = this.map.keys().next().value;
|
|
112
|
+
this.map.delete(firstKey);
|
|
113
|
+
}
|
|
114
|
+
this.map.set(key, { value, expiresAt });
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Checks whether a non-expired key exists in the cache.
|
|
118
|
+
* Removes the entry if it has expired.
|
|
119
|
+
* @param key - The key to check
|
|
120
|
+
* @returns True if the key exists and has not expired
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
125
|
+
* cache.set("a", 1);
|
|
126
|
+
* cache.has("a"); // true
|
|
127
|
+
* cache.has("b"); // false
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
has(key) {
|
|
131
|
+
const entry = this.map.get(key);
|
|
132
|
+
if (entry === undefined) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if (Date.now() >= entry.expiresAt) {
|
|
136
|
+
this.map.delete(key);
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Removes an entry from the cache by key.
|
|
143
|
+
* @param key - The key to remove
|
|
144
|
+
* @returns True if the entry was found and removed
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
149
|
+
* cache.set("a", 1);
|
|
150
|
+
* cache.delete("a"); // true
|
|
151
|
+
* cache.delete("b"); // false
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
delete(key) {
|
|
155
|
+
return this.map.delete(key);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Removes all entries from the cache.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const cache = new TTLCache<string, number>({ defaultTTL: 5000 });
|
|
163
|
+
* cache.set("a", 1);
|
|
164
|
+
* cache.clear();
|
|
165
|
+
* console.log(cache.size); // 0
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
clear() {
|
|
169
|
+
this.map.clear();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=ttlCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ttlCache.js","sourceRoot":"","sources":["../../src/DataStructure/ttlCache.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,QAAQ;IACX,UAAU,CAAS;IACnB,OAAO,CAAqB;IAC5B,GAAG,GAAG,IAAI,GAAG,EAAsC,CAAC;IAE5D;;;;;;;;;;;OAWG;IACH,YAAY,OAAwB;QAClC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;IAED;;;;;;;;;;;OAWG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,GAAM;QACR,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;YAClC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;QACD,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,GAAG,CAAC,GAAM,EAAE,KAAQ,EAAE,GAAY;QAChC,MAAM,YAAY,GAAG,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC;QAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,YAAY,CAAC;QAE5C,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;YACxC,OAAO;QACT,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAChE,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAU,CAAC;YACnD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5B,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAC,GAAM;QACR,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;YAClC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACrB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,GAAM;QACX,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Result } from "../Error/safeExecute";
|
|
2
|
+
/**
|
|
3
|
+
* Transforms the value inside a successful Result using a function
|
|
4
|
+
* that itself returns a Result. If the original Result is an error,
|
|
5
|
+
* it is returned unchanged.
|
|
6
|
+
*
|
|
7
|
+
* @param result - The Result to transform.
|
|
8
|
+
* @param function_ - The function to apply to the success value,
|
|
9
|
+
* which returns a new Result.
|
|
10
|
+
* @returns The Result returned by the mapping function, or the original error.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const success = { type: "success", value: 5 } as const;
|
|
15
|
+
* flatMapResult(success, (n) =>
|
|
16
|
+
* n > 0
|
|
17
|
+
* ? { type: "success", value: n * 2 }
|
|
18
|
+
* : { type: "error", error: new Error("negative") }
|
|
19
|
+
* );
|
|
20
|
+
* // { type: "success", value: 10 }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const flatMapResult: <V, E, U, F>(result: Result<V, E>, function_: (value: V) => Result<U, F>) => Result<U, E | F>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transforms the value inside a successful Result using a function
|
|
3
|
+
* that itself returns a Result. If the original Result is an error,
|
|
4
|
+
* it is returned unchanged.
|
|
5
|
+
*
|
|
6
|
+
* @param result - The Result to transform.
|
|
7
|
+
* @param function_ - The function to apply to the success value,
|
|
8
|
+
* which returns a new Result.
|
|
9
|
+
* @returns The Result returned by the mapping function, or the original error.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const success = { type: "success", value: 5 } as const;
|
|
14
|
+
* flatMapResult(success, (n) =>
|
|
15
|
+
* n > 0
|
|
16
|
+
* ? { type: "success", value: n * 2 }
|
|
17
|
+
* : { type: "error", error: new Error("negative") }
|
|
18
|
+
* );
|
|
19
|
+
* // { type: "success", value: 10 }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const flatMapResult = (result, function_) => {
|
|
23
|
+
if (result.type === "success") {
|
|
24
|
+
return function_(result.value);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=flatMapResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatMapResult.js","sourceRoot":"","sources":["../../src/Error/flatMapResult.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,MAAoB,EACpB,SAAqC,EACnB,EAAE;IACpB,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
package/module/Error/index.d.ts
CHANGED
package/module/Error/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Error/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Error/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Result } from "../Error/safeExecute";
|
|
2
|
+
/**
|
|
3
|
+
* Transforms the value inside a successful Result using the provided
|
|
4
|
+
* mapping function. If the Result is an error, it is returned unchanged.
|
|
5
|
+
*
|
|
6
|
+
* @param result - The Result to transform.
|
|
7
|
+
* @param function_ - The function to apply to the success value.
|
|
8
|
+
* @returns A new Result with the transformed value, or the original error.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const success = { type: "success", value: 5 } as const;
|
|
13
|
+
* mapResult(success, (n) => n * 2);
|
|
14
|
+
* // { type: "success", value: 10 }
|
|
15
|
+
*
|
|
16
|
+
* const error = { type: "error", error: new Error("fail") } as const;
|
|
17
|
+
* mapResult(error, (n) => n * 2);
|
|
18
|
+
* // { type: "error", error: Error("fail") }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const mapResult: <V, E, U>(result: Result<V, E>, function_: (value: V) => U) => Result<U, E>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { successFunction } from "../Error/safeExecute";
|
|
2
|
+
/**
|
|
3
|
+
* Transforms the value inside a successful Result using the provided
|
|
4
|
+
* mapping function. If the Result is an error, it is returned unchanged.
|
|
5
|
+
*
|
|
6
|
+
* @param result - The Result to transform.
|
|
7
|
+
* @param function_ - The function to apply to the success value.
|
|
8
|
+
* @returns A new Result with the transformed value, or the original error.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const success = { type: "success", value: 5 } as const;
|
|
13
|
+
* mapResult(success, (n) => n * 2);
|
|
14
|
+
* // { type: "success", value: 10 }
|
|
15
|
+
*
|
|
16
|
+
* const error = { type: "error", error: new Error("fail") } as const;
|
|
17
|
+
* mapResult(error, (n) => n * 2);
|
|
18
|
+
* // { type: "error", error: Error("fail") }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const mapResult = (result, function_) => {
|
|
22
|
+
if (result.type === "success") {
|
|
23
|
+
return successFunction(function_(result.value));
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=mapResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapResult.js","sourceRoot":"","sources":["../../src/Error/mapResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEnE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,MAAoB,EACpB,SAA0B,EACZ,EAAE;IAChB,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,eAAe,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Result } from "../Error/safeExecute";
|
|
2
|
+
/**
|
|
3
|
+
* Pattern-matches on a Result, applying the appropriate handler
|
|
4
|
+
* depending on whether the Result is a success or an error.
|
|
5
|
+
*
|
|
6
|
+
* @param result - The Result to match on.
|
|
7
|
+
* @param handlers - An object with onSuccess and onError callbacks.
|
|
8
|
+
* @param handlers.onSuccess - Called with the value if the Result is a success.
|
|
9
|
+
* @param handlers.onError - Called with the error if the Result is an error.
|
|
10
|
+
* @returns The return value of whichever handler is invoked.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const result = { type: "success", value: 42 } as const;
|
|
15
|
+
* matchResult(result, {
|
|
16
|
+
* onSuccess: (v) => `Got ${v}`,
|
|
17
|
+
* onError: (e) => `Failed: ${e}`,
|
|
18
|
+
* });
|
|
19
|
+
* // "Got 42"
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const matchResult: <V, E, S, F>(result: Result<V, E>, handlers: {
|
|
23
|
+
onSuccess: (value: V) => S;
|
|
24
|
+
onError: (error: E) => F;
|
|
25
|
+
}) => S | F;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern-matches on a Result, applying the appropriate handler
|
|
3
|
+
* depending on whether the Result is a success or an error.
|
|
4
|
+
*
|
|
5
|
+
* @param result - The Result to match on.
|
|
6
|
+
* @param handlers - An object with onSuccess and onError callbacks.
|
|
7
|
+
* @param handlers.onSuccess - Called with the value if the Result is a success.
|
|
8
|
+
* @param handlers.onError - Called with the error if the Result is an error.
|
|
9
|
+
* @returns The return value of whichever handler is invoked.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const result = { type: "success", value: 42 } as const;
|
|
14
|
+
* matchResult(result, {
|
|
15
|
+
* onSuccess: (v) => `Got ${v}`,
|
|
16
|
+
* onError: (e) => `Failed: ${e}`,
|
|
17
|
+
* });
|
|
18
|
+
* // "Got 42"
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const matchResult = (result, handlers) => {
|
|
22
|
+
if (result.type === "success") {
|
|
23
|
+
return handlers.onSuccess(result.value);
|
|
24
|
+
}
|
|
25
|
+
return handlers.onError(result.error);
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=matchResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchResult.js","sourceRoot":"","sources":["../../src/Error/matchResult.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,MAAoB,EACpB,QAGC,EACM,EAAE;IACT,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC,CAAC"}
|