umt 2.4.0 → 2.6.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 +288 -16
- 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 +8 -7
- package/module/Array/groupBy.js.map +1 -1
- package/module/Array/index.d.ts +3 -0
- package/module/Array/index.js +3 -0
- package/module/Array/index.js.map +1 -1
- package/module/Array/timSort.js +2 -20
- package/module/Array/timSort.js.map +1 -1
- package/module/Array/ultraNumberSort.d.ts +7 -0
- package/module/Array/ultraNumberSort.js +373 -0
- package/module/Array/ultraNumberSort.js.map +1 -0
- 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/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/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/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/index.d.ts +5 -0
- package/module/String/index.js +5 -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/stringSimilarity.d.ts +8 -0
- package/module/String/stringSimilarity.js +23 -0
- package/module/String/stringSimilarity.js.map +1 -0
- package/module/Tool/pipe.d.ts +1 -1
- package/module/Tool/pipe.js.map +1 -1
- package/module/Validate/core/index.js +0 -1
- package/module/Validate/core/index.js.map +1 -1
- 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 +8 -7
- package/module/es5/Array/index.d.ts +3 -0
- package/module/es5/Array/index.js +33 -0
- package/module/es5/Array/timSort.js +2 -20
- package/module/es5/Array/ultraNumberSort.d.ts +7 -0
- package/module/es5/Array/ultraNumberSort.js +475 -0
- 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/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/division.js +3 -3
- package/module/es5/Math/gcd.js +43 -5
- 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/index.d.ts +5 -0
- package/module/es5/String/index.js +55 -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/stringSimilarity.d.ts +8 -0
- package/module/es5/String/stringSimilarity.js +30 -0
- package/module/es5/Tool/pipe.d.ts +1 -1
- package/module/es5/Validate/core/index.js +0 -1
- 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/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/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 +31 -32
- 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
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultFormatters.js","sourceRoot":"","sources":["../../../src/String/formatString/defaultFormatters.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA8B;IAC1D,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE;IAC7C,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE;IAE7C,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,QAAQ,GAAG,KAAK,EAAE,EAAE;QACtD,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;YACnC,KAAK,EAAE,UAAU;YACjB,QAAQ;SACT,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,MAAM,GAAG,OAAO,EAAE,EAAE;QAClD,MAAM,IAAI,GAAG,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACrE,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;QAC5B,CAAC;QACD,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,EAAE;QAChC,MAAM,IAAI,GAAG,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,MAAM,EAAE,CACN,KAAK,EACL,MAAM,GAAG,OAAO,EAChB,qBAAqB,GAAG,GAAG,EAC3B,qBAAqB,GAAG,IAAI,EAC5B,EAAE;QACF,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;YACnC,qBAAqB,EAAE,MAAM,CAAC,qBAAqB,CAAC;YACpD,qBAAqB,EAAE,MAAM,CAAC,qBAAqB,CAAC;SACrD,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED,MAAM,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE;QAClC,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;IACjD,CAAC;IAED,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,GAAG,GAAG,EAAE,EAAE;QACvC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FormatData } from "../../types/string/formatString/formatData";
|
|
2
|
+
import type { FormatOptions } from "../../types/string/formatString/formatOptions";
|
|
3
|
+
import type { FormatValue } from "../../types/string/formatString/formatValue";
|
|
4
|
+
/**
|
|
5
|
+
* Detects whether formatString should use indexed or named mode based on arguments.
|
|
6
|
+
*
|
|
7
|
+
* Named mode: First argument is a non-array object
|
|
8
|
+
* Indexed mode: Arguments are treated as array values
|
|
9
|
+
*
|
|
10
|
+
* @param dataOrFirstValue - First argument (object for named mode, value for indexed mode)
|
|
11
|
+
* @param optionsOrSecondValue - Second argument (options for named mode, value for indexed mode)
|
|
12
|
+
* @param restValues - Remaining arguments for indexed mode
|
|
13
|
+
* @returns Object containing data and options for formatting
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Named mode detection
|
|
17
|
+
* detectMode({ name: "Alice" }) // → { data: { name: "Alice" }, options: {} }
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Indexed mode detection
|
|
21
|
+
* detectMode("first", "second") // → { data: ["first", "second"], options: {} }
|
|
22
|
+
*/
|
|
23
|
+
export declare function detectMode(dataOrFirstValue: FormatData | FormatValue | undefined, optionsOrSecondValue: FormatOptions | FormatValue | undefined, restValues: FormatValue[]): {
|
|
24
|
+
data: unknown;
|
|
25
|
+
options: FormatOptions;
|
|
26
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects whether formatString should use indexed or named mode based on arguments.
|
|
3
|
+
*
|
|
4
|
+
* Named mode: First argument is a non-array object
|
|
5
|
+
* Indexed mode: Arguments are treated as array values
|
|
6
|
+
*
|
|
7
|
+
* @param dataOrFirstValue - First argument (object for named mode, value for indexed mode)
|
|
8
|
+
* @param optionsOrSecondValue - Second argument (options for named mode, value for indexed mode)
|
|
9
|
+
* @param restValues - Remaining arguments for indexed mode
|
|
10
|
+
* @returns Object containing data and options for formatting
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Named mode detection
|
|
14
|
+
* detectMode({ name: "Alice" }) // → { data: { name: "Alice" }, options: {} }
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Indexed mode detection
|
|
18
|
+
* detectMode("first", "second") // → { data: ["first", "second"], options: {} }
|
|
19
|
+
*/
|
|
20
|
+
export function detectMode(dataOrFirstValue, optionsOrSecondValue, restValues) {
|
|
21
|
+
const isFirstArgumentObject = dataOrFirstValue !== undefined &&
|
|
22
|
+
typeof dataOrFirstValue === "object" &&
|
|
23
|
+
dataOrFirstValue !== null &&
|
|
24
|
+
!Array.isArray(dataOrFirstValue) &&
|
|
25
|
+
!(dataOrFirstValue instanceof Date);
|
|
26
|
+
const isSecondArgumentOptions = optionsOrSecondValue !== undefined &&
|
|
27
|
+
typeof optionsOrSecondValue === "object" &&
|
|
28
|
+
optionsOrSecondValue !== null &&
|
|
29
|
+
!Array.isArray(optionsOrSecondValue) &&
|
|
30
|
+
!(optionsOrSecondValue instanceof Date) &&
|
|
31
|
+
"formatters" in optionsOrSecondValue;
|
|
32
|
+
if (isFirstArgumentObject &&
|
|
33
|
+
optionsOrSecondValue === undefined &&
|
|
34
|
+
restValues.length === 0) {
|
|
35
|
+
return {
|
|
36
|
+
data: dataOrFirstValue,
|
|
37
|
+
options: {},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (isFirstArgumentObject &&
|
|
41
|
+
isSecondArgumentOptions &&
|
|
42
|
+
restValues.length === 0) {
|
|
43
|
+
return {
|
|
44
|
+
data: dataOrFirstValue,
|
|
45
|
+
options: optionsOrSecondValue,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const allValues = [];
|
|
49
|
+
if (dataOrFirstValue !== undefined) {
|
|
50
|
+
allValues.push(dataOrFirstValue);
|
|
51
|
+
}
|
|
52
|
+
if (optionsOrSecondValue !== undefined) {
|
|
53
|
+
allValues.push(optionsOrSecondValue);
|
|
54
|
+
}
|
|
55
|
+
allValues.push(...restValues);
|
|
56
|
+
return {
|
|
57
|
+
data: allValues,
|
|
58
|
+
options: {},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=detectMode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectMode.js","sourceRoot":"","sources":["../../../src/String/formatString/detectMode.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,UAAU,CACxB,gBAAsD,EACtD,oBAA6D,EAC7D,UAAyB;IAKzB,MAAM,qBAAqB,GACzB,gBAAgB,KAAK,SAAS;QAC9B,OAAO,gBAAgB,KAAK,QAAQ;QACpC,gBAAgB,KAAK,IAAI;QACzB,CAAC,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC;QAChC,CAAC,CAAC,gBAAgB,YAAY,IAAI,CAAC,CAAC;IAEtC,MAAM,uBAAuB,GAC3B,oBAAoB,KAAK,SAAS;QAClC,OAAO,oBAAoB,KAAK,QAAQ;QACxC,oBAAoB,KAAK,IAAI;QAC7B,CAAC,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC;QACpC,CAAC,CAAC,oBAAoB,YAAY,IAAI,CAAC;QACvC,YAAY,IAAI,oBAAoB,CAAC;IAEvC,IACE,qBAAqB;QACrB,oBAAoB,KAAK,SAAS;QAClC,UAAU,CAAC,MAAM,KAAK,CAAC,EACvB,CAAC;QACD,OAAO;YACL,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,EAAE;SACZ,CAAC;IACJ,CAAC;IAED,IACE,qBAAqB;QACrB,uBAAuB;QACvB,UAAU,CAAC,MAAM,KAAK,CAAC,EACvB,CAAC;QACD,OAAO;YACL,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,oBAAoB;SAC9B,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAc,EAAE,CAAC;IAChC,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;QACnC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACnC,CAAC;IACD,IAAI,oBAAoB,KAAK,SAAS,EAAE,CAAC;QACvC,SAAS,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACvC,CAAC;IACD,SAAS,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;IAE9B,OAAO;QACL,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,EAAE;KACZ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves a value from an object using a dot-notation path with array index support.
|
|
3
|
+
*
|
|
4
|
+
* Supports nested properties and array access with positive/negative indices.
|
|
5
|
+
*
|
|
6
|
+
* @param object - The object to retrieve the value from
|
|
7
|
+
* @param path - Dot-notation path (e.g., "user.name", "items[0]", "data[0].items[-1].name")
|
|
8
|
+
* @returns The value at the specified path, or undefined if not found
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Simple property access
|
|
12
|
+
* getValue({ name: "Alice" }, "name") // → "Alice"
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Nested property access
|
|
16
|
+
* getValue({ user: { name: "Bob" } }, "user.name") // → "Bob"
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Array access
|
|
20
|
+
* getValue({ items: ["A", "B", "C"] }, "items[0]") // → "A"
|
|
21
|
+
* getValue({ items: ["A", "B", "C"] }, "items[-1]") // → "C"
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Complex nested access
|
|
25
|
+
* getValue({ users: [{ name: "Alice" }] }, "users[0].name") // → "Alice"
|
|
26
|
+
*/
|
|
27
|
+
export declare function getValue(object: unknown, path: string): unknown;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves a value from an object using a dot-notation path with array index support.
|
|
3
|
+
*
|
|
4
|
+
* Supports nested properties and array access with positive/negative indices.
|
|
5
|
+
*
|
|
6
|
+
* @param object - The object to retrieve the value from
|
|
7
|
+
* @param path - Dot-notation path (e.g., "user.name", "items[0]", "data[0].items[-1].name")
|
|
8
|
+
* @returns The value at the specified path, or undefined if not found
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Simple property access
|
|
12
|
+
* getValue({ name: "Alice" }, "name") // → "Alice"
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Nested property access
|
|
16
|
+
* getValue({ user: { name: "Bob" } }, "user.name") // → "Bob"
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Array access
|
|
20
|
+
* getValue({ items: ["A", "B", "C"] }, "items[0]") // → "A"
|
|
21
|
+
* getValue({ items: ["A", "B", "C"] }, "items[-1]") // → "C"
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* // Complex nested access
|
|
25
|
+
* getValue({ users: [{ name: "Alice" }] }, "users[0].name") // → "Alice"
|
|
26
|
+
*/
|
|
27
|
+
export function getValue(object, path) {
|
|
28
|
+
const segments = [];
|
|
29
|
+
const parts = path.split(".");
|
|
30
|
+
for (const part of parts) {
|
|
31
|
+
const arrayMatch = part.match(/^(.+?)\[(-?\d+)\]$/);
|
|
32
|
+
if (arrayMatch) {
|
|
33
|
+
const [, key, indexString] = arrayMatch;
|
|
34
|
+
segments.push({ key, index: Number(indexString) });
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
segments.push({ key: part });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
let current = object;
|
|
41
|
+
for (const segment of segments) {
|
|
42
|
+
if (typeof current !== "object" || current == null) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
current = current[segment.key];
|
|
46
|
+
if (segment.index !== undefined) {
|
|
47
|
+
if (!Array.isArray(current)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const index = segment.index;
|
|
51
|
+
current = index < 0 ? current[current.length + index] : current[index];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return current;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=getValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getValue.js","sourceRoot":"","sources":["../../../src/String/formatString/getValue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAe,EAAE,IAAY;IACpD,MAAM,QAAQ,GAA2C,EAAE,CAAC;IAE5D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE9B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACpD,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,GAAG,UAAU,CAAC;YACxC,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,IAAI,OAAO,GAAG,MAAM,CAAC;IAErB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACnD,OAAO;QACT,CAAC;QAED,OAAO,GAAI,OAAmC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAE5D,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC5B,OAAO;YACT,CAAC;YACD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;YAC5B,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { FormatData } from "../../types/string/formatString/formatData";
|
|
2
|
+
import type { FormatOptions } from "../../types/string/formatString/formatOptions";
|
|
3
|
+
import type { FormatValue } from "../../types/string/formatString/formatValue";
|
|
4
|
+
/**
|
|
5
|
+
* Replaces placeholders in a template string with specified values.
|
|
6
|
+
*
|
|
7
|
+
* Supports two modes:
|
|
8
|
+
* 1. **Indexed mode**: Use numbered placeholders like {0}, {1}, {2}...
|
|
9
|
+
* 2. **Named mode**: Use named placeholders with an object like {name}, {age}...
|
|
10
|
+
*
|
|
11
|
+
* ## Advanced Features
|
|
12
|
+
*
|
|
13
|
+
* ### Nested Object Access
|
|
14
|
+
* Access nested properties using dot notation: `{user.name}`, `{user.address.city}`
|
|
15
|
+
*
|
|
16
|
+
* ### Array Access
|
|
17
|
+
* Access array elements with brackets: `{items[0]}`, `{users[1].name}`
|
|
18
|
+
* Supports negative indices: `{items[-1]}` (last element), `{items[-2]}` (second to last)
|
|
19
|
+
*
|
|
20
|
+
* ### Default Values
|
|
21
|
+
* Provide fallback values using pipe syntax: `{name|Unknown}`, `{age|N/A}`
|
|
22
|
+
*
|
|
23
|
+
* ### Formatters
|
|
24
|
+
* Apply formatters to values: `{name:upper}`, `{price:currency}`, `{date:date}`
|
|
25
|
+
*
|
|
26
|
+
* Built-in formatters:
|
|
27
|
+
* - `upper` - Convert to uppercase
|
|
28
|
+
* - `lower` - Convert to lowercase
|
|
29
|
+
* - `currency(locale?, currency?)` - Format as currency (e.g., `{price:currency(ja-JP,JPY)}`)
|
|
30
|
+
* - `date(locale?, format?)` - Format dates (format: short|medium|long|full|iso|time)
|
|
31
|
+
* - `time(locale?)` - Format time
|
|
32
|
+
* - `number(locale?, minFraction?, maxFraction?)` - Format numbers
|
|
33
|
+
* - `plural(singular, plural)` - Pluralization (e.g., `{count:plural(item,items)}`)
|
|
34
|
+
* - `pad(length, char?)` - Pad string/number (e.g., `{id:pad(4,0)}`)
|
|
35
|
+
*
|
|
36
|
+
* ### Escape Sequences
|
|
37
|
+
* Use double braces to escape: `{{name}}` renders as literal `{name}`
|
|
38
|
+
*
|
|
39
|
+
* @param template - Template string containing placeholders
|
|
40
|
+
* @param data - Data object for named mode OR first value for indexed mode
|
|
41
|
+
* @param options - Options object with custom formatters (named mode only)
|
|
42
|
+
* @returns String with placeholders replaced with formatted values
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* // Indexed mode - basic replacement
|
|
46
|
+
* formatString("Hello, {0}! It's {1} today.", "World", "sunny");
|
|
47
|
+
* // → "Hello, World! It's sunny today."
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* // Named mode - object properties
|
|
51
|
+
* formatString("Hello, {name}! You are {age} years old.", { name: "Alice", age: 25 });
|
|
52
|
+
* // → "Hello, Alice! You are 25 years old."
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // Nested object access
|
|
56
|
+
* formatString("User: {user.name}, Email: {user.email}", {
|
|
57
|
+
* user: { name: "Charlie", email: "charlie@example.com" }
|
|
58
|
+
* });
|
|
59
|
+
* // → "User: Charlie, Email: charlie@example.com"
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // Array access with negative indices
|
|
63
|
+
* formatString("First: {items[0]}, Last: {items[-1]}", { items: ["A", "B", "C"] });
|
|
64
|
+
* // → "First: A, Last: C"
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* // Default values
|
|
68
|
+
* formatString("Name: {name|Unknown}, Age: {age|N/A}", { age: 25 });
|
|
69
|
+
* // → "Name: Unknown, Age: 25"
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Built-in formatters
|
|
73
|
+
* formatString("Price: {price:currency(ja-JP,JPY)}", { price: 1234 });
|
|
74
|
+
* // → "Price: ¥1,234"
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* // Custom formatters
|
|
78
|
+
* formatString("Reversed: {text:reverse}", { text: "hello" }, {
|
|
79
|
+
* formatters: {
|
|
80
|
+
* reverse: (value) => String(value).split("").reverse().join("")
|
|
81
|
+
* }
|
|
82
|
+
* });
|
|
83
|
+
* // → "Reversed: olleh"
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* // Escape sequences
|
|
87
|
+
* formatString("Literal {{name}} and value {name}", { name: "Alice" });
|
|
88
|
+
* // → "Literal {name} and value Alice"
|
|
89
|
+
*/
|
|
90
|
+
export declare function formatString(template: string, data?: FormatData, options?: FormatOptions): string;
|
|
91
|
+
export declare function formatString(template: string, ...values: FormatValue[]): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { applyFormatter } from "./applyFormatter";
|
|
2
|
+
import { defaultFormatters } from "./defaultFormatters";
|
|
3
|
+
import { detectMode } from "./detectMode";
|
|
4
|
+
import { getValue } from "./getValue";
|
|
5
|
+
export function formatString(template, dataOrFirstValue, optionsOrSecondValue, ...restValues) {
|
|
6
|
+
const escapedTemplate = template
|
|
7
|
+
.replaceAll("{{", "\u0000")
|
|
8
|
+
.replaceAll("}}", "\u0001");
|
|
9
|
+
const { data, options } = detectMode(dataOrFirstValue, optionsOrSecondValue, restValues);
|
|
10
|
+
const formatters = { ...defaultFormatters, ...options.formatters };
|
|
11
|
+
const result = escapedTemplate.replaceAll(/{([^}]+)}/g, (match, content) => {
|
|
12
|
+
const [pathAndFormatter, defaultValue] = content
|
|
13
|
+
.split("|")
|
|
14
|
+
.map((part) => part.trim());
|
|
15
|
+
const [path, ...formatterParts] = pathAndFormatter.split(":");
|
|
16
|
+
const formatterString = formatterParts.join(":");
|
|
17
|
+
let value;
|
|
18
|
+
if (Array.isArray(data)) {
|
|
19
|
+
const index = Number(path);
|
|
20
|
+
value = Number.isNaN(index) ? undefined : data[index];
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
value = getValue(data, path);
|
|
24
|
+
}
|
|
25
|
+
if (value === undefined || value === null) {
|
|
26
|
+
if (defaultValue === undefined) {
|
|
27
|
+
return match;
|
|
28
|
+
}
|
|
29
|
+
value = defaultValue;
|
|
30
|
+
}
|
|
31
|
+
if (formatterString) {
|
|
32
|
+
return applyFormatter(value, formatterString, formatters);
|
|
33
|
+
}
|
|
34
|
+
return String(value);
|
|
35
|
+
});
|
|
36
|
+
return result.replaceAll("\u0000", "{").replaceAll("\u0001", "}");
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/String/formatString/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAqGtC,MAAM,UAAU,YAAY,CAC1B,QAAgB,EAChB,gBAA2C,EAC3C,oBAAkD,EAClD,GAAG,UAAyB;IAE5B,MAAM,eAAe,GAAG,QAAQ;SAC7B,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC;SAC1B,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAE9B,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAClC,gBAAgB,EAChB,oBAAoB,EACpB,UAAU,CACX,CAAC;IAEF,MAAM,UAAU,GAAG,EAAE,GAAG,iBAAiB,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAEnE,MAAM,MAAM,GAAG,eAAe,CAAC,UAAU,CACvC,YAAY,EACZ,CAAC,KAAK,EAAE,OAAe,EAAE,EAAE;QACzB,MAAM,CAAC,gBAAgB,EAAE,YAAY,CAAC,GAAG,OAAO;aAC7C,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,IAAI,EAAE,GAAG,cAAc,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9D,MAAM,eAAe,GAAG,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAEjD,IAAI,KAAc,CAAC;QACnB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YAC3B,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/B,CAAC;QAED,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAC1C,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;gBAC/B,OAAO,KAAK,CAAC;YACf,CAAC;YACD,KAAK,GAAG,YAAY,CAAC;QACvB,CAAC;QAED,IAAI,eAAe,EAAE,CAAC;YACpB,OAAO,cAAc,CAAC,KAAK,EAAE,eAAe,EAAE,UAAU,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AACpE,CAAC"}
|
package/module/String/index.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
export * from "./camelCase";
|
|
1
2
|
export * from "./deleteSpaces";
|
|
3
|
+
export * from "./escapeHtml";
|
|
2
4
|
export * from "./formatString";
|
|
3
5
|
export * from "./fromBase64";
|
|
4
6
|
export * from "./hasNoLetters";
|
|
7
|
+
export * from "./kebabCase";
|
|
8
|
+
export * from "./levenshteinDistance";
|
|
5
9
|
export * from "./padEnd";
|
|
6
10
|
export * from "./padStart";
|
|
7
11
|
export * from "./randomString";
|
|
8
12
|
export * from "./randomStringInitialization";
|
|
9
13
|
export * from "./reverseString";
|
|
14
|
+
export * from "./stringSimilarity";
|
|
10
15
|
export * from "./toBase64";
|
|
11
16
|
export * from "./toHalfWidth";
|
|
12
17
|
export * from "./trimCharacters";
|
package/module/String/index.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
export * from "./camelCase";
|
|
1
2
|
export * from "./deleteSpaces";
|
|
3
|
+
export * from "./escapeHtml";
|
|
2
4
|
export * from "./formatString";
|
|
3
5
|
export * from "./fromBase64";
|
|
4
6
|
export * from "./hasNoLetters";
|
|
7
|
+
export * from "./kebabCase";
|
|
8
|
+
export * from "./levenshteinDistance";
|
|
5
9
|
export * from "./padEnd";
|
|
6
10
|
export * from "./padStart";
|
|
7
11
|
export * from "./randomString";
|
|
8
12
|
export * from "./randomStringInitialization";
|
|
9
13
|
export * from "./reverseString";
|
|
14
|
+
export * from "./stringSimilarity";
|
|
10
15
|
export * from "./toBase64";
|
|
11
16
|
export * from "./toHalfWidth";
|
|
12
17
|
export * from "./trimCharacters";
|