umt 2.5.0 → 2.7.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 +36 -0
- package/module/Array/generateNumberArray.js +13 -7
- package/module/Array/generateNumberArray.js.map +1 -1
- package/module/Array/getArraysCommon.js +21 -3
- package/module/Array/getArraysCommon.js.map +1 -1
- package/module/Array/groupBy.js +1 -1
- package/module/Array/groupBy.js.map +1 -1
- package/module/Array/index.d.ts +2 -0
- package/module/Array/index.js +2 -0
- package/module/Array/index.js.map +1 -1
- package/module/Array/ultraNumberSort.js +2 -2
- package/module/Array/ultraNumberSort.js.map +1 -1
- package/module/Array/uniqBy.d.ts +7 -0
- package/module/Array/uniqBy.js +19 -0
- package/module/Array/uniqBy.js.map +1 -0
- package/module/Array/unique.d.ts +6 -0
- package/module/Array/unique.js +9 -0
- package/module/Array/unique.js.map +1 -0
- package/module/Color/rgbaToHsla.js +1 -1
- package/module/Color/rgbaToHsla.js.map +1 -1
- package/module/Crypto/decodeBase32.d.ts +7 -0
- package/module/Crypto/decodeBase32.js +27 -0
- package/module/Crypto/decodeBase32.js.map +1 -0
- package/module/Crypto/decodeBase32ToString.d.ts +7 -0
- package/module/Crypto/decodeBase32ToString.js +11 -0
- package/module/Crypto/decodeBase32ToString.js.map +1 -0
- package/module/Crypto/decodeBase58.d.ts +7 -0
- package/module/Crypto/decodeBase58.js +34 -0
- package/module/Crypto/decodeBase58.js.map +1 -0
- package/module/Crypto/decodeBase58ToString.d.ts +7 -0
- package/module/Crypto/decodeBase58ToString.js +11 -0
- package/module/Crypto/decodeBase58ToString.js.map +1 -0
- package/module/Crypto/encodeBase32.d.ts +7 -0
- package/module/Crypto/encodeBase32.js +28 -0
- package/module/Crypto/encodeBase32.js.map +1 -0
- package/module/Crypto/encodeBase58.d.ts +7 -0
- package/module/Crypto/encodeBase58.js +29 -0
- package/module/Crypto/encodeBase58.js.map +1 -0
- package/module/Crypto/index.d.ts +6 -0
- package/module/Crypto/index.js +7 -0
- package/module/Crypto/index.js.map +1 -0
- package/module/DataStructure/index.d.ts +1 -0
- package/module/DataStructure/index.js +2 -0
- package/module/DataStructure/index.js.map +1 -0
- package/module/DataStructure/priorityQueue.d.ts +241 -0
- package/module/DataStructure/priorityQueue.js +327 -0
- package/module/DataStructure/priorityQueue.js.map +1 -0
- package/module/Date/birthday.js +14 -6
- package/module/Date/birthday.js.map +1 -1
- package/module/Date/isLeapYear.js +3 -0
- package/module/Date/isLeapYear.js.map +1 -1
- package/module/Error/index.d.ts +1 -0
- package/module/Error/index.js +1 -0
- package/module/Error/index.js.map +1 -1
- package/module/Error/retry.d.ts +37 -0
- package/module/Error/retry.js +47 -0
- package/module/Error/retry.js.map +1 -0
- package/module/IP/getIpClass.js +1 -1
- package/module/IP/getIpClass.js.map +1 -1
- package/module/IP/getNetworkAddress.js +2 -2
- package/module/IP/getNetworkAddress.js.map +1 -1
- package/module/IP/ipToBinaryString.js +2 -2
- package/module/IP/ipToBinaryString.js.map +1 -1
- package/module/IP/subnetMaskToCidr.js +1 -1
- package/module/IP/subnetMaskToCidr.js.map +1 -1
- package/module/Math/calculator/core.js +21 -13
- package/module/Math/calculator/core.js.map +1 -1
- package/module/Math/calculator/literalExpression.js +19 -7
- package/module/Math/calculator/literalExpression.js.map +1 -1
- package/module/Math/correlationCoefficient.d.ts +11 -0
- package/module/Math/correlationCoefficient.js +40 -0
- package/module/Math/correlationCoefficient.js.map +1 -0
- package/module/Math/division.js +3 -3
- package/module/Math/division.js.map +1 -1
- package/module/Math/gcd.js +26 -4
- package/module/Math/gcd.js.map +1 -1
- 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/mode.d.ts +10 -0
- package/module/Math/mode.js +31 -0
- package/module/Math/mode.js.map +1 -0
- package/module/Math/percentile.d.ts +11 -0
- package/module/Math/percentile.js +31 -0
- package/module/Math/percentile.js.map +1 -0
- package/module/Math/standardDeviation.js +4 -2
- package/module/Math/standardDeviation.js.map +1 -1
- package/module/Object/has.js +1 -2
- package/module/Object/has.js.map +1 -1
- package/module/Object/index.d.ts +4 -0
- package/module/Object/index.js +4 -0
- package/module/Object/index.js.map +1 -1
- package/module/Object/isEmpty.d.ts +6 -0
- package/module/Object/isEmpty.js +20 -0
- package/module/Object/isEmpty.js.map +1 -0
- package/module/Object/merge.d.ts +8 -0
- package/module/Object/merge.js +10 -0
- package/module/Object/merge.js.map +1 -0
- package/module/Object/mergeDeep.d.ts +8 -0
- package/module/Object/mergeDeep.js +37 -0
- package/module/Object/mergeDeep.js.map +1 -0
- package/module/Object/omit.d.ts +7 -0
- package/module/Object/omit.js +14 -0
- package/module/Object/omit.js.map +1 -0
- package/module/Object/pickDeep.d.ts +2 -2
- package/module/Object/pickDeep.js +4 -4
- package/module/Object/pickDeep.js.map +1 -1
- package/module/Simple/Date/dayOfWeekSimple.js +3 -3
- package/module/Simple/Date/dayOfWeekSimple.js.map +1 -1
- package/module/String/camelCase.d.ts +6 -0
- package/module/String/camelCase.js +12 -0
- package/module/String/camelCase.js.map +1 -0
- package/module/String/escapeHtml.d.ts +6 -0
- package/module/String/escapeHtml.js +19 -0
- package/module/String/escapeHtml.js.map +1 -0
- package/module/String/formatString/applyFormatter.d.ts +25 -0
- package/module/String/formatString/applyFormatter.js +71 -0
- package/module/String/formatString/applyFormatter.js.map +1 -0
- package/module/String/formatString/defaultFormatters.d.ts +24 -0
- package/module/String/formatString/defaultFormatters.js +59 -0
- package/module/String/formatString/defaultFormatters.js.map +1 -0
- package/module/String/formatString/detectMode.d.ts +26 -0
- package/module/String/formatString/detectMode.js +61 -0
- package/module/String/formatString/detectMode.js.map +1 -0
- package/module/String/formatString/getValue.d.ts +27 -0
- package/module/String/formatString/getValue.js +56 -0
- package/module/String/formatString/getValue.js.map +1 -0
- package/module/String/formatString/index.d.ts +91 -0
- package/module/String/formatString/index.js +38 -0
- package/module/String/formatString/index.js.map +1 -0
- package/module/String/fuzzySearch.d.ts +14 -0
- package/module/String/fuzzySearch.js +27 -0
- package/module/String/fuzzySearch.js.map +1 -0
- package/module/String/index.d.ts +9 -0
- package/module/String/index.js +9 -0
- package/module/String/index.js.map +1 -1
- package/module/String/kebabCase.d.ts +6 -0
- package/module/String/kebabCase.js +22 -0
- package/module/String/kebabCase.js.map +1 -0
- package/module/String/levenshteinDistance.d.ts +8 -0
- package/module/String/levenshteinDistance.js +38 -0
- package/module/String/levenshteinDistance.js.map +1 -0
- package/module/String/slugify.d.ts +10 -0
- package/module/String/slugify.js +21 -0
- package/module/String/slugify.js.map +1 -0
- package/module/String/stringSimilarity.d.ts +8 -0
- package/module/String/stringSimilarity.js +23 -0
- package/module/String/stringSimilarity.js.map +1 -0
- package/module/String/truncate.d.ts +12 -0
- package/module/String/truncate.js +21 -0
- package/module/String/truncate.js.map +1 -0
- package/module/String/unescapeHtml.d.ts +17 -0
- package/module/String/unescapeHtml.js +45 -0
- package/module/String/unescapeHtml.js.map +1 -0
- package/module/Validate/core/index.js +0 -1
- package/module/Validate/core/index.js.map +1 -1
- package/module/Validate/index.d.ts +1 -0
- package/module/Validate/index.js +1 -0
- package/module/Validate/index.js.map +1 -1
- package/module/Validate/isDeepEqual.d.ts +28 -0
- package/module/Validate/isDeepEqual.js +148 -0
- package/module/Validate/isDeepEqual.js.map +1 -0
- package/module/Validate/isDouble.js +1 -1
- package/module/Validate/isDouble.js.map +1 -1
- package/module/Validate/isNode.js +1 -0
- package/module/Validate/isNode.js.map +1 -1
- package/module/Validate/isNumber.js +1 -1
- package/module/Validate/isNumber.js.map +1 -1
- package/module/Validate/isValueNaN.js +1 -1
- package/module/Validate/isValueNaN.js.map +1 -1
- package/module/Validate/number/even.js +7 -1
- package/module/Validate/number/even.js.map +1 -1
- package/module/Validate/number/odd.js +7 -1
- package/module/Validate/number/odd.js.map +1 -1
- package/module/Validate/string/email.js +20 -2
- package/module/Validate/string/email.js.map +1 -1
- package/module/es5/Array/generateNumberArray.js +15 -9
- package/module/es5/Array/getArraysCommon.js +39 -4
- package/module/es5/Array/groupBy.js +1 -1
- package/module/es5/Array/index.d.ts +2 -0
- package/module/es5/Array/index.js +22 -0
- package/module/es5/Array/ultraNumberSort.js +2 -2
- package/module/es5/Array/uniqBy.d.ts +7 -0
- package/module/es5/Array/uniqBy.js +36 -0
- package/module/es5/Array/unique.d.ts +6 -0
- package/module/es5/Array/unique.js +20 -0
- package/module/es5/Color/rgbaToHsla.js +1 -1
- package/module/es5/Crypto/decodeBase32.d.ts +7 -0
- package/module/es5/Crypto/decodeBase32.js +44 -0
- package/module/es5/Crypto/decodeBase32ToString.d.ts +7 -0
- package/module/es5/Crypto/decodeBase32ToString.js +16 -0
- package/module/es5/Crypto/decodeBase58.d.ts +7 -0
- package/module/es5/Crypto/decodeBase58.js +63 -0
- package/module/es5/Crypto/decodeBase58ToString.d.ts +7 -0
- package/module/es5/Crypto/decodeBase58ToString.js +16 -0
- package/module/es5/Crypto/encodeBase32.d.ts +7 -0
- package/module/es5/Crypto/encodeBase32.js +45 -0
- package/module/es5/Crypto/encodeBase58.d.ts +7 -0
- package/module/es5/Crypto/encodeBase58.js +55 -0
- package/module/es5/Crypto/index.d.ts +6 -0
- package/module/es5/Crypto/index.js +71 -0
- package/module/es5/DataStructure/index.d.ts +1 -0
- package/module/es5/DataStructure/index.js +16 -0
- package/module/es5/DataStructure/priorityQueue.d.ts +241 -0
- package/module/es5/DataStructure/priorityQueue.js +405 -0
- package/module/es5/Date/birthday.js +17 -3
- package/module/es5/Date/isLeapYear.js +3 -0
- package/module/es5/Error/index.d.ts +1 -0
- package/module/es5/Error/index.js +11 -0
- package/module/es5/Error/retry.d.ts +37 -0
- package/module/es5/Error/retry.js +88 -0
- package/module/es5/IP/getIpClass.js +1 -1
- package/module/es5/IP/getNetworkAddress.js +2 -2
- package/module/es5/IP/ipToBinaryString.js +2 -2
- package/module/es5/IP/subnetMaskToCidr.js +1 -1
- package/module/es5/Math/calculator/core.js +17 -9
- package/module/es5/Math/calculator/literalExpression.js +19 -6
- package/module/es5/Math/correlationCoefficient.d.ts +11 -0
- package/module/es5/Math/correlationCoefficient.js +63 -0
- package/module/es5/Math/division.js +3 -3
- package/module/es5/Math/gcd.js +43 -5
- package/module/es5/Math/index.d.ts +3 -0
- package/module/es5/Math/index.js +33 -0
- package/module/es5/Math/mode.d.ts +10 -0
- package/module/es5/Math/mode.js +67 -0
- package/module/es5/Math/percentile.d.ts +11 -0
- package/module/es5/Math/percentile.js +42 -0
- package/module/es5/Math/standardDeviation.js +4 -2
- package/module/es5/Object/has.js +1 -1
- package/module/es5/Object/index.d.ts +4 -0
- package/module/es5/Object/index.js +44 -0
- package/module/es5/Object/isEmpty.d.ts +6 -0
- package/module/es5/Object/isEmpty.js +26 -0
- package/module/es5/Object/merge.d.ts +8 -0
- package/module/es5/Object/merge.js +18 -0
- package/module/es5/Object/mergeDeep.d.ts +8 -0
- package/module/es5/Object/mergeDeep.js +46 -0
- package/module/es5/Object/omit.d.ts +7 -0
- package/module/es5/Object/omit.js +29 -0
- package/module/es5/Object/pickDeep.d.ts +2 -2
- package/module/es5/Object/pickDeep.js +4 -4
- package/module/es5/Simple/Date/dayOfWeekSimple.js +3 -3
- package/module/es5/String/camelCase.d.ts +6 -0
- package/module/es5/String/camelCase.js +18 -0
- package/module/es5/String/escapeHtml.d.ts +6 -0
- package/module/es5/String/escapeHtml.js +27 -0
- package/module/es5/String/formatString/applyFormatter.d.ts +25 -0
- package/module/es5/String/formatString/applyFormatter.js +100 -0
- package/module/es5/String/formatString/defaultFormatters.d.ts +24 -0
- package/module/es5/String/formatString/defaultFormatters.js +79 -0
- package/module/es5/String/formatString/detectMode.d.ts +26 -0
- package/module/es5/String/formatString/detectMode.js +60 -0
- package/module/es5/String/formatString/getValue.d.ts +27 -0
- package/module/es5/String/formatString/getValue.js +85 -0
- package/module/es5/String/formatString/index.d.ts +91 -0
- package/module/es5/String/formatString/index.js +152 -0
- package/module/es5/String/fuzzySearch.d.ts +14 -0
- package/module/es5/String/fuzzySearch.js +50 -0
- package/module/es5/String/index.d.ts +9 -0
- package/module/es5/String/index.js +99 -0
- package/module/es5/String/kebabCase.d.ts +6 -0
- package/module/es5/String/kebabCase.js +26 -0
- package/module/es5/String/levenshteinDistance.d.ts +8 -0
- package/module/es5/String/levenshteinDistance.js +58 -0
- package/module/es5/String/slugify.d.ts +10 -0
- package/module/es5/String/slugify.js +18 -0
- package/module/es5/String/stringSimilarity.d.ts +8 -0
- package/module/es5/String/stringSimilarity.js +30 -0
- package/module/es5/String/truncate.d.ts +12 -0
- package/module/es5/String/truncate.js +27 -0
- package/module/es5/String/unescapeHtml.d.ts +17 -0
- package/module/es5/String/unescapeHtml.js +51 -0
- package/module/es5/Validate/core/index.js +0 -1
- package/module/es5/Validate/index.d.ts +1 -0
- package/module/es5/Validate/index.js +11 -0
- package/module/es5/Validate/isDeepEqual.d.ts +28 -0
- package/module/es5/Validate/isDeepEqual.js +232 -0
- package/module/es5/Validate/isDouble.js +1 -1
- package/module/es5/Validate/isNode.js +1 -0
- package/module/es5/Validate/isNumber.js +1 -1
- package/module/es5/Validate/isValueNaN.js +1 -1
- package/module/es5/Validate/number/even.js +4 -0
- package/module/es5/Validate/number/odd.js +4 -0
- package/module/es5/Validate/string/email.js +26 -1
- package/module/es5/index.d.ts +2 -0
- package/module/es5/index.js +22 -0
- package/module/es5/tsconfig.tsbuildinfo +1 -1
- package/module/es5/types/index.d.ts +1 -0
- package/module/es5/types/index.js +11 -0
- package/module/es5/types/logic/deepPartial.d.ts +37 -0
- package/module/es5/types/logic/deepPartial.js +5 -0
- package/module/es5/types/logic/deepRequired.d.ts +37 -0
- package/module/es5/types/logic/deepRequired.js +5 -0
- package/module/es5/types/logic/index.d.ts +3 -0
- package/module/es5/types/logic/index.js +33 -0
- package/module/es5/types/logic/unionToIntersection.d.ts +12 -0
- package/module/es5/types/logic/unionToIntersection.js +5 -0
- package/module/es5/types/object/index.d.ts +1 -0
- package/module/es5/types/object/index.js +11 -0
- package/module/es5/types/object/pickDeep.d.ts +13 -1
- package/module/es5/types/object/shallowObjectValue.d.ts +9 -0
- package/module/es5/types/object/shallowObjectValue.js +5 -0
- package/module/es5/types/string/formatString/formatData.d.ts +17 -0
- package/module/es5/types/string/formatString/formatData.js +5 -0
- package/module/es5/types/string/formatString/formatOptions.d.ts +21 -0
- package/module/es5/types/string/formatString/formatOptions.js +5 -0
- package/module/es5/types/string/formatString/formatString.d.ts +4 -0
- package/module/es5/types/string/formatString/formatString.js +49 -0
- package/module/es5/types/string/formatString/formatValue.d.ts +15 -0
- package/module/es5/types/string/formatString/formatValue.js +5 -0
- package/module/es5/types/string/formatString/formatter.d.ts +13 -0
- package/module/es5/types/string/formatString/formatter.js +5 -0
- package/module/es5/types/string/formatString/index.d.ts +5 -0
- package/module/es5/types/string/formatString/index.js +60 -0
- package/module/es5/types/string/index.d.ts +1 -0
- package/module/es5/types/string/index.js +16 -0
- package/module/index.d.ts +2 -0
- package/module/index.js +2 -0
- package/module/index.js.map +1 -1
- package/module/types/index.d.ts +1 -0
- package/module/types/index.js +1 -0
- package/module/types/index.js.map +1 -1
- package/module/types/logic/deepPartial.d.ts +37 -0
- package/module/types/logic/deepPartial.js +36 -0
- package/module/types/logic/deepPartial.js.map +1 -0
- package/module/types/logic/deepRequired.d.ts +37 -0
- package/module/types/logic/deepRequired.js +2 -0
- package/module/types/logic/deepRequired.js.map +1 -0
- package/module/types/logic/index.d.ts +3 -0
- package/module/types/logic/index.js +3 -0
- package/module/types/logic/index.js.map +1 -1
- package/module/types/logic/unionToIntersection.d.ts +12 -0
- package/module/types/logic/unionToIntersection.js +2 -0
- package/module/types/logic/unionToIntersection.js.map +1 -0
- package/module/types/object/index.d.ts +1 -0
- package/module/types/object/index.js +1 -0
- package/module/types/object/index.js.map +1 -1
- package/module/types/object/pickDeep.d.ts +13 -1
- package/module/types/object/shallowObjectValue.d.ts +9 -0
- package/module/types/object/shallowObjectValue.js +2 -0
- package/module/types/object/shallowObjectValue.js.map +1 -0
- package/module/types/string/formatString/formatData.d.ts +17 -0
- package/module/types/string/formatString/formatData.js +2 -0
- package/module/types/string/formatString/formatData.js.map +1 -0
- package/module/types/string/formatString/formatOptions.d.ts +21 -0
- package/module/types/string/formatString/formatOptions.js +2 -0
- package/module/types/string/formatString/formatOptions.js.map +1 -0
- package/module/types/string/formatString/formatString.d.ts +4 -0
- package/module/types/string/formatString/formatString.js +5 -0
- package/module/types/string/formatString/formatString.js.map +1 -0
- package/module/types/string/formatString/formatValue.d.ts +15 -0
- package/module/types/string/formatString/formatValue.js +2 -0
- package/module/types/string/formatString/formatValue.js.map +1 -0
- package/module/types/string/formatString/formatter.d.ts +13 -0
- package/module/types/string/formatString/formatter.js +2 -0
- package/module/types/string/formatString/formatter.js.map +1 -0
- package/module/types/string/formatString/index.d.ts +5 -0
- package/module/types/string/formatString/index.js +6 -0
- package/module/types/string/formatString/index.js.map +1 -0
- package/module/types/string/index.d.ts +1 -0
- package/module/types/string/index.js +2 -0
- package/module/types/string/index.js.map +1 -0
- package/package.json +40 -41
- package/module/String/formatString.d.ts +0 -13
- package/module/String/formatString.js +0 -18
- package/module/String/formatString.js.map +0 -1
- package/module/es5/String/formatString.d.ts +0 -13
- package/module/es5/String/formatString.js +0 -26
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultFormatters.js","sourceRoot":"","sources":["../../../src/String/formatString/defaultFormatters.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA8B;IAC1D,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE;IAC7C,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE;IAE7C,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,QAAQ,GAAG,KAAK,EAAE,EAAE;QACtD,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;YACnC,KAAK,EAAE,UAAU;YACjB,QAAQ;SACT,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,EAAE,EAAE;QAClD,MAAM,IAAI,GAAG,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACrE,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;QAC5B,CAAC;QACD,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,EAAE;QAChC,MAAM,IAAI,GAAG,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,MAAM,EAAE,CACN,KAAK,EACL,MAAM,GAAG,OAAO,EAChB,qBAAqB,GAAG,GAAG,EAC3B,qBAAqB,GAAG,IAAI,EAC5B,EAAE;QACF,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;YACnC,qBAAqB,EAAE,MAAM,CAAC,qBAAqB,CAAC;YACpD,qBAAqB,EAAE,MAAM,CAAC,qBAAqB,CAAC;SACrD,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE;QAClC,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;IACjD,CAAC;IAED,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,GAAG,GAAG,EAAE,EAAE;QACvC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FormatData } from "../../types/string/formatString/formatData";
|
|
2
|
+
import type { FormatOptions } from "../../types/string/formatString/formatOptions";
|
|
3
|
+
import type { FormatValue } from "../../types/string/formatString/formatValue";
|
|
4
|
+
/**
|
|
5
|
+
* Detects whether formatString should use indexed or named mode based on arguments.
|
|
6
|
+
*
|
|
7
|
+
* Named mode: First argument is a non-array object
|
|
8
|
+
* Indexed mode: Arguments are treated as array values
|
|
9
|
+
*
|
|
10
|
+
* @param dataOrFirstValue - First argument (object for named mode, value for indexed mode)
|
|
11
|
+
* @param optionsOrSecondValue - Second argument (options for named mode, value for indexed mode)
|
|
12
|
+
* @param restValues - Remaining arguments for indexed mode
|
|
13
|
+
* @returns Object containing data and options for formatting
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Named mode detection
|
|
17
|
+
* detectMode({ name: "Alice" }) // → { data: { name: "Alice" }, options: {} }
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Indexed mode detection
|
|
21
|
+
* detectMode("first", "second") // → { data: ["first", "second"], options: {} }
|
|
22
|
+
*/
|
|
23
|
+
export declare function detectMode(dataOrFirstValue: FormatData | FormatValue | undefined, optionsOrSecondValue: FormatOptions | FormatValue | undefined, restValues: FormatValue[]): {
|
|
24
|
+
data: unknown;
|
|
25
|
+
options: FormatOptions;
|
|
26
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects whether formatString should use indexed or named mode based on arguments.
|
|
3
|
+
*
|
|
4
|
+
* Named mode: First argument is a non-array object
|
|
5
|
+
* Indexed mode: Arguments are treated as array values
|
|
6
|
+
*
|
|
7
|
+
* @param dataOrFirstValue - First argument (object for named mode, value for indexed mode)
|
|
8
|
+
* @param optionsOrSecondValue - Second argument (options for named mode, value for indexed mode)
|
|
9
|
+
* @param restValues - Remaining arguments for indexed mode
|
|
10
|
+
* @returns Object containing data and options for formatting
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Named mode detection
|
|
14
|
+
* detectMode({ name: "Alice" }) // → { data: { name: "Alice" }, options: {} }
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Indexed mode detection
|
|
18
|
+
* detectMode("first", "second") // → { data: ["first", "second"], options: {} }
|
|
19
|
+
*/
|
|
20
|
+
export function detectMode(dataOrFirstValue, optionsOrSecondValue, restValues) {
|
|
21
|
+
const isFirstArgumentObject = dataOrFirstValue !== undefined &&
|
|
22
|
+
typeof dataOrFirstValue === "object" &&
|
|
23
|
+
dataOrFirstValue !== null &&
|
|
24
|
+
!Array.isArray(dataOrFirstValue) &&
|
|
25
|
+
!(dataOrFirstValue instanceof Date);
|
|
26
|
+
const isSecondArgumentOptions = optionsOrSecondValue !== undefined &&
|
|
27
|
+
typeof optionsOrSecondValue === "object" &&
|
|
28
|
+
optionsOrSecondValue !== null &&
|
|
29
|
+
!Array.isArray(optionsOrSecondValue) &&
|
|
30
|
+
!(optionsOrSecondValue instanceof Date) &&
|
|
31
|
+
"formatters" in optionsOrSecondValue;
|
|
32
|
+
if (isFirstArgumentObject &&
|
|
33
|
+
optionsOrSecondValue === undefined &&
|
|
34
|
+
restValues.length === 0) {
|
|
35
|
+
return {
|
|
36
|
+
data: dataOrFirstValue,
|
|
37
|
+
options: {},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (isFirstArgumentObject &&
|
|
41
|
+
isSecondArgumentOptions &&
|
|
42
|
+
restValues.length === 0) {
|
|
43
|
+
return {
|
|
44
|
+
data: dataOrFirstValue,
|
|
45
|
+
options: optionsOrSecondValue,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const allValues = [];
|
|
49
|
+
if (dataOrFirstValue !== undefined) {
|
|
50
|
+
allValues.push(dataOrFirstValue);
|
|
51
|
+
}
|
|
52
|
+
if (optionsOrSecondValue !== undefined) {
|
|
53
|
+
allValues.push(optionsOrSecondValue);
|
|
54
|
+
}
|
|
55
|
+
allValues.push(...restValues);
|
|
56
|
+
return {
|
|
57
|
+
data: allValues,
|
|
58
|
+
options: {},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=detectMode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectMode.js","sourceRoot":"","sources":["../../../src/String/formatString/detectMode.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,UAAU,CACxB,gBAAsD,EACtD,oBAA6D,EAC7D,UAAyB;IAKzB,MAAM,qBAAqB,GACzB,gBAAgB,KAAK,SAAS;QAC9B,OAAO,gBAAgB,KAAK,QAAQ;QACpC,gBAAgB,KAAK,IAAI;QACzB,CAAC,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC;QAChC,CAAC,CAAC,gBAAgB,YAAY,IAAI,CAAC,CAAC;IAEtC,MAAM,uBAAuB,GAC3B,oBAAoB,KAAK,SAAS;QAClC,OAAO,oBAAoB,KAAK,QAAQ;QACxC,oBAAoB,KAAK,IAAI;QAC7B,CAAC,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC;QACpC,CAAC,CAAC,oBAAoB,YAAY,IAAI,CAAC;QACvC,YAAY,IAAI,oBAAoB,CAAC;IAEvC,IACE,qBAAqB;QACrB,oBAAoB,KAAK,SAAS;QAClC,UAAU,CAAC,MAAM,KAAK,CAAC,EACvB,CAAC;QACD,OAAO;YACL,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,EAAE;SACZ,CAAC;IACJ,CAAC;IAED,IACE,qBAAqB;QACrB,uBAAuB;QACvB,UAAU,CAAC,MAAM,KAAK,CAAC,EACvB,CAAC;QACD,OAAO;YACL,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,oBAAoB;SAC9B,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAc,EAAE,CAAC;IAChC,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;QACnC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACnC,CAAC;IACD,IAAI,oBAAoB,KAAK,SAAS,EAAE,CAAC;QACvC,SAAS,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACvC,CAAC;IACD,SAAS,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;IAE9B,OAAO;QACL,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,EAAE;KACZ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves a value from an object using a dot-notation path with array index support.
|
|
3
|
+
*
|
|
4
|
+
* Supports nested properties and array access with positive/negative indices.
|
|
5
|
+
*
|
|
6
|
+
* @param object - The object to retrieve the value from
|
|
7
|
+
* @param path - Dot-notation path (e.g., "user.name", "items[0]", "data[0].items[-1].name")
|
|
8
|
+
* @returns The value at the specified path, or undefined if not found
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Simple property access
|
|
12
|
+
* getValue({ name: "Alice" }, "name") // → "Alice"
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Nested property access
|
|
16
|
+
* getValue({ user: { name: "Bob" } }, "user.name") // → "Bob"
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Array access
|
|
20
|
+
* getValue({ items: ["A", "B", "C"] }, "items[0]") // → "A"
|
|
21
|
+
* getValue({ items: ["A", "B", "C"] }, "items[-1]") // → "C"
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Complex nested access
|
|
25
|
+
* getValue({ users: [{ name: "Alice" }] }, "users[0].name") // → "Alice"
|
|
26
|
+
*/
|
|
27
|
+
export declare function getValue(object: unknown, path: string): unknown;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves a value from an object using a dot-notation path with array index support.
|
|
3
|
+
*
|
|
4
|
+
* Supports nested properties and array access with positive/negative indices.
|
|
5
|
+
*
|
|
6
|
+
* @param object - The object to retrieve the value from
|
|
7
|
+
* @param path - Dot-notation path (e.g., "user.name", "items[0]", "data[0].items[-1].name")
|
|
8
|
+
* @returns The value at the specified path, or undefined if not found
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Simple property access
|
|
12
|
+
* getValue({ name: "Alice" }, "name") // → "Alice"
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Nested property access
|
|
16
|
+
* getValue({ user: { name: "Bob" } }, "user.name") // → "Bob"
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Array access
|
|
20
|
+
* getValue({ items: ["A", "B", "C"] }, "items[0]") // → "A"
|
|
21
|
+
* getValue({ items: ["A", "B", "C"] }, "items[-1]") // → "C"
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Complex nested access
|
|
25
|
+
* getValue({ users: [{ name: "Alice" }] }, "users[0].name") // → "Alice"
|
|
26
|
+
*/
|
|
27
|
+
export function getValue(object, path) {
|
|
28
|
+
const segments = [];
|
|
29
|
+
const parts = path.split(".");
|
|
30
|
+
for (const part of parts) {
|
|
31
|
+
const arrayMatch = part.match(/^(.+?)\[(-?\d+)\]$/);
|
|
32
|
+
if (arrayMatch) {
|
|
33
|
+
const [, key, indexString] = arrayMatch;
|
|
34
|
+
segments.push({ key, index: Number(indexString) });
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
segments.push({ key: part });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
let current = object;
|
|
41
|
+
for (const segment of segments) {
|
|
42
|
+
if (typeof current !== "object" || current == null) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
current = current[segment.key];
|
|
46
|
+
if (segment.index !== undefined) {
|
|
47
|
+
if (!Array.isArray(current)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const index = segment.index;
|
|
51
|
+
current = index < 0 ? current[current.length + index] : current[index];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return current;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=getValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getValue.js","sourceRoot":"","sources":["../../../src/String/formatString/getValue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAe,EAAE,IAAY;IACpD,MAAM,QAAQ,GAA2C,EAAE,CAAC;IAE5D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE9B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACpD,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,GAAG,UAAU,CAAC;YACxC,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,IAAI,OAAO,GAAG,MAAM,CAAC;IAErB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACnD,OAAO;QACT,CAAC;QAED,OAAO,GAAI,OAAmC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAE5D,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC5B,OAAO;YACT,CAAC;YACD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YAC5B,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { FormatData } from "../../types/string/formatString/formatData";
|
|
2
|
+
import type { FormatOptions } from "../../types/string/formatString/formatOptions";
|
|
3
|
+
import type { FormatValue } from "../../types/string/formatString/formatValue";
|
|
4
|
+
/**
|
|
5
|
+
* Replaces placeholders in a template string with specified values.
|
|
6
|
+
*
|
|
7
|
+
* Supports two modes:
|
|
8
|
+
* 1. **Indexed mode**: Use numbered placeholders like {0}, {1}, {2}...
|
|
9
|
+
* 2. **Named mode**: Use named placeholders with an object like {name}, {age}...
|
|
10
|
+
*
|
|
11
|
+
* ## Advanced Features
|
|
12
|
+
*
|
|
13
|
+
* ### Nested Object Access
|
|
14
|
+
* Access nested properties using dot notation: `{user.name}`, `{user.address.city}`
|
|
15
|
+
*
|
|
16
|
+
* ### Array Access
|
|
17
|
+
* Access array elements with brackets: `{items[0]}`, `{users[1].name}`
|
|
18
|
+
* Supports negative indices: `{items[-1]}` (last element), `{items[-2]}` (second to last)
|
|
19
|
+
*
|
|
20
|
+
* ### Default Values
|
|
21
|
+
* Provide fallback values using pipe syntax: `{name|Unknown}`, `{age|N/A}`
|
|
22
|
+
*
|
|
23
|
+
* ### Formatters
|
|
24
|
+
* Apply formatters to values: `{name:upper}`, `{price:currency}`, `{date:date}`
|
|
25
|
+
*
|
|
26
|
+
* Built-in formatters:
|
|
27
|
+
* - `upper` - Convert to uppercase
|
|
28
|
+
* - `lower` - Convert to lowercase
|
|
29
|
+
* - `currency(locale?, currency?)` - Format as currency (e.g., `{price:currency(ja-JP,JPY)}`)
|
|
30
|
+
* - `date(locale?, format?)` - Format dates (format: short|medium|long|full|iso|time)
|
|
31
|
+
* - `time(locale?)` - Format time
|
|
32
|
+
* - `number(locale?, minFraction?, maxFraction?)` - Format numbers
|
|
33
|
+
* - `plural(singular, plural)` - Pluralization (e.g., `{count:plural(item,items)}`)
|
|
34
|
+
* - `pad(length, char?)` - Pad string/number (e.g., `{id:pad(4,0)}`)
|
|
35
|
+
*
|
|
36
|
+
* ### Escape Sequences
|
|
37
|
+
* Use double braces to escape: `{{name}}` renders as literal `{name}`
|
|
38
|
+
*
|
|
39
|
+
* @param template - Template string containing placeholders
|
|
40
|
+
* @param data - Data object for named mode OR first value for indexed mode
|
|
41
|
+
* @param options - Options object with custom formatters (named mode only)
|
|
42
|
+
* @returns String with placeholders replaced with formatted values
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* // Indexed mode - basic replacement
|
|
46
|
+
* formatString("Hello, {0}! It's {1} today.", "World", "sunny");
|
|
47
|
+
* // → "Hello, World! It's sunny today."
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* // Named mode - object properties
|
|
51
|
+
* formatString("Hello, {name}! You are {age} years old.", { name: "Alice", age: 25 });
|
|
52
|
+
* // → "Hello, Alice! You are 25 years old."
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // Nested object access
|
|
56
|
+
* formatString("User: {user.name}, Email: {user.email}", {
|
|
57
|
+
* user: { name: "Charlie", email: "charlie@example.com" }
|
|
58
|
+
* });
|
|
59
|
+
* // → "User: Charlie, Email: charlie@example.com"
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // Array access with negative indices
|
|
63
|
+
* formatString("First: {items[0]}, Last: {items[-1]}", { items: ["A", "B", "C"] });
|
|
64
|
+
* // → "First: A, Last: C"
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* // Default values
|
|
68
|
+
* formatString("Name: {name|Unknown}, Age: {age|N/A}", { age: 25 });
|
|
69
|
+
* // → "Name: Unknown, Age: 25"
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Built-in formatters
|
|
73
|
+
* formatString("Price: {price:currency(ja-JP,JPY)}", { price: 1234 });
|
|
74
|
+
* // → "Price: ¥1,234"
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* // Custom formatters
|
|
78
|
+
* formatString("Reversed: {text:reverse}", { text: "hello" }, {
|
|
79
|
+
* formatters: {
|
|
80
|
+
* reverse: (value) => String(value).split("").reverse().join("")
|
|
81
|
+
* }
|
|
82
|
+
* });
|
|
83
|
+
* // → "Reversed: olleh"
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* // Escape sequences
|
|
87
|
+
* formatString("Literal {{name}} and value {name}", { name: "Alice" });
|
|
88
|
+
* // → "Literal {name} and value Alice"
|
|
89
|
+
*/
|
|
90
|
+
export declare function formatString(template: string, data?: FormatData, options?: FormatOptions): string;
|
|
91
|
+
export declare function formatString(template: string, ...values: FormatValue[]): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { applyFormatter } from "./applyFormatter";
|
|
2
|
+
import { defaultFormatters } from "./defaultFormatters";
|
|
3
|
+
import { detectMode } from "./detectMode";
|
|
4
|
+
import { getValue } from "./getValue";
|
|
5
|
+
export function formatString(template, dataOrFirstValue, optionsOrSecondValue, ...restValues) {
|
|
6
|
+
const escapedTemplate = template
|
|
7
|
+
.replaceAll("{{", "\u0000")
|
|
8
|
+
.replaceAll("}}", "\u0001");
|
|
9
|
+
const { data, options } = detectMode(dataOrFirstValue, optionsOrSecondValue, restValues);
|
|
10
|
+
const formatters = { ...defaultFormatters, ...options.formatters };
|
|
11
|
+
const result = escapedTemplate.replaceAll(/{([^}]+)}/g, (match, content) => {
|
|
12
|
+
const [pathAndFormatter, defaultValue] = content
|
|
13
|
+
.split("|")
|
|
14
|
+
.map((part) => part.trim());
|
|
15
|
+
const [path, ...formatterParts] = pathAndFormatter.split(":");
|
|
16
|
+
const formatterString = formatterParts.join(":");
|
|
17
|
+
let value;
|
|
18
|
+
if (Array.isArray(data)) {
|
|
19
|
+
const index = Number(path);
|
|
20
|
+
value = Number.isNaN(index) ? undefined : data[index];
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
value = getValue(data, path);
|
|
24
|
+
}
|
|
25
|
+
if (value === undefined || value === null) {
|
|
26
|
+
if (defaultValue === undefined) {
|
|
27
|
+
return match;
|
|
28
|
+
}
|
|
29
|
+
value = defaultValue;
|
|
30
|
+
}
|
|
31
|
+
if (formatterString) {
|
|
32
|
+
return applyFormatter(value, formatterString, formatters);
|
|
33
|
+
}
|
|
34
|
+
return String(value);
|
|
35
|
+
});
|
|
36
|
+
return result.replaceAll("\u0000", "{").replaceAll("\u0001", "}");
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/String/formatString/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAqGtC,MAAM,UAAU,YAAY,CAC1B,QAAgB,EAChB,gBAA2C,EAC3C,oBAAkD,EAClD,GAAG,UAAyB;IAE5B,MAAM,eAAe,GAAG,QAAQ;SAC7B,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC;SAC1B,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAE9B,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAClC,gBAAgB,EAChB,oBAAoB,EACpB,UAAU,CACX,CAAC;IAEF,MAAM,UAAU,GAAG,EAAE,GAAG,iBAAiB,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAEnE,MAAM,MAAM,GAAG,eAAe,CAAC,UAAU,CACvC,YAAY,EACZ,CAAC,KAAK,EAAE,OAAe,EAAE,EAAE;QACzB,MAAM,CAAC,gBAAgB,EAAE,YAAY,CAAC,GAAG,OAAO;aAC7C,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,IAAI,EAAE,GAAG,cAAc,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9D,MAAM,eAAe,GAAG,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEjD,IAAI,KAAc,CAAC;QACnB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YAC3B,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/B,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAC1C,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;gBAC/B,OAAO,KAAK,CAAC;YACf,CAAC;YACD,KAAK,GAAG,YAAY,CAAC;QACvB,CAAC;QAED,IAAI,eAAe,EAAE,CAAC;YACpB,OAAO,cAAc,CAAC,KAAK,EAAE,eAAe,EAAE,UAAU,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Perform fuzzy string matching on an array of strings
|
|
3
|
+
* @param query - The search query
|
|
4
|
+
* @param items - Array of strings to search in
|
|
5
|
+
* @param threshold - Similarity threshold (0-1) for matching (default: 0.6)
|
|
6
|
+
* @returns Array of matching items with their similarity scores, sorted by best match
|
|
7
|
+
* @example
|
|
8
|
+
* fuzzySearch("hello", ["hello", "world", "helo", "help"]);
|
|
9
|
+
* // [{ item: "hello", score: 1 }, { item: "helo", score: 0.8 }, { item: "help", score: 0.6 }]
|
|
10
|
+
*/
|
|
11
|
+
export declare const fuzzySearch: (query: string, items: string[], threshold?: number) => Array<{
|
|
12
|
+
item: string;
|
|
13
|
+
score: number;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { levenshteinDistance } from "./levenshteinDistance";
|
|
2
|
+
/**
|
|
3
|
+
* Perform fuzzy string matching on an array of strings
|
|
4
|
+
* @param query - The search query
|
|
5
|
+
* @param items - Array of strings to search in
|
|
6
|
+
* @param threshold - Similarity threshold (0-1) for matching (default: 0.6)
|
|
7
|
+
* @returns Array of matching items with their similarity scores, sorted by best match
|
|
8
|
+
* @example
|
|
9
|
+
* fuzzySearch("hello", ["hello", "world", "helo", "help"]);
|
|
10
|
+
* // [{ item: "hello", score: 1 }, { item: "helo", score: 0.8 }, { item: "help", score: 0.6 }]
|
|
11
|
+
*/
|
|
12
|
+
export const fuzzySearch = (query, items, threshold = 0.6) => {
|
|
13
|
+
if (query.length === 0) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
const results = [];
|
|
17
|
+
for (const item of items) {
|
|
18
|
+
const distance = levenshteinDistance(query.toLowerCase(), item.toLowerCase());
|
|
19
|
+
const maxLength = Math.max(query.length, item.length);
|
|
20
|
+
const score = 1 - distance / maxLength;
|
|
21
|
+
if (score >= threshold) {
|
|
22
|
+
results.push({ item, score });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return results.sort((a, b) => b.score - a.score);
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=fuzzySearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fuzzySearch.js","sourceRoot":"","sources":["../../src/String/fuzzySearch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,KAAa,EACb,KAAe,EACf,SAAS,GAAG,GAAG,EACyB,EAAE;IAC1C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,OAAO,GAA2C,EAAE,CAAC;IAE3D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,QAAQ,GAAG,mBAAmB,CAClC,KAAK,CAAC,WAAW,EAAE,EACnB,IAAI,CAAC,WAAW,EAAE,CACnB,CAAC;QACF,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACtD,MAAM,KAAK,GAAG,CAAC,GAAG,QAAQ,GAAG,SAAS,CAAC;QAEvC,IAAI,KAAK,IAAI,SAAS,EAAE,CAAC;YACvB,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC,CAAC"}
|
package/module/String/index.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
+
export * from "./camelCase";
|
|
1
2
|
export * from "./deleteSpaces";
|
|
3
|
+
export * from "./escapeHtml";
|
|
2
4
|
export * from "./formatString";
|
|
3
5
|
export * from "./fromBase64";
|
|
6
|
+
export * from "./fuzzySearch";
|
|
4
7
|
export * from "./hasNoLetters";
|
|
8
|
+
export * from "./kebabCase";
|
|
9
|
+
export * from "./levenshteinDistance";
|
|
5
10
|
export * from "./padEnd";
|
|
6
11
|
export * from "./padStart";
|
|
7
12
|
export * from "./randomString";
|
|
8
13
|
export * from "./randomStringInitialization";
|
|
9
14
|
export * from "./reverseString";
|
|
15
|
+
export * from "./slugify";
|
|
16
|
+
export * from "./stringSimilarity";
|
|
10
17
|
export * from "./toBase64";
|
|
11
18
|
export * from "./toHalfWidth";
|
|
12
19
|
export * from "./trimCharacters";
|
|
13
20
|
export * from "./trimEndCharacters";
|
|
14
21
|
export * from "./trimStartCharacters";
|
|
22
|
+
export * from "./truncate";
|
|
23
|
+
export * from "./unescapeHtml";
|
package/module/String/index.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
+
export * from "./camelCase";
|
|
1
2
|
export * from "./deleteSpaces";
|
|
3
|
+
export * from "./escapeHtml";
|
|
2
4
|
export * from "./formatString";
|
|
3
5
|
export * from "./fromBase64";
|
|
6
|
+
export * from "./fuzzySearch";
|
|
4
7
|
export * from "./hasNoLetters";
|
|
8
|
+
export * from "./kebabCase";
|
|
9
|
+
export * from "./levenshteinDistance";
|
|
5
10
|
export * from "./padEnd";
|
|
6
11
|
export * from "./padStart";
|
|
7
12
|
export * from "./randomString";
|
|
8
13
|
export * from "./randomStringInitialization";
|
|
9
14
|
export * from "./reverseString";
|
|
15
|
+
export * from "./slugify";
|
|
16
|
+
export * from "./stringSimilarity";
|
|
10
17
|
export * from "./toBase64";
|
|
11
18
|
export * from "./toHalfWidth";
|
|
12
19
|
export * from "./trimCharacters";
|
|
13
20
|
export * from "./trimEndCharacters";
|
|
14
21
|
export * from "./trimStartCharacters";
|
|
22
|
+
export * from "./truncate";
|
|
23
|
+
export * from "./unescapeHtml";
|
|
15
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/String/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/String/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to kebab-case
|
|
3
|
+
* @param str - The string to convert
|
|
4
|
+
* @returns The kebab-case string
|
|
5
|
+
*/
|
|
6
|
+
export const kebabCase = (string_) => {
|
|
7
|
+
return (string_
|
|
8
|
+
// Insert dash between lowercase and uppercase
|
|
9
|
+
.replaceAll(/([a-z])([A-Z])/g, "$1-$2")
|
|
10
|
+
// Insert dash between sequences of uppercase letters and following lowercase
|
|
11
|
+
.replaceAll(/([A-Z])([A-Z][a-z])/g, "$1-$2")
|
|
12
|
+
// Replace spaces and underscores with dashes
|
|
13
|
+
.replaceAll(/[\s_]+/g, "-")
|
|
14
|
+
// Remove special characters except alphanumeric and dashes
|
|
15
|
+
.replaceAll(/[^a-zA-Z0-9-]/g, "-")
|
|
16
|
+
// Remove multiple consecutive dashes
|
|
17
|
+
.replaceAll(/-+/g, "-")
|
|
18
|
+
// Remove leading and trailing dashes
|
|
19
|
+
.replaceAll(/^-|-$/g, "")
|
|
20
|
+
.toLowerCase());
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=kebabCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kebabCase.js","sourceRoot":"","sources":["../../src/String/kebabCase.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAe,EAAU,EAAE;IACnD,OAAO,CACL,OAAO;QACL,8CAA8C;SAC7C,UAAU,CAAC,iBAAiB,EAAE,OAAO,CAAC;QACvC,6EAA6E;SAC5E,UAAU,CAAC,sBAAsB,EAAE,OAAO,CAAC;QAC5C,6CAA6C;SAC5C,UAAU,CAAC,SAAS,EAAE,GAAG,CAAC;QAC3B,2DAA2D;SAC1D,UAAU,CAAC,gBAAgB,EAAE,GAAG,CAAC;QAClC,qCAAqC;SACpC,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC;QACvB,qCAAqC;SACpC,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC;SACxB,WAAW,EAAE,CACjB,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the Levenshtein distance between two strings
|
|
3
|
+
* Returns the minimum number of single-character edits (insertions, deletions, or substitutions)
|
|
4
|
+
* @param str1 - First string to compare
|
|
5
|
+
* @param str2 - Second string to compare
|
|
6
|
+
* @returns The Levenshtein distance
|
|
7
|
+
*/
|
|
8
|
+
export declare const levenshteinDistance: (string1: string, string2: string) => number;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the Levenshtein distance between two strings
|
|
3
|
+
* Returns the minimum number of single-character edits (insertions, deletions, or substitutions)
|
|
4
|
+
* @param str1 - First string to compare
|
|
5
|
+
* @param str2 - Second string to compare
|
|
6
|
+
* @returns The Levenshtein distance
|
|
7
|
+
*/
|
|
8
|
+
export const levenshteinDistance = (string1, string2) => {
|
|
9
|
+
const length1 = string1.length;
|
|
10
|
+
const length2 = string2.length;
|
|
11
|
+
// Return the length of the other string if one is empty
|
|
12
|
+
if (length1 === 0) {
|
|
13
|
+
return length2;
|
|
14
|
+
}
|
|
15
|
+
if (length2 === 0) {
|
|
16
|
+
return length1;
|
|
17
|
+
}
|
|
18
|
+
// Create a 2D array for dynamic programming
|
|
19
|
+
const matrix = Array.from({ length: length1 + 1 }, () => Array.from({ length: length2 + 1 }, () => 0));
|
|
20
|
+
// Initialize first column and row
|
|
21
|
+
for (let index = 0; index <= length1; index++) {
|
|
22
|
+
matrix[index][0] = index;
|
|
23
|
+
}
|
|
24
|
+
for (let index = 0; index <= length2; index++) {
|
|
25
|
+
matrix[0][index] = index;
|
|
26
|
+
}
|
|
27
|
+
// Calculate distances
|
|
28
|
+
for (let index = 1; index <= length1; index++) {
|
|
29
|
+
for (let index_ = 1; index_ <= length2; index_++) {
|
|
30
|
+
const cost = string1[index - 1] === string2[index_ - 1] ? 0 : 1;
|
|
31
|
+
matrix[index][index_] = Math.min(matrix[index - 1][index_] + 1, // deletion
|
|
32
|
+
matrix[index][index_ - 1] + 1, // insertion
|
|
33
|
+
matrix[index - 1][index_ - 1] + cost);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return matrix[length1][length2];
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=levenshteinDistance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"levenshteinDistance.js","sourceRoot":"","sources":["../../src/String/levenshteinDistance.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,OAAe,EACf,OAAe,EACP,EAAE;IACV,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAE/B,wDAAwD;IACxD,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;QAClB,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;QAClB,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,4CAA4C;IAC5C,MAAM,MAAM,GAAe,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,CAClE,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAC7C,CAAC;IAEF,kCAAkC;IAClC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,IAAI,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;QAC9C,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;IAC3B,CAAC;IACD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,IAAI,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;QAC9C,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED,sBAAsB;IACtB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,IAAI,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC;QAC9C,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC;YACjD,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAChE,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAC9B,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,WAAW;YAC1C,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,YAAY;YAC3C,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CACrC,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a string to a URL-friendly slug
|
|
3
|
+
* @param str - The string to convert
|
|
4
|
+
* @returns The slugified string
|
|
5
|
+
* @example
|
|
6
|
+
* slugify("Hello World!"); // "hello-world"
|
|
7
|
+
* slugify("This is a Test"); // "this-is-a-test"
|
|
8
|
+
* slugify("Japanese: こんにちは"); // "japanese"
|
|
9
|
+
*/
|
|
10
|
+
export declare const slugify: (string_: string) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a string to a URL-friendly slug
|
|
3
|
+
* @param str - The string to convert
|
|
4
|
+
* @returns The slugified string
|
|
5
|
+
* @example
|
|
6
|
+
* slugify("Hello World!"); // "hello-world"
|
|
7
|
+
* slugify("This is a Test"); // "this-is-a-test"
|
|
8
|
+
* slugify("Japanese: こんにちは"); // "japanese"
|
|
9
|
+
*/
|
|
10
|
+
export const slugify = (string_) => {
|
|
11
|
+
return string_
|
|
12
|
+
.normalize("NFD")
|
|
13
|
+
.replaceAll(/[\u0300-\u036F]/g, "")
|
|
14
|
+
.toLowerCase()
|
|
15
|
+
.replaceAll(/[^\w\s-]/g, "-")
|
|
16
|
+
.replaceAll(/\s+/g, "-")
|
|
17
|
+
.replaceAll(/_+/g, "-")
|
|
18
|
+
.replaceAll(/-+/g, "-")
|
|
19
|
+
.replaceAll(/^-+|-+$/g, "");
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=slugify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slugify.js","sourceRoot":"","sources":["../../src/String/slugify.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAe,EAAU,EAAE;IACjD,OAAO,OAAO;SACX,SAAS,CAAC,KAAK,CAAC;SAChB,UAAU,CAAC,kBAAkB,EAAE,EAAE,CAAC;SAClC,WAAW,EAAE;SACb,UAAU,CAAC,WAAW,EAAE,GAAG,CAAC;SAC5B,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC;SACvB,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC;SACtB,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC;SACtB,UAAU,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAChC,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the similarity between two strings as a percentage
|
|
3
|
+
* Uses Levenshtein distance normalized by the length of the longer string
|
|
4
|
+
* @param str1 - First string to compare
|
|
5
|
+
* @param str2 - Second string to compare
|
|
6
|
+
* @returns Similarity score between 0 (completely different) and 1 (identical)
|
|
7
|
+
*/
|
|
8
|
+
export declare const stringSimilarity: (string1: string, string2: string) => number;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { levenshteinDistance } from "./levenshteinDistance";
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the similarity between two strings as a percentage
|
|
4
|
+
* Uses Levenshtein distance normalized by the length of the longer string
|
|
5
|
+
* @param str1 - First string to compare
|
|
6
|
+
* @param str2 - Second string to compare
|
|
7
|
+
* @returns Similarity score between 0 (completely different) and 1 (identical)
|
|
8
|
+
*/
|
|
9
|
+
export const stringSimilarity = (string1, string2) => {
|
|
10
|
+
// Identical strings have 100% similarity
|
|
11
|
+
if (string1 === string2) {
|
|
12
|
+
return 1;
|
|
13
|
+
}
|
|
14
|
+
// Empty strings handling
|
|
15
|
+
if (string1.length === 0 || string2.length === 0) {
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
const distance = levenshteinDistance(string1, string2);
|
|
19
|
+
const maxLength = Math.max(string1.length, string2.length);
|
|
20
|
+
// Calculate similarity as 1 - (distance / maxLength)
|
|
21
|
+
return 1 - distance / maxLength;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=stringSimilarity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringSimilarity.js","sourceRoot":"","sources":["../../src/String/stringSimilarity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,OAAe,EAAU,EAAE;IAC3E,yCAAyC;IACzC,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;QACxB,OAAO,CAAC,CAAC;IACX,CAAC;IAED,yBAAyB;IACzB,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjD,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,QAAQ,GAAG,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACvD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3D,qDAAqD;IACrD,OAAO,CAAC,GAAG,QAAQ,GAAG,SAAS,CAAC;AAClC,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Truncate a string to a specified length
|
|
3
|
+
* @param str - The string to truncate
|
|
4
|
+
* @param length - The maximum length
|
|
5
|
+
* @param suffix - The suffix to add when truncating (default: "...")
|
|
6
|
+
* @returns The truncated string
|
|
7
|
+
* @example
|
|
8
|
+
* truncate("Hello World", 5); // "Hello..."
|
|
9
|
+
* truncate("Hello World", 5, "~"); // "Hello~"
|
|
10
|
+
* truncate("Hello", 10); // "Hello"
|
|
11
|
+
*/
|
|
12
|
+
export declare const truncate: (string_: string, length: number, suffix?: string) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Truncate a string to a specified length
|
|
3
|
+
* @param str - The string to truncate
|
|
4
|
+
* @param length - The maximum length
|
|
5
|
+
* @param suffix - The suffix to add when truncating (default: "...")
|
|
6
|
+
* @returns The truncated string
|
|
7
|
+
* @example
|
|
8
|
+
* truncate("Hello World", 5); // "Hello..."
|
|
9
|
+
* truncate("Hello World", 5, "~"); // "Hello~"
|
|
10
|
+
* truncate("Hello", 10); // "Hello"
|
|
11
|
+
*/
|
|
12
|
+
export const truncate = (string_, length, suffix = "...") => {
|
|
13
|
+
if (length < 0) {
|
|
14
|
+
throw new Error("Length must be non-negative");
|
|
15
|
+
}
|
|
16
|
+
if (string_.length <= length) {
|
|
17
|
+
return string_;
|
|
18
|
+
}
|
|
19
|
+
return string_.slice(0, length) + suffix;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=truncate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncate.js","sourceRoot":"","sources":["../../src/String/truncate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,OAAe,EACf,MAAc,EACd,MAAM,GAAG,KAAK,EACN,EAAE;IACV,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,IAAI,MAAM,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;AAC3C,CAAC,CAAC"}
|