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,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the most frequently occurring value(s) in an array
|
|
3
|
+
* @param array - Array of numbers to find mode for
|
|
4
|
+
* @returns Array of mode values (can be multiple values if there are ties)
|
|
5
|
+
* @example
|
|
6
|
+
* mode([1, 2, 2, 3, 3, 3]); // [3]
|
|
7
|
+
* mode([1, 2, 2, 3, 3]); // [2, 3]
|
|
8
|
+
* mode([1, 2, 3]); // [1, 2, 3]
|
|
9
|
+
*/
|
|
10
|
+
export const mode = (array) => {
|
|
11
|
+
if (array.length === 0) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
const frequency = new Map();
|
|
15
|
+
let maxFrequency = 0;
|
|
16
|
+
// Count frequencies
|
|
17
|
+
for (const value of array) {
|
|
18
|
+
const count = (frequency.get(value) || 0) + 1;
|
|
19
|
+
frequency.set(value, count);
|
|
20
|
+
maxFrequency = Math.max(maxFrequency, count);
|
|
21
|
+
}
|
|
22
|
+
// Find all values with maximum frequency
|
|
23
|
+
const modes = [];
|
|
24
|
+
for (const [value, count] of frequency) {
|
|
25
|
+
if (count === maxFrequency) {
|
|
26
|
+
modes.push(value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return modes.sort((a, b) => a - b);
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mode.js","sourceRoot":"","sources":["../../src/Math/mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,KAAe,EAAY,EAAE;IAChD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC5C,IAAI,YAAY,GAAG,CAAC,CAAC;IAErB,oBAAoB;IACpB,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QAC9C,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC5B,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IAC/C,CAAC;IAED,yCAAyC;IACzC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,SAAS,EAAE,CAAC;QACvC,IAAI,KAAK,KAAK,YAAY,EAAE,CAAC;YAC3B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACrC,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate the nth percentile of values in an array
|
|
3
|
+
* @param array - Array of numbers
|
|
4
|
+
* @param percentile - Percentile value (0-100)
|
|
5
|
+
* @returns The percentile value
|
|
6
|
+
* @example
|
|
7
|
+
* percentile([1, 2, 3, 4, 5], 50); // 3 (50th percentile - median)
|
|
8
|
+
* percentile([1, 2, 3, 4, 5], 25); // 2 (25th percentile)
|
|
9
|
+
* percentile([1, 2, 3, 4, 5], 75); // 4 (75th percentile)
|
|
10
|
+
*/
|
|
11
|
+
export declare const percentile: (array: number[], percentile: number) => number;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { quickSort } from "../Array/quickSort";
|
|
2
|
+
/**
|
|
3
|
+
* Calculate the nth percentile of values in an array
|
|
4
|
+
* @param array - Array of numbers
|
|
5
|
+
* @param percentile - Percentile value (0-100)
|
|
6
|
+
* @returns The percentile value
|
|
7
|
+
* @example
|
|
8
|
+
* percentile([1, 2, 3, 4, 5], 50); // 3 (50th percentile - median)
|
|
9
|
+
* percentile([1, 2, 3, 4, 5], 25); // 2 (25th percentile)
|
|
10
|
+
* percentile([1, 2, 3, 4, 5], 75); // 4 (75th percentile)
|
|
11
|
+
*/
|
|
12
|
+
export const percentile = (array, percentile) => {
|
|
13
|
+
if (array.length === 0) {
|
|
14
|
+
return Number.NaN;
|
|
15
|
+
}
|
|
16
|
+
if (percentile < 0 || percentile > 100) {
|
|
17
|
+
throw new Error("Percentile must be between 0 and 100");
|
|
18
|
+
}
|
|
19
|
+
const sortedArray = quickSort([...array]);
|
|
20
|
+
const index = (percentile / 100) * (sortedArray.length - 1);
|
|
21
|
+
const lowerIndex = Math.floor(index);
|
|
22
|
+
const upperIndex = Math.ceil(index);
|
|
23
|
+
if (lowerIndex === upperIndex) {
|
|
24
|
+
return sortedArray[lowerIndex];
|
|
25
|
+
}
|
|
26
|
+
const lowerValue = sortedArray[lowerIndex];
|
|
27
|
+
const upperValue = sortedArray[upperIndex];
|
|
28
|
+
const weight = index - lowerIndex;
|
|
29
|
+
return lowerValue + (upperValue - lowerValue) * weight;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=percentile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"percentile.js","sourceRoot":"","sources":["../../src/Math/percentile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAe,EAAE,UAAkB,EAAU,EAAE;IACxE,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,GAAG,CAAC;IACpB,CAAC;IAED,IAAI,UAAU,GAAG,CAAC,IAAI,UAAU,GAAG,GAAG,EAAE,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,WAAW,GAAG,SAAS,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC5D,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACrC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEpC,IAAI,UAAU,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,UAAU,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;IAC3C,MAAM,UAAU,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,KAAK,GAAG,UAAU,CAAC;IAElC,OAAO,UAAU,GAAG,CAAC,UAAU,GAAG,UAAU,CAAC,GAAG,MAAM,CAAC;AACzD,CAAC,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { average } from "./average";
|
|
2
|
+
import { multiplication } from "../Math/multiplication";
|
|
3
|
+
import { subtract } from "../Math/subtract";
|
|
2
4
|
/**
|
|
3
5
|
* Calculates the standard deviation of a set of values
|
|
4
6
|
* @param {number[]} values Array of numeric values
|
|
@@ -14,8 +16,8 @@ export const standardDeviation = (values) => {
|
|
|
14
16
|
const avg = average(values);
|
|
15
17
|
// Calculate the squared differences from the mean
|
|
16
18
|
const squareDiffs = values.map((value) => {
|
|
17
|
-
const diff = value
|
|
18
|
-
return diff
|
|
19
|
+
const diff = subtract(value, avg);
|
|
20
|
+
return multiplication(diff, diff);
|
|
19
21
|
});
|
|
20
22
|
// Calculate the mean of the squared differences
|
|
21
23
|
const avgSquareDiff = average(squareDiffs);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standardDeviation.js","sourceRoot":"","sources":["../../src/Math/standardDeviation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAgB,EAAU,EAAE;IAC5D,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE5B,kDAAkD;IAClD,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACvC,MAAM,IAAI,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"standardDeviation.js","sourceRoot":"","sources":["../../src/Math/standardDeviation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAgB,EAAU,EAAE;IAC5D,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE5B,kDAAkD;IAClD,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACvC,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAClC,OAAO,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,gDAAgD;IAChD,MAAM,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAE3C,yDAAyD;IACzD,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AAClC,CAAC,CAAC"}
|
package/module/Object/has.js
CHANGED
|
@@ -11,8 +11,7 @@ export const has = (object, path) => {
|
|
|
11
11
|
const localPath = typeof path === "string" ? path.split(".") : path;
|
|
12
12
|
let current = { ...object };
|
|
13
13
|
for (const key of localPath) {
|
|
14
|
-
if (current == null ||
|
|
15
|
-
!Object.prototype.hasOwnProperty.call(current, key)) {
|
|
14
|
+
if (current == null || !Object.hasOwn(current, key)) {
|
|
16
15
|
return false;
|
|
17
16
|
}
|
|
18
17
|
current = current[key];
|
package/module/Object/has.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has.js","sourceRoot":"","sources":["../../src/Object/has.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CACjB,MAAS,EACT,IAAuB,EACd,EAAE;IACX,MAAM,SAAS,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACpE,IAAI,OAAO,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAC5B,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;QAC5B,
|
|
1
|
+
{"version":3,"file":"has.js","sourceRoot":"","sources":["../../src/Object/has.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CACjB,MAAS,EACT,IAAuB,EACd,EAAE;IACX,MAAM,SAAS,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACpE,IAAI,OAAO,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAC5B,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;QAC5B,IAAI,OAAO,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;YACpD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,GAAG,CAAM,CAAC;IAC9B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
package/module/Object/index.d.ts
CHANGED
package/module/Object/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Object/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Object/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if an object is empty (has no own properties)
|
|
3
|
+
* @param object - The object to check
|
|
4
|
+
* @returns true if the object is empty, false otherwise
|
|
5
|
+
*/
|
|
6
|
+
export const isEmpty = (object) => {
|
|
7
|
+
// Check enumerable string keys
|
|
8
|
+
for (const key in object) {
|
|
9
|
+
if (Object.hasOwn(object, key)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// Check symbol properties
|
|
14
|
+
const symbolKeys = Object.getOwnPropertySymbols(object);
|
|
15
|
+
if (symbolKeys.length > 0) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=isEmpty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isEmpty.js","sourceRoot":"","sources":["../../src/Object/isEmpty.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAA+B,EAAW,EAAE;IAClE,+BAA+B;IAC/B,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACzB,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;YAC/B,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,0BAA0B;IAC1B,MAAM,UAAU,GAAG,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACxD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UnionToIntersection } from "../types/logic/unionToIntersection";
|
|
2
|
+
/**
|
|
3
|
+
* Merges multiple objects into a single object (shallow merge)
|
|
4
|
+
* @param target - The target object to merge into
|
|
5
|
+
* @param sources - The source objects to merge from
|
|
6
|
+
* @returns The merged object
|
|
7
|
+
*/
|
|
8
|
+
export declare const merge: <T extends Record<string, unknown>, U extends Record<string, unknown>[]>(target: T, ...sources: U) => T & UnionToIntersection<U[number]>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merges multiple objects into a single object (shallow merge)
|
|
3
|
+
* @param target - The target object to merge into
|
|
4
|
+
* @param sources - The source objects to merge from
|
|
5
|
+
* @returns The merged object
|
|
6
|
+
*/
|
|
7
|
+
export const merge = (target, ...sources) => {
|
|
8
|
+
return Object.assign({}, target, ...sources);
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/Object/merge.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAInB,MAAS,EACT,GAAG,OAAU,EACuB,EAAE;IACtC,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;AAC/C,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UnionToIntersection } from "../types/logic/unionToIntersection";
|
|
2
|
+
/**
|
|
3
|
+
* Deeply merges multiple objects into a single object
|
|
4
|
+
* @param target - The target object to merge into
|
|
5
|
+
* @param sources - The source objects to merge from
|
|
6
|
+
* @returns The deeply merged object
|
|
7
|
+
*/
|
|
8
|
+
export declare const mergeDeep: <T extends Record<string, unknown>, U extends Record<string, unknown>[]>(target: T, ...sources: U) => T & UnionToIntersection<U[number]>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a value is a plain object
|
|
3
|
+
*/
|
|
4
|
+
const isPlainObject = (value) => {
|
|
5
|
+
return (value !== null &&
|
|
6
|
+
typeof value === "object" &&
|
|
7
|
+
value.constructor === Object &&
|
|
8
|
+
Object.prototype.toString.call(value) === "[object Object]");
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Deeply merges multiple objects into a single object
|
|
12
|
+
* @param target - The target object to merge into
|
|
13
|
+
* @param sources - The source objects to merge from
|
|
14
|
+
* @returns The deeply merged object
|
|
15
|
+
*/
|
|
16
|
+
export const mergeDeep = (target, ...sources) => {
|
|
17
|
+
if (sources.length === 0) {
|
|
18
|
+
return target;
|
|
19
|
+
}
|
|
20
|
+
const source = sources.shift();
|
|
21
|
+
if (isPlainObject(target) && isPlainObject(source)) {
|
|
22
|
+
const result = { ...target };
|
|
23
|
+
for (const key in source) {
|
|
24
|
+
if (Object.hasOwn(source, key)) {
|
|
25
|
+
const sourceValue = source[key];
|
|
26
|
+
const targetValue = result[key];
|
|
27
|
+
result[key] =
|
|
28
|
+
isPlainObject(targetValue) && isPlainObject(sourceValue)
|
|
29
|
+
? mergeDeep(targetValue, sourceValue)
|
|
30
|
+
: sourceValue;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return mergeDeep(result, ...sources);
|
|
34
|
+
}
|
|
35
|
+
return mergeDeep(source, ...sources);
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=mergeDeep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeDeep.js","sourceRoot":"","sources":["../../src/Object/mergeDeep.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,aAAa,GAAG,CAAC,KAAc,EAAoC,EAAE;IACzE,OAAO,CACL,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,CAAC,WAAW,KAAK,MAAM;QAC5B,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAC5D,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAIvB,MAAS,EACT,GAAG,OAAU,EACuB,EAAE;IACtC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,MAA4C,CAAC;IACtD,CAAC;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAE/B,IAAI,aAAa,CAAC,MAAM,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;QAE7B,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;YACzB,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;gBAC/B,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;gBAChC,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;gBAE/B,MAAkC,CAAC,GAAG,CAAC;oBACtC,aAAa,CAAC,WAAW,CAAC,IAAI,aAAa,CAAC,WAAW,CAAC;wBACtD,CAAC,CAAC,SAAS,CACP,WAAsC,EACtC,WAAsC,CACvC;wBACH,CAAC,CAAC,WAAW,CAAC;YACpB,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC,MAAM,EAAE,GAAG,OAAO,CAAuC,CAAC;IAC7E,CAAC;IAED,OAAO,SAAS,CAAC,MAAW,EAAE,GAAG,OAAO,CACR,CAAC;AACnC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an object without the specified keys
|
|
3
|
+
* @param object - The source object
|
|
4
|
+
* @param keys - The keys to omit
|
|
5
|
+
* @returns A new object without the specified keys
|
|
6
|
+
*/
|
|
7
|
+
export declare const omit: <T extends object, K extends keyof T>(object: T, ...keys: K[]) => Omit<T, K>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an object without the specified keys
|
|
3
|
+
* @param object - The source object
|
|
4
|
+
* @param keys - The keys to omit
|
|
5
|
+
* @returns A new object without the specified keys
|
|
6
|
+
*/
|
|
7
|
+
export const omit = (object, ...keys) => {
|
|
8
|
+
const result = { ...object };
|
|
9
|
+
for (const key of keys) {
|
|
10
|
+
delete result[key];
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=omit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omit.js","sourceRoot":"","sources":["../../src/Object/omit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,MAAS,EACT,GAAG,IAAS,EACA,EAAE;IACd,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAE7B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -7,7 +7,7 @@ import type { PickDeepKey } from "../types/object/pickDeepKey";
|
|
|
7
7
|
* @template K - Type of property keys to select. Must be a subset of PickDeepKey<T>.
|
|
8
8
|
* @param {T} object - The source object to extract properties from.
|
|
9
9
|
* @param {...K[]} keys - Property keys to extract. Can use dot notation for nested properties.
|
|
10
|
-
* @returns {PickDeep<T>} A new object containing only the specified properties.
|
|
10
|
+
* @returns {PickDeep<T, K>} A new object containing only the specified properties.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```typescript
|
|
@@ -16,4 +16,4 @@ import type { PickDeepKey } from "../types/object/pickDeepKey";
|
|
|
16
16
|
* // picked will be { a: { b: { c: 1 } }, f: 4 }
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
export declare const pickDeep: <T extends object, K extends PickDeepKey<T
|
|
19
|
+
export declare const pickDeep: <T extends object, const K extends readonly PickDeepKey<T>[]>(object: T, ...keys: K) => PickDeep<T, K>;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @template K - Type of property keys to select. Must be a subset of PickDeepKey<T>.
|
|
6
6
|
* @param {T} object - The source object to extract properties from.
|
|
7
7
|
* @param {...K[]} keys - Property keys to extract. Can use dot notation for nested properties.
|
|
8
|
-
* @returns {PickDeep<T>} A new object containing only the specified properties.
|
|
8
|
+
* @returns {PickDeep<T, K>} A new object containing only the specified properties.
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```typescript
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
17
|
export const pickDeep = (object, ...keys) => {
|
|
18
|
-
// biome-ignore lint/suspicious/noExplicitAny:
|
|
18
|
+
// biome-ignore lint/suspicious/noExplicitAny: ignore
|
|
19
19
|
const result = {};
|
|
20
20
|
for (const key of keys) {
|
|
21
21
|
const parts = key.split(".");
|
|
22
|
-
// biome-ignore lint/suspicious/noExplicitAny:
|
|
22
|
+
// biome-ignore lint/suspicious/noExplicitAny: ignore
|
|
23
23
|
let current = { ...object };
|
|
24
|
-
// biome-ignore lint/suspicious/noExplicitAny:
|
|
24
|
+
// biome-ignore lint/suspicious/noExplicitAny: ignore
|
|
25
25
|
let target = result;
|
|
26
26
|
for (const [index, part] of parts.entries()) {
|
|
27
27
|
if (current && typeof current === "object" && part in current) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pickDeep.js","sourceRoot":"","sources":["../../src/Object/pickDeep.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,
|
|
1
|
+
{"version":3,"file":"pickDeep.js","sourceRoot":"","sources":["../../src/Object/pickDeep.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAItB,MAAS,EACT,GAAG,IAAO,EACM,EAAE;IAClB,qDAAqD;IACrD,MAAM,MAAM,GAAQ,EAAE,CAAC;IAEvB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,KAAK,GAAI,GAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACzC,qDAAqD;QACrD,IAAI,OAAO,GAAQ,EAAE,GAAG,MAAM,EAAE,CAAC;QACjC,qDAAqD;QACrD,IAAI,MAAM,GAAQ,MAAM,CAAC;QAEzB,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC5C,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,IAAI,IAAI,OAAO,EAAE,CAAC;gBAC9D,IAAI,KAAK,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC/B,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;gBAC/B,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;oBAClC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;oBACxB,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -4,20 +4,20 @@ function dayOfWeekSimple(properties, timeDifference = 9) {
|
|
|
4
4
|
if (properties.includes(":")) {
|
|
5
5
|
const [year, mon, day] = properties
|
|
6
6
|
.split(":")
|
|
7
|
-
// biome-ignore lint/suspicious/noExplicitAny:
|
|
7
|
+
// biome-ignore lint/suspicious/noExplicitAny: ignore
|
|
8
8
|
.map(Number);
|
|
9
9
|
return dayOfWeek({ year, mon, day }, timeDifference);
|
|
10
10
|
}
|
|
11
11
|
if (properties.includes("/")) {
|
|
12
12
|
const [year, mon, day] = properties
|
|
13
13
|
.split("/")
|
|
14
|
-
// biome-ignore lint/suspicious/noExplicitAny:
|
|
14
|
+
// biome-ignore lint/suspicious/noExplicitAny: ignore
|
|
15
15
|
.map(Number);
|
|
16
16
|
return dayOfWeek({ year, mon, day }, timeDifference);
|
|
17
17
|
}
|
|
18
18
|
const [year, mon, day] = properties
|
|
19
19
|
.split("-")
|
|
20
|
-
// biome-ignore lint/suspicious/noExplicitAny:
|
|
20
|
+
// biome-ignore lint/suspicious/noExplicitAny: ignore
|
|
21
21
|
.map(Number);
|
|
22
22
|
return dayOfWeek({ year, mon, day }, timeDifference);
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dayOfWeekSimple.js","sourceRoot":"","sources":["../../../src/Simple/Date/dayOfWeekSimple.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AA8B7C,SAAS,eAAe,CAOtB,UAyBQ,EACR,iBAA+B,CAAC;IAEhC,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,UAAU;iBAChC,KAAK,CAAC,GAAG,CAAC;gBACX,
|
|
1
|
+
{"version":3,"file":"dayOfWeekSimple.js","sourceRoot":"","sources":["../../../src/Simple/Date/dayOfWeekSimple.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AA8B7C,SAAS,eAAe,CAOtB,UAyBQ,EACR,iBAA+B,CAAC;IAEhC,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,UAAU;iBAChC,KAAK,CAAC,GAAG,CAAC;gBACX,qDAAqD;iBACpD,GAAG,CAAC,MAAM,CAAQ,CAAC;YACtB,OAAO,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;QACvD,CAAC;QACD,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,UAAU;iBAChC,KAAK,CAAC,GAAG,CAAC;gBACX,qDAAqD;iBACpD,GAAG,CAAC,MAAM,CAAQ,CAAC;YACtB,OAAO,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;QACvD,CAAC;QACD,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,UAAU;aAChC,KAAK,CAAC,GAAG,CAAC;YACX,qDAAqD;aACpD,GAAG,CAAC,MAAM,CAAQ,CAAC;QACtB,OAAO,SAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,UAAU,YAAY,IAAI,EAAE,CAAC;QAC/B,OAAO,SAAS,CACd;YACE,IAAI,EAAE,UAAU,CAAC,WAAW,EAAE;YAC9B,GAAG,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAER;YACvB,GAAG,EAAE,UAAU,CAAC,OAAO,EAEtB;SACF,EACD,cAAc,CACf,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CACd,UAIC,EACD,cAAc,CACf,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string to camelCase
|
|
3
|
+
* @param str - The string to convert
|
|
4
|
+
* @returns The camelCase string
|
|
5
|
+
*/
|
|
6
|
+
export const camelCase = (string_) => {
|
|
7
|
+
return string_
|
|
8
|
+
.replaceAll(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase())
|
|
9
|
+
.replaceAll(/[^a-zA-Z0-9]+$/g, "")
|
|
10
|
+
.replace(/^[A-Z]/, (char) => char.toLowerCase());
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=camelCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camelCase.js","sourceRoot":"","sources":["../../src/String/camelCase.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAe,EAAU,EAAE;IACnD,OAAO,OAAO;SACX,UAAU,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;SAChE,UAAU,CAAC,iBAAiB,EAAE,EAAE,CAAC;SACjC,OAAO,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;AACrD,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML entities map for escaping
|
|
3
|
+
*/
|
|
4
|
+
const htmlEscapeMap = {
|
|
5
|
+
"&": "&",
|
|
6
|
+
"<": "<",
|
|
7
|
+
">": ">",
|
|
8
|
+
'"': """,
|
|
9
|
+
"'": "'",
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Escapes HTML special characters in a string
|
|
13
|
+
* @param str - The string to escape
|
|
14
|
+
* @returns The escaped string
|
|
15
|
+
*/
|
|
16
|
+
export const escapeHtml = (string_) => {
|
|
17
|
+
return string_.replaceAll(/[&<>"']/g, (match) => htmlEscapeMap[match]);
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=escapeHtml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escapeHtml.js","sourceRoot":"","sources":["../../src/String/escapeHtml.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,aAAa,GAA2B;IAC5C,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,OAAO;CACb,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAe,EAAU,EAAE;IACpD,OAAO,OAAO,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;AACzE,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Formatter } from "../../types/string/formatString/formatter";
|
|
2
|
+
/**
|
|
3
|
+
* Applies a formatter function to a value with optional arguments.
|
|
4
|
+
*
|
|
5
|
+
* Parses formatter syntax like "upper", "currency(ja-JP,JPY)", "pad(4,0)" and applies
|
|
6
|
+
* the corresponding formatter function with parsed arguments.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The value to format
|
|
9
|
+
* @param formatterString - Formatter name with optional arguments (e.g., "upper", "currency(ja-JP,JPY)")
|
|
10
|
+
* @param formatters - Available formatter functions
|
|
11
|
+
* @returns Formatted string, or original string value if formatter not found/invalid
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Simple formatter
|
|
15
|
+
* applyFormatter("hello", "upper", { upper: (v) => String(v).toUpperCase() }) // → "HELLO"
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Formatter with arguments
|
|
19
|
+
* applyFormatter(42, "pad(4,0)", { pad: (v, len, char) => String(v).padStart(+len, char) }) // → "0042"
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Invalid formatter returns original value
|
|
23
|
+
* applyFormatter("test", "invalid!@#", {}) // → "test"
|
|
24
|
+
*/
|
|
25
|
+
export declare function applyFormatter(value: unknown, formatterString: string, formatters: Record<string, Formatter>): string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies a formatter function to a value with optional arguments.
|
|
3
|
+
*
|
|
4
|
+
* Parses formatter syntax like "upper", "currency(ja-JP,JPY)", "pad(4,0)" and applies
|
|
5
|
+
* the corresponding formatter function with parsed arguments.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The value to format
|
|
8
|
+
* @param formatterString - Formatter name with optional arguments (e.g., "upper", "currency(ja-JP,JPY)")
|
|
9
|
+
* @param formatters - Available formatter functions
|
|
10
|
+
* @returns Formatted string, or original string value if formatter not found/invalid
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Simple formatter
|
|
14
|
+
* applyFormatter("hello", "upper", { upper: (v) => String(v).toUpperCase() }) // → "HELLO"
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Formatter with arguments
|
|
18
|
+
* applyFormatter(42, "pad(4,0)", { pad: (v, len, char) => String(v).padStart(+len, char) }) // → "0042"
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Invalid formatter returns original value
|
|
22
|
+
* applyFormatter("test", "invalid!@#", {}) // → "test"
|
|
23
|
+
*/
|
|
24
|
+
export function applyFormatter(value, formatterString, formatters) {
|
|
25
|
+
const match = formatterString.match(/^(\w+)(?:\(([^)]*)\))?$/);
|
|
26
|
+
if (!match) {
|
|
27
|
+
return String(value);
|
|
28
|
+
}
|
|
29
|
+
const [, formatterName, argumentsString] = match;
|
|
30
|
+
const formatter = formatters[formatterName];
|
|
31
|
+
if (!formatter) {
|
|
32
|
+
return String(value);
|
|
33
|
+
}
|
|
34
|
+
const arguments_ = argumentsString ? parseArguments(argumentsString) : [];
|
|
35
|
+
return formatter(value, ...arguments_);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Parses comma-separated arguments while preserving quoted strings
|
|
39
|
+
* @param argumentsString - String containing comma-separated arguments
|
|
40
|
+
* @returns Array of parsed arguments
|
|
41
|
+
*/
|
|
42
|
+
function parseArguments(argumentsString) {
|
|
43
|
+
const arguments_ = [];
|
|
44
|
+
let current = "";
|
|
45
|
+
let inQuotes = false;
|
|
46
|
+
let quoteChar = "";
|
|
47
|
+
for (const char of argumentsString) {
|
|
48
|
+
if (!inQuotes && (char === '"' || char === "'")) {
|
|
49
|
+
inQuotes = true;
|
|
50
|
+
quoteChar = char;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (inQuotes && char === quoteChar) {
|
|
54
|
+
inQuotes = false;
|
|
55
|
+
quoteChar = "";
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (!inQuotes && char === ",") {
|
|
59
|
+
const trimmed = current.trim();
|
|
60
|
+
arguments_.push(trimmed === "" ? " " : trimmed);
|
|
61
|
+
current = "";
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
current += char;
|
|
65
|
+
}
|
|
66
|
+
// Handle last argument
|
|
67
|
+
const trimmed = current.trim();
|
|
68
|
+
arguments_.push(trimmed === "" ? " " : trimmed);
|
|
69
|
+
return arguments_;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=applyFormatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyFormatter.js","sourceRoot":"","sources":["../../../src/String/formatString/applyFormatter.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAc,EACd,eAAuB,EACvB,UAAqC;IAErC,MAAM,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,EAAE,aAAa,EAAE,eAAe,CAAC,GAAG,KAAK,CAAC;IACjD,MAAM,SAAS,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IAE5C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAE1E,OAAO,SAAS,CAAC,KAAK,EAAE,GAAG,UAAU,CAAC,CAAC;AACzC,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,eAAuB;IAC7C,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,SAAS,GAAG,EAAE,CAAC;IAEnB,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;QACnC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YAChD,QAAQ,GAAG,IAAI,CAAC;YAChB,SAAS,GAAG,IAAI,CAAC;YACjB,SAAS;QACX,CAAC;QAED,IAAI,QAAQ,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACnC,QAAQ,GAAG,KAAK,CAAC;YACjB,SAAS,GAAG,EAAE,CAAC;YACf,SAAS;QACX,CAAC;QAED,IAAI,CAAC,QAAQ,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YAC9B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;YAC/B,UAAU,CAAC,IAAI,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YAChD,OAAO,GAAG,EAAE,CAAC;YACb,SAAS;QACX,CAAC;QAED,OAAO,IAAI,IAAI,CAAC;IAClB,CAAC;IAED,uBAAuB;IACvB,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/B,UAAU,CAAC,IAAI,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAEhD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Formatter } from "../../types/string/formatString/formatter";
|
|
2
|
+
/**
|
|
3
|
+
* Built-in formatter functions for formatString.
|
|
4
|
+
*
|
|
5
|
+
* Each formatter takes a value and optional arguments, returning a formatted string.
|
|
6
|
+
* Formatters are used with syntax like {value:formatterName} or {value:formatterName(arg1,arg2)}.
|
|
7
|
+
*
|
|
8
|
+
* Available formatters:
|
|
9
|
+
* - upper: Convert to uppercase
|
|
10
|
+
* - lower: Convert to lowercase
|
|
11
|
+
* - currency: Format as currency with locale support
|
|
12
|
+
* - date: Format dates with locale and format options
|
|
13
|
+
* - time: Format time with locale support
|
|
14
|
+
* - number: Format numbers with precision control
|
|
15
|
+
* - plural: Choose singular/plural form based on count
|
|
16
|
+
* - pad: Pad string with characters to specified length
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Usage in formatString
|
|
20
|
+
* formatString("{name:upper}", { name: "alice" }) // → "ALICE"
|
|
21
|
+
* formatString("{price:currency(ja-JP,JPY)}", { price: 1000 }) // → "¥1,000"
|
|
22
|
+
* formatString("{count:plural(item,items)}", { count: 1 }) // → "item"
|
|
23
|
+
*/
|
|
24
|
+
export declare const defaultFormatters: Record<string, Formatter>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in formatter functions for formatString.
|
|
3
|
+
*
|
|
4
|
+
* Each formatter takes a value and optional arguments, returning a formatted string.
|
|
5
|
+
* Formatters are used with syntax like {value:formatterName} or {value:formatterName(arg1,arg2)}.
|
|
6
|
+
*
|
|
7
|
+
* Available formatters:
|
|
8
|
+
* - upper: Convert to uppercase
|
|
9
|
+
* - lower: Convert to lowercase
|
|
10
|
+
* - currency: Format as currency with locale support
|
|
11
|
+
* - date: Format dates with locale and format options
|
|
12
|
+
* - time: Format time with locale support
|
|
13
|
+
* - number: Format numbers with precision control
|
|
14
|
+
* - plural: Choose singular/plural form based on count
|
|
15
|
+
* - pad: Pad string with characters to specified length
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Usage in formatString
|
|
19
|
+
* formatString("{name:upper}", { name: "alice" }) // → "ALICE"
|
|
20
|
+
* formatString("{price:currency(ja-JP,JPY)}", { price: 1000 }) // → "¥1,000"
|
|
21
|
+
* formatString("{count:plural(item,items)}", { count: 1 }) // → "item"
|
|
22
|
+
*/
|
|
23
|
+
export const defaultFormatters = {
|
|
24
|
+
upper: (value) => String(value).toUpperCase(),
|
|
25
|
+
lower: (value) => String(value).toLowerCase(),
|
|
26
|
+
currency: (value, locale = "en-US", currency = "USD") => {
|
|
27
|
+
return new Intl.NumberFormat(locale, {
|
|
28
|
+
style: "currency",
|
|
29
|
+
currency,
|
|
30
|
+
}).format(Number(value));
|
|
31
|
+
},
|
|
32
|
+
date: (value, locale = "en-US", format = "short") => {
|
|
33
|
+
const date = value instanceof Date ? value : new Date(String(value));
|
|
34
|
+
if (format === "iso") {
|
|
35
|
+
return date.toISOString();
|
|
36
|
+
}
|
|
37
|
+
if (format === "time") {
|
|
38
|
+
return date.toLocaleTimeString(locale);
|
|
39
|
+
}
|
|
40
|
+
return date.toLocaleDateString(locale);
|
|
41
|
+
},
|
|
42
|
+
time: (value, locale = "en-US") => {
|
|
43
|
+
const date = value instanceof Date ? value : new Date(String(value));
|
|
44
|
+
return date.toLocaleTimeString(locale);
|
|
45
|
+
},
|
|
46
|
+
number: (value, locale = "en-US", minimumFractionDigits = "0", maximumFractionDigits = "20") => {
|
|
47
|
+
return new Intl.NumberFormat(locale, {
|
|
48
|
+
minimumFractionDigits: Number(minimumFractionDigits),
|
|
49
|
+
maximumFractionDigits: Number(maximumFractionDigits),
|
|
50
|
+
}).format(Number(value));
|
|
51
|
+
},
|
|
52
|
+
plural: (value, singular, plural) => {
|
|
53
|
+
return Number(value) === 1 ? singular : plural;
|
|
54
|
+
},
|
|
55
|
+
pad: (value, length = "2", char = "0") => {
|
|
56
|
+
return String(value).padStart(Number(length), char);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=defaultFormatters.js.map
|