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,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.defaultFormatters = void 0;
|
|
7
|
+
function _readOnlyError(r) { throw new TypeError('"' + r + '" is read-only'); }
|
|
8
|
+
/**
|
|
9
|
+
* Built-in formatter functions for formatString.
|
|
10
|
+
*
|
|
11
|
+
* Each formatter takes a value and optional arguments, returning a formatted string.
|
|
12
|
+
* Formatters are used with syntax like {value:formatterName} or {value:formatterName(arg1,arg2)}.
|
|
13
|
+
*
|
|
14
|
+
* Available formatters:
|
|
15
|
+
* - upper: Convert to uppercase
|
|
16
|
+
* - lower: Convert to lowercase
|
|
17
|
+
* - currency: Format as currency with locale support
|
|
18
|
+
* - date: Format dates with locale and format options
|
|
19
|
+
* - time: Format time with locale support
|
|
20
|
+
* - number: Format numbers with precision control
|
|
21
|
+
* - plural: Choose singular/plural form based on count
|
|
22
|
+
* - pad: Pad string with characters to specified length
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Usage in formatString
|
|
26
|
+
* formatString("{name:upper}", { name: "alice" }) // → "ALICE"
|
|
27
|
+
* formatString("{price:currency(ja-JP,JPY)}", { price: 1000 }) // → "¥1,000"
|
|
28
|
+
* formatString("{count:plural(item,items)}", { count: 1 }) // → "item"
|
|
29
|
+
*/
|
|
30
|
+
var defaultFormatters = exports.defaultFormatters = {
|
|
31
|
+
upper: function upper(value) {
|
|
32
|
+
return String(value).toUpperCase();
|
|
33
|
+
},
|
|
34
|
+
lower: function lower(value) {
|
|
35
|
+
return String(value).toLowerCase();
|
|
36
|
+
},
|
|
37
|
+
currency: function currency(value) {
|
|
38
|
+
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "en-US";
|
|
39
|
+
var _currency = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "USD";
|
|
40
|
+
return new Intl.NumberFormat(locale, {
|
|
41
|
+
style: "currency",
|
|
42
|
+
currency: _currency
|
|
43
|
+
}).format(Number(value));
|
|
44
|
+
},
|
|
45
|
+
date: function date(value) {
|
|
46
|
+
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "en-US";
|
|
47
|
+
var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "short";
|
|
48
|
+
var date = value instanceof Date ? value : new Date(String(value));
|
|
49
|
+
if (format === "iso") {
|
|
50
|
+
return date.toISOString();
|
|
51
|
+
}
|
|
52
|
+
if (format === "time") {
|
|
53
|
+
return date.toLocaleTimeString(locale);
|
|
54
|
+
}
|
|
55
|
+
return date.toLocaleDateString(locale);
|
|
56
|
+
},
|
|
57
|
+
time: function time(value) {
|
|
58
|
+
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "en-US";
|
|
59
|
+
var date = value instanceof Date ? value : new Date(String(value));
|
|
60
|
+
return date.toLocaleTimeString(locale);
|
|
61
|
+
},
|
|
62
|
+
number: function number(value) {
|
|
63
|
+
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "en-US";
|
|
64
|
+
var minimumFractionDigits = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "0";
|
|
65
|
+
var maximumFractionDigits = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "20";
|
|
66
|
+
return new Intl.NumberFormat(locale, {
|
|
67
|
+
minimumFractionDigits: Number(minimumFractionDigits),
|
|
68
|
+
maximumFractionDigits: Number(maximumFractionDigits)
|
|
69
|
+
}).format(Number(value));
|
|
70
|
+
},
|
|
71
|
+
plural: function plural(value, singular, _plural) {
|
|
72
|
+
return Number(value) === 1 ? singular : _plural;
|
|
73
|
+
},
|
|
74
|
+
pad: function pad(value) {
|
|
75
|
+
var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "2";
|
|
76
|
+
var _char = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "0";
|
|
77
|
+
return String(value).padStart(Number(length), _char);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FormatData } from "$/string/formatString/formatData";
|
|
2
|
+
import type { FormatOptions } from "$/string/formatString/formatOptions";
|
|
3
|
+
import type { FormatValue } from "$/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,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.detectMode = detectMode;
|
|
7
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
8
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
10
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
11
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
12
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
13
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
14
|
+
/**
|
|
15
|
+
* Detects whether formatString should use indexed or named mode based on arguments.
|
|
16
|
+
*
|
|
17
|
+
* Named mode: First argument is a non-array object
|
|
18
|
+
* Indexed mode: Arguments are treated as array values
|
|
19
|
+
*
|
|
20
|
+
* @param dataOrFirstValue - First argument (object for named mode, value for indexed mode)
|
|
21
|
+
* @param optionsOrSecondValue - Second argument (options for named mode, value for indexed mode)
|
|
22
|
+
* @param restValues - Remaining arguments for indexed mode
|
|
23
|
+
* @returns Object containing data and options for formatting
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Named mode detection
|
|
27
|
+
* detectMode({ name: "Alice" }) // → { data: { name: "Alice" }, options: {} }
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Indexed mode detection
|
|
31
|
+
* detectMode("first", "second") // → { data: ["first", "second"], options: {} }
|
|
32
|
+
*/
|
|
33
|
+
function detectMode(dataOrFirstValue, optionsOrSecondValue, restValues) {
|
|
34
|
+
var isFirstArgumentObject = dataOrFirstValue !== undefined && _typeof(dataOrFirstValue) === "object" && dataOrFirstValue !== null && !Array.isArray(dataOrFirstValue) && !(dataOrFirstValue instanceof Date);
|
|
35
|
+
var isSecondArgumentOptions = optionsOrSecondValue !== undefined && _typeof(optionsOrSecondValue) === "object" && optionsOrSecondValue !== null && !Array.isArray(optionsOrSecondValue) && !(optionsOrSecondValue instanceof Date) && "formatters" in optionsOrSecondValue;
|
|
36
|
+
if (isFirstArgumentObject && optionsOrSecondValue === undefined && restValues.length === 0) {
|
|
37
|
+
return {
|
|
38
|
+
data: dataOrFirstValue,
|
|
39
|
+
options: {}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (isFirstArgumentObject && isSecondArgumentOptions && restValues.length === 0) {
|
|
43
|
+
return {
|
|
44
|
+
data: dataOrFirstValue,
|
|
45
|
+
options: optionsOrSecondValue
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
var allValues = [];
|
|
49
|
+
if (dataOrFirstValue !== undefined) {
|
|
50
|
+
allValues.push(dataOrFirstValue);
|
|
51
|
+
}
|
|
52
|
+
if (optionsOrSecondValue !== undefined) {
|
|
53
|
+
allValues.push(optionsOrSecondValue);
|
|
54
|
+
}
|
|
55
|
+
allValues.push.apply(allValues, _toConsumableArray(restValues));
|
|
56
|
+
return {
|
|
57
|
+
data: allValues,
|
|
58
|
+
options: {}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -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,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getValue = getValue;
|
|
7
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
10
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
11
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
12
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
13
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
14
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves a value from an object using a dot-notation path with array index support.
|
|
17
|
+
*
|
|
18
|
+
* Supports nested properties and array access with positive/negative indices.
|
|
19
|
+
*
|
|
20
|
+
* @param object - The object to retrieve the value from
|
|
21
|
+
* @param path - Dot-notation path (e.g., "user.name", "items[0]", "data[0].items[-1].name")
|
|
22
|
+
* @returns The value at the specified path, or undefined if not found
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Simple property access
|
|
26
|
+
* getValue({ name: "Alice" }, "name") // → "Alice"
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Nested property access
|
|
30
|
+
* getValue({ user: { name: "Bob" } }, "user.name") // → "Bob"
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Array access
|
|
34
|
+
* getValue({ items: ["A", "B", "C"] }, "items[0]") // → "A"
|
|
35
|
+
* getValue({ items: ["A", "B", "C"] }, "items[-1]") // → "C"
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Complex nested access
|
|
39
|
+
* getValue({ users: [{ name: "Alice" }] }, "users[0].name") // → "Alice"
|
|
40
|
+
*/
|
|
41
|
+
function getValue(object, path) {
|
|
42
|
+
var segments = [];
|
|
43
|
+
var parts = path.split(".");
|
|
44
|
+
var _iterator = _createForOfIteratorHelper(parts),
|
|
45
|
+
_step;
|
|
46
|
+
try {
|
|
47
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
48
|
+
var part = _step.value;
|
|
49
|
+
var arrayMatch = part.match(/^(.+?)\[(-?\d+)\]$/);
|
|
50
|
+
if (arrayMatch) {
|
|
51
|
+
var _arrayMatch = _slicedToArray(arrayMatch, 3),
|
|
52
|
+
key = _arrayMatch[1],
|
|
53
|
+
indexString = _arrayMatch[2];
|
|
54
|
+
segments.push({
|
|
55
|
+
key: key,
|
|
56
|
+
index: Number(indexString)
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
segments.push({
|
|
60
|
+
key: part
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
_iterator.e(err);
|
|
66
|
+
} finally {
|
|
67
|
+
_iterator.f();
|
|
68
|
+
}
|
|
69
|
+
var current = object;
|
|
70
|
+
for (var _i = 0, _segments = segments; _i < _segments.length; _i++) {
|
|
71
|
+
var segment = _segments[_i];
|
|
72
|
+
if (_typeof(current) !== "object" || current == null) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
current = current[segment.key];
|
|
76
|
+
if (segment.index !== undefined) {
|
|
77
|
+
if (!Array.isArray(current)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
var index = segment.index;
|
|
81
|
+
current = index < 0 ? current[current.length + index] : current[index];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return current;
|
|
85
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { FormatData } from "$/string/formatString/formatData";
|
|
2
|
+
import type { FormatOptions } from "$/string/formatString/formatOptions";
|
|
3
|
+
import type { FormatValue } from "$/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,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.formatString = formatString;
|
|
7
|
+
var _applyFormatter = require("./applyFormatter");
|
|
8
|
+
var _defaultFormatters = require("./defaultFormatters");
|
|
9
|
+
var _detectMode2 = require("./detectMode");
|
|
10
|
+
var _getValue = require("./getValue");
|
|
11
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
12
|
+
function _toArray(r) { return _arrayWithHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableRest(); }
|
|
13
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
14
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
15
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
16
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
17
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
18
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
19
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
20
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
21
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
22
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
23
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
24
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
25
|
+
/**
|
|
26
|
+
* Replaces placeholders in a template string with specified values.
|
|
27
|
+
*
|
|
28
|
+
* Supports two modes:
|
|
29
|
+
* 1. **Indexed mode**: Use numbered placeholders like {0}, {1}, {2}...
|
|
30
|
+
* 2. **Named mode**: Use named placeholders with an object like {name}, {age}...
|
|
31
|
+
*
|
|
32
|
+
* ## Advanced Features
|
|
33
|
+
*
|
|
34
|
+
* ### Nested Object Access
|
|
35
|
+
* Access nested properties using dot notation: `{user.name}`, `{user.address.city}`
|
|
36
|
+
*
|
|
37
|
+
* ### Array Access
|
|
38
|
+
* Access array elements with brackets: `{items[0]}`, `{users[1].name}`
|
|
39
|
+
* Supports negative indices: `{items[-1]}` (last element), `{items[-2]}` (second to last)
|
|
40
|
+
*
|
|
41
|
+
* ### Default Values
|
|
42
|
+
* Provide fallback values using pipe syntax: `{name|Unknown}`, `{age|N/A}`
|
|
43
|
+
*
|
|
44
|
+
* ### Formatters
|
|
45
|
+
* Apply formatters to values: `{name:upper}`, `{price:currency}`, `{date:date}`
|
|
46
|
+
*
|
|
47
|
+
* Built-in formatters:
|
|
48
|
+
* - `upper` - Convert to uppercase
|
|
49
|
+
* - `lower` - Convert to lowercase
|
|
50
|
+
* - `currency(locale?, currency?)` - Format as currency (e.g., `{price:currency(ja-JP,JPY)}`)
|
|
51
|
+
* - `date(locale?, format?)` - Format dates (format: short|medium|long|full|iso|time)
|
|
52
|
+
* - `time(locale?)` - Format time
|
|
53
|
+
* - `number(locale?, minFraction?, maxFraction?)` - Format numbers
|
|
54
|
+
* - `plural(singular, plural)` - Pluralization (e.g., `{count:plural(item,items)}`)
|
|
55
|
+
* - `pad(length, char?)` - Pad string/number (e.g., `{id:pad(4,0)}`)
|
|
56
|
+
*
|
|
57
|
+
* ### Escape Sequences
|
|
58
|
+
* Use double braces to escape: `{{name}}` renders as literal `{name}`
|
|
59
|
+
*
|
|
60
|
+
* @param template - Template string containing placeholders
|
|
61
|
+
* @param data - Data object for named mode OR first value for indexed mode
|
|
62
|
+
* @param options - Options object with custom formatters (named mode only)
|
|
63
|
+
* @returns String with placeholders replaced with formatted values
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* // Indexed mode - basic replacement
|
|
67
|
+
* formatString("Hello, {0}! It's {1} today.", "World", "sunny");
|
|
68
|
+
* // → "Hello, World! It's sunny today."
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* // Named mode - object properties
|
|
72
|
+
* formatString("Hello, {name}! You are {age} years old.", { name: "Alice", age: 25 });
|
|
73
|
+
* // → "Hello, Alice! You are 25 years old."
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // Nested object access
|
|
77
|
+
* formatString("User: {user.name}, Email: {user.email}", {
|
|
78
|
+
* user: { name: "Charlie", email: "charlie@example.com" }
|
|
79
|
+
* });
|
|
80
|
+
* // → "User: Charlie, Email: charlie@example.com"
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* // Array access with negative indices
|
|
84
|
+
* formatString("First: {items[0]}, Last: {items[-1]}", { items: ["A", "B", "C"] });
|
|
85
|
+
* // → "First: A, Last: C"
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* // Default values
|
|
89
|
+
* formatString("Name: {name|Unknown}, Age: {age|N/A}", { age: 25 });
|
|
90
|
+
* // → "Name: Unknown, Age: 25"
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* // Built-in formatters
|
|
94
|
+
* formatString("Price: {price:currency(ja-JP,JPY)}", { price: 1234 });
|
|
95
|
+
* // → "Price: ¥1,234"
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // Custom formatters
|
|
99
|
+
* formatString("Reversed: {text:reverse}", { text: "hello" }, {
|
|
100
|
+
* formatters: {
|
|
101
|
+
* reverse: (value) => String(value).split("").reverse().join("")
|
|
102
|
+
* }
|
|
103
|
+
* });
|
|
104
|
+
* // → "Reversed: olleh"
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* // Escape sequences
|
|
108
|
+
* formatString("Literal {{name}} and value {name}", { name: "Alice" });
|
|
109
|
+
* // → "Literal {name} and value Alice"
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
function formatString(template, dataOrFirstValue, optionsOrSecondValue) {
|
|
113
|
+
var escapedTemplate = template.replaceAll("{{", "\0").replaceAll("}}", "\x01");
|
|
114
|
+
for (var _len = arguments.length, restValues = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
115
|
+
restValues[_key - 3] = arguments[_key];
|
|
116
|
+
}
|
|
117
|
+
var _detectMode = (0, _detectMode2.detectMode)(dataOrFirstValue, optionsOrSecondValue, restValues),
|
|
118
|
+
data = _detectMode.data,
|
|
119
|
+
options = _detectMode.options;
|
|
120
|
+
var formatters = _objectSpread(_objectSpread({}, _defaultFormatters.defaultFormatters), options.formatters);
|
|
121
|
+
var result = escapedTemplate.replaceAll(/{([^}]+)}/g, function (match, content) {
|
|
122
|
+
var _content$split$map = content.split("|").map(function (part) {
|
|
123
|
+
return part.trim();
|
|
124
|
+
}),
|
|
125
|
+
_content$split$map2 = _slicedToArray(_content$split$map, 2),
|
|
126
|
+
pathAndFormatter = _content$split$map2[0],
|
|
127
|
+
defaultValue = _content$split$map2[1];
|
|
128
|
+
var _pathAndFormatter$spl = pathAndFormatter.split(":"),
|
|
129
|
+
_pathAndFormatter$spl2 = _toArray(_pathAndFormatter$spl),
|
|
130
|
+
path = _pathAndFormatter$spl2[0],
|
|
131
|
+
formatterParts = _pathAndFormatter$spl2.slice(1);
|
|
132
|
+
var formatterString = formatterParts.join(":");
|
|
133
|
+
var value;
|
|
134
|
+
if (Array.isArray(data)) {
|
|
135
|
+
var index = Number(path);
|
|
136
|
+
value = Number.isNaN(index) ? undefined : data[index];
|
|
137
|
+
} else {
|
|
138
|
+
value = (0, _getValue.getValue)(data, path);
|
|
139
|
+
}
|
|
140
|
+
if (value === undefined || value === null) {
|
|
141
|
+
if (defaultValue === undefined) {
|
|
142
|
+
return match;
|
|
143
|
+
}
|
|
144
|
+
value = defaultValue;
|
|
145
|
+
}
|
|
146
|
+
if (formatterString) {
|
|
147
|
+
return (0, _applyFormatter.applyFormatter)(value, formatterString, formatters);
|
|
148
|
+
}
|
|
149
|
+
return String(value);
|
|
150
|
+
});
|
|
151
|
+
return result.replaceAll("\0", "{").replaceAll("\x01", "}");
|
|
152
|
+
}
|
|
@@ -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,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fuzzySearch = void 0;
|
|
7
|
+
var _levenshteinDistance = require("./levenshteinDistance");
|
|
8
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
9
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
10
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
11
|
+
/**
|
|
12
|
+
* Perform fuzzy string matching on an array of strings
|
|
13
|
+
* @param query - The search query
|
|
14
|
+
* @param items - Array of strings to search in
|
|
15
|
+
* @param threshold - Similarity threshold (0-1) for matching (default: 0.6)
|
|
16
|
+
* @returns Array of matching items with their similarity scores, sorted by best match
|
|
17
|
+
* @example
|
|
18
|
+
* fuzzySearch("hello", ["hello", "world", "helo", "help"]);
|
|
19
|
+
* // [{ item: "hello", score: 1 }, { item: "helo", score: 0.8 }, { item: "help", score: 0.6 }]
|
|
20
|
+
*/
|
|
21
|
+
var fuzzySearch = exports.fuzzySearch = function fuzzySearch(query, items) {
|
|
22
|
+
var threshold = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.6;
|
|
23
|
+
if (query.length === 0) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
var results = [];
|
|
27
|
+
var _iterator = _createForOfIteratorHelper(items),
|
|
28
|
+
_step;
|
|
29
|
+
try {
|
|
30
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
31
|
+
var item = _step.value;
|
|
32
|
+
var distance = (0, _levenshteinDistance.levenshteinDistance)(query.toLowerCase(), item.toLowerCase());
|
|
33
|
+
var maxLength = Math.max(query.length, item.length);
|
|
34
|
+
var score = 1 - distance / maxLength;
|
|
35
|
+
if (score >= threshold) {
|
|
36
|
+
results.push({
|
|
37
|
+
item: item,
|
|
38
|
+
score: score
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
} catch (err) {
|
|
43
|
+
_iterator.e(err);
|
|
44
|
+
} finally {
|
|
45
|
+
_iterator.f();
|
|
46
|
+
}
|
|
47
|
+
return results.sort(function (a, b) {
|
|
48
|
+
return b.score - a.score;
|
|
49
|
+
});
|
|
50
|
+
};
|
|
@@ -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";
|