umt 2.5.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.
Files changed (268) hide show
  1. package/README.md +11 -0
  2. package/module/Array/generateNumberArray.js +13 -7
  3. package/module/Array/generateNumberArray.js.map +1 -1
  4. package/module/Array/getArraysCommon.js +21 -3
  5. package/module/Array/getArraysCommon.js.map +1 -1
  6. package/module/Array/groupBy.js +1 -1
  7. package/module/Array/groupBy.js.map +1 -1
  8. package/module/Array/index.d.ts +2 -0
  9. package/module/Array/index.js +2 -0
  10. package/module/Array/index.js.map +1 -1
  11. package/module/Array/ultraNumberSort.js +2 -2
  12. package/module/Array/ultraNumberSort.js.map +1 -1
  13. package/module/Array/uniqBy.d.ts +7 -0
  14. package/module/Array/uniqBy.js +19 -0
  15. package/module/Array/uniqBy.js.map +1 -0
  16. package/module/Array/unique.d.ts +6 -0
  17. package/module/Array/unique.js +9 -0
  18. package/module/Array/unique.js.map +1 -0
  19. package/module/Color/rgbaToHsla.js +1 -1
  20. package/module/Color/rgbaToHsla.js.map +1 -1
  21. package/module/Date/birthday.js +14 -6
  22. package/module/Date/birthday.js.map +1 -1
  23. package/module/Date/isLeapYear.js +3 -0
  24. package/module/Date/isLeapYear.js.map +1 -1
  25. package/module/Error/index.d.ts +1 -0
  26. package/module/Error/index.js +1 -0
  27. package/module/Error/index.js.map +1 -1
  28. package/module/Error/retry.d.ts +37 -0
  29. package/module/Error/retry.js +47 -0
  30. package/module/Error/retry.js.map +1 -0
  31. package/module/IP/getIpClass.js +1 -1
  32. package/module/IP/getIpClass.js.map +1 -1
  33. package/module/IP/getNetworkAddress.js +2 -2
  34. package/module/IP/getNetworkAddress.js.map +1 -1
  35. package/module/IP/ipToBinaryString.js +2 -2
  36. package/module/IP/ipToBinaryString.js.map +1 -1
  37. package/module/IP/subnetMaskToCidr.js +1 -1
  38. package/module/IP/subnetMaskToCidr.js.map +1 -1
  39. package/module/Math/calculator/core.js +21 -13
  40. package/module/Math/calculator/core.js.map +1 -1
  41. package/module/Math/calculator/literalExpression.js +19 -7
  42. package/module/Math/calculator/literalExpression.js.map +1 -1
  43. package/module/Math/division.js +3 -3
  44. package/module/Math/division.js.map +1 -1
  45. package/module/Math/gcd.js +26 -4
  46. package/module/Math/gcd.js.map +1 -1
  47. package/module/Math/standardDeviation.js +4 -2
  48. package/module/Math/standardDeviation.js.map +1 -1
  49. package/module/Object/has.js +1 -2
  50. package/module/Object/has.js.map +1 -1
  51. package/module/Object/index.d.ts +4 -0
  52. package/module/Object/index.js +4 -0
  53. package/module/Object/index.js.map +1 -1
  54. package/module/Object/isEmpty.d.ts +6 -0
  55. package/module/Object/isEmpty.js +20 -0
  56. package/module/Object/isEmpty.js.map +1 -0
  57. package/module/Object/merge.d.ts +8 -0
  58. package/module/Object/merge.js +10 -0
  59. package/module/Object/merge.js.map +1 -0
  60. package/module/Object/mergeDeep.d.ts +8 -0
  61. package/module/Object/mergeDeep.js +37 -0
  62. package/module/Object/mergeDeep.js.map +1 -0
  63. package/module/Object/omit.d.ts +7 -0
  64. package/module/Object/omit.js +14 -0
  65. package/module/Object/omit.js.map +1 -0
  66. package/module/Object/pickDeep.d.ts +2 -2
  67. package/module/Object/pickDeep.js +4 -4
  68. package/module/Object/pickDeep.js.map +1 -1
  69. package/module/Simple/Date/dayOfWeekSimple.js +3 -3
  70. package/module/Simple/Date/dayOfWeekSimple.js.map +1 -1
  71. package/module/String/camelCase.d.ts +6 -0
  72. package/module/String/camelCase.js +12 -0
  73. package/module/String/camelCase.js.map +1 -0
  74. package/module/String/escapeHtml.d.ts +6 -0
  75. package/module/String/escapeHtml.js +19 -0
  76. package/module/String/escapeHtml.js.map +1 -0
  77. package/module/String/formatString/applyFormatter.d.ts +25 -0
  78. package/module/String/formatString/applyFormatter.js +71 -0
  79. package/module/String/formatString/applyFormatter.js.map +1 -0
  80. package/module/String/formatString/defaultFormatters.d.ts +24 -0
  81. package/module/String/formatString/defaultFormatters.js +59 -0
  82. package/module/String/formatString/defaultFormatters.js.map +1 -0
  83. package/module/String/formatString/detectMode.d.ts +26 -0
  84. package/module/String/formatString/detectMode.js +61 -0
  85. package/module/String/formatString/detectMode.js.map +1 -0
  86. package/module/String/formatString/getValue.d.ts +27 -0
  87. package/module/String/formatString/getValue.js +56 -0
  88. package/module/String/formatString/getValue.js.map +1 -0
  89. package/module/String/formatString/index.d.ts +91 -0
  90. package/module/String/formatString/index.js +38 -0
  91. package/module/String/formatString/index.js.map +1 -0
  92. package/module/String/index.d.ts +5 -0
  93. package/module/String/index.js +5 -0
  94. package/module/String/index.js.map +1 -1
  95. package/module/String/kebabCase.d.ts +6 -0
  96. package/module/String/kebabCase.js +22 -0
  97. package/module/String/kebabCase.js.map +1 -0
  98. package/module/String/levenshteinDistance.d.ts +8 -0
  99. package/module/String/levenshteinDistance.js +38 -0
  100. package/module/String/levenshteinDistance.js.map +1 -0
  101. package/module/String/stringSimilarity.d.ts +8 -0
  102. package/module/String/stringSimilarity.js +23 -0
  103. package/module/String/stringSimilarity.js.map +1 -0
  104. package/module/Validate/core/index.js +0 -1
  105. package/module/Validate/core/index.js.map +1 -1
  106. package/module/Validate/isDouble.js +1 -1
  107. package/module/Validate/isDouble.js.map +1 -1
  108. package/module/Validate/isNode.js +1 -0
  109. package/module/Validate/isNode.js.map +1 -1
  110. package/module/Validate/isNumber.js +1 -1
  111. package/module/Validate/isNumber.js.map +1 -1
  112. package/module/Validate/isValueNaN.js +1 -1
  113. package/module/Validate/isValueNaN.js.map +1 -1
  114. package/module/Validate/number/even.js +7 -1
  115. package/module/Validate/number/even.js.map +1 -1
  116. package/module/Validate/number/odd.js +7 -1
  117. package/module/Validate/number/odd.js.map +1 -1
  118. package/module/Validate/string/email.js +20 -2
  119. package/module/Validate/string/email.js.map +1 -1
  120. package/module/es5/Array/generateNumberArray.js +15 -9
  121. package/module/es5/Array/getArraysCommon.js +39 -4
  122. package/module/es5/Array/groupBy.js +1 -1
  123. package/module/es5/Array/index.d.ts +2 -0
  124. package/module/es5/Array/index.js +22 -0
  125. package/module/es5/Array/ultraNumberSort.js +2 -2
  126. package/module/es5/Array/uniqBy.d.ts +7 -0
  127. package/module/es5/Array/uniqBy.js +36 -0
  128. package/module/es5/Array/unique.d.ts +6 -0
  129. package/module/es5/Array/unique.js +20 -0
  130. package/module/es5/Color/rgbaToHsla.js +1 -1
  131. package/module/es5/Date/birthday.js +17 -3
  132. package/module/es5/Date/isLeapYear.js +3 -0
  133. package/module/es5/Error/index.d.ts +1 -0
  134. package/module/es5/Error/index.js +11 -0
  135. package/module/es5/Error/retry.d.ts +37 -0
  136. package/module/es5/Error/retry.js +88 -0
  137. package/module/es5/IP/getIpClass.js +1 -1
  138. package/module/es5/IP/getNetworkAddress.js +2 -2
  139. package/module/es5/IP/ipToBinaryString.js +2 -2
  140. package/module/es5/IP/subnetMaskToCidr.js +1 -1
  141. package/module/es5/Math/calculator/core.js +17 -9
  142. package/module/es5/Math/calculator/literalExpression.js +19 -6
  143. package/module/es5/Math/division.js +3 -3
  144. package/module/es5/Math/gcd.js +43 -5
  145. package/module/es5/Math/standardDeviation.js +4 -2
  146. package/module/es5/Object/has.js +1 -1
  147. package/module/es5/Object/index.d.ts +4 -0
  148. package/module/es5/Object/index.js +44 -0
  149. package/module/es5/Object/isEmpty.d.ts +6 -0
  150. package/module/es5/Object/isEmpty.js +26 -0
  151. package/module/es5/Object/merge.d.ts +8 -0
  152. package/module/es5/Object/merge.js +18 -0
  153. package/module/es5/Object/mergeDeep.d.ts +8 -0
  154. package/module/es5/Object/mergeDeep.js +46 -0
  155. package/module/es5/Object/omit.d.ts +7 -0
  156. package/module/es5/Object/omit.js +29 -0
  157. package/module/es5/Object/pickDeep.d.ts +2 -2
  158. package/module/es5/Object/pickDeep.js +4 -4
  159. package/module/es5/Simple/Date/dayOfWeekSimple.js +3 -3
  160. package/module/es5/String/camelCase.d.ts +6 -0
  161. package/module/es5/String/camelCase.js +18 -0
  162. package/module/es5/String/escapeHtml.d.ts +6 -0
  163. package/module/es5/String/escapeHtml.js +27 -0
  164. package/module/es5/String/formatString/applyFormatter.d.ts +25 -0
  165. package/module/es5/String/formatString/applyFormatter.js +100 -0
  166. package/module/es5/String/formatString/defaultFormatters.d.ts +24 -0
  167. package/module/es5/String/formatString/defaultFormatters.js +79 -0
  168. package/module/es5/String/formatString/detectMode.d.ts +26 -0
  169. package/module/es5/String/formatString/detectMode.js +60 -0
  170. package/module/es5/String/formatString/getValue.d.ts +27 -0
  171. package/module/es5/String/formatString/getValue.js +85 -0
  172. package/module/es5/String/formatString/index.d.ts +91 -0
  173. package/module/es5/String/formatString/index.js +152 -0
  174. package/module/es5/String/index.d.ts +5 -0
  175. package/module/es5/String/index.js +55 -0
  176. package/module/es5/String/kebabCase.d.ts +6 -0
  177. package/module/es5/String/kebabCase.js +26 -0
  178. package/module/es5/String/levenshteinDistance.d.ts +8 -0
  179. package/module/es5/String/levenshteinDistance.js +58 -0
  180. package/module/es5/String/stringSimilarity.d.ts +8 -0
  181. package/module/es5/String/stringSimilarity.js +30 -0
  182. package/module/es5/Validate/core/index.js +0 -1
  183. package/module/es5/Validate/isDouble.js +1 -1
  184. package/module/es5/Validate/isNode.js +1 -0
  185. package/module/es5/Validate/isNumber.js +1 -1
  186. package/module/es5/Validate/isValueNaN.js +1 -1
  187. package/module/es5/Validate/number/even.js +4 -0
  188. package/module/es5/Validate/number/odd.js +4 -0
  189. package/module/es5/Validate/string/email.js +26 -1
  190. package/module/es5/tsconfig.tsbuildinfo +1 -1
  191. package/module/es5/types/index.d.ts +1 -0
  192. package/module/es5/types/index.js +11 -0
  193. package/module/es5/types/logic/deepPartial.d.ts +37 -0
  194. package/module/es5/types/logic/deepPartial.js +5 -0
  195. package/module/es5/types/logic/deepRequired.d.ts +37 -0
  196. package/module/es5/types/logic/deepRequired.js +5 -0
  197. package/module/es5/types/logic/index.d.ts +3 -0
  198. package/module/es5/types/logic/index.js +33 -0
  199. package/module/es5/types/logic/unionToIntersection.d.ts +12 -0
  200. package/module/es5/types/logic/unionToIntersection.js +5 -0
  201. package/module/es5/types/object/index.d.ts +1 -0
  202. package/module/es5/types/object/index.js +11 -0
  203. package/module/es5/types/object/pickDeep.d.ts +13 -1
  204. package/module/es5/types/object/shallowObjectValue.d.ts +9 -0
  205. package/module/es5/types/object/shallowObjectValue.js +5 -0
  206. package/module/es5/types/string/formatString/formatData.d.ts +17 -0
  207. package/module/es5/types/string/formatString/formatData.js +5 -0
  208. package/module/es5/types/string/formatString/formatOptions.d.ts +21 -0
  209. package/module/es5/types/string/formatString/formatOptions.js +5 -0
  210. package/module/es5/types/string/formatString/formatString.d.ts +4 -0
  211. package/module/es5/types/string/formatString/formatString.js +49 -0
  212. package/module/es5/types/string/formatString/formatValue.d.ts +15 -0
  213. package/module/es5/types/string/formatString/formatValue.js +5 -0
  214. package/module/es5/types/string/formatString/formatter.d.ts +13 -0
  215. package/module/es5/types/string/formatString/formatter.js +5 -0
  216. package/module/es5/types/string/formatString/index.d.ts +5 -0
  217. package/module/es5/types/string/formatString/index.js +60 -0
  218. package/module/es5/types/string/index.d.ts +1 -0
  219. package/module/es5/types/string/index.js +16 -0
  220. package/module/types/index.d.ts +1 -0
  221. package/module/types/index.js +1 -0
  222. package/module/types/index.js.map +1 -1
  223. package/module/types/logic/deepPartial.d.ts +37 -0
  224. package/module/types/logic/deepPartial.js +36 -0
  225. package/module/types/logic/deepPartial.js.map +1 -0
  226. package/module/types/logic/deepRequired.d.ts +37 -0
  227. package/module/types/logic/deepRequired.js +2 -0
  228. package/module/types/logic/deepRequired.js.map +1 -0
  229. package/module/types/logic/index.d.ts +3 -0
  230. package/module/types/logic/index.js +3 -0
  231. package/module/types/logic/index.js.map +1 -1
  232. package/module/types/logic/unionToIntersection.d.ts +12 -0
  233. package/module/types/logic/unionToIntersection.js +2 -0
  234. package/module/types/logic/unionToIntersection.js.map +1 -0
  235. package/module/types/object/index.d.ts +1 -0
  236. package/module/types/object/index.js +1 -0
  237. package/module/types/object/index.js.map +1 -1
  238. package/module/types/object/pickDeep.d.ts +13 -1
  239. package/module/types/object/shallowObjectValue.d.ts +9 -0
  240. package/module/types/object/shallowObjectValue.js +2 -0
  241. package/module/types/object/shallowObjectValue.js.map +1 -0
  242. package/module/types/string/formatString/formatData.d.ts +17 -0
  243. package/module/types/string/formatString/formatData.js +2 -0
  244. package/module/types/string/formatString/formatData.js.map +1 -0
  245. package/module/types/string/formatString/formatOptions.d.ts +21 -0
  246. package/module/types/string/formatString/formatOptions.js +2 -0
  247. package/module/types/string/formatString/formatOptions.js.map +1 -0
  248. package/module/types/string/formatString/formatString.d.ts +4 -0
  249. package/module/types/string/formatString/formatString.js +5 -0
  250. package/module/types/string/formatString/formatString.js.map +1 -0
  251. package/module/types/string/formatString/formatValue.d.ts +15 -0
  252. package/module/types/string/formatString/formatValue.js +2 -0
  253. package/module/types/string/formatString/formatValue.js.map +1 -0
  254. package/module/types/string/formatString/formatter.d.ts +13 -0
  255. package/module/types/string/formatString/formatter.js +2 -0
  256. package/module/types/string/formatString/formatter.js.map +1 -0
  257. package/module/types/string/formatString/index.d.ts +5 -0
  258. package/module/types/string/formatString/index.js +6 -0
  259. package/module/types/string/formatString/index.js.map +1 -0
  260. package/module/types/string/index.d.ts +1 -0
  261. package/module/types/string/index.js +2 -0
  262. package/module/types/string/index.js.map +1 -0
  263. package/package.json +31 -32
  264. package/module/String/formatString.d.ts +0 -13
  265. package/module/String/formatString.js +0 -18
  266. package/module/String/formatString.js.map +0 -1
  267. package/module/es5/String/formatString.d.ts +0 -13
  268. package/module/es5/String/formatString.js +0 -26
@@ -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,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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":[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AC;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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"./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";
@@ -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";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/String/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/String/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Converts a string to kebab-case
3
+ * @param str - The string to convert
4
+ * @returns The kebab-case string
5
+ */
6
+ export declare const kebabCase: (string_: string) => string;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Converts a string to kebab-case
3
+ * @param str - The string to convert
4
+ * @returns The kebab-case string
5
+ */
6
+ export const kebabCase = (string_) => {
7
+ return (string_
8
+ // Insert dash between lowercase and uppercase
9
+ .replaceAll(/([a-z])([A-Z])/g, "$1-$2")
10
+ // Insert dash between sequences of uppercase letters and following lowercase
11
+ .replaceAll(/([A-Z])([A-Z][a-z])/g, "$1-$2")
12
+ // Replace spaces and underscores with dashes
13
+ .replaceAll(/[\s_]+/g, "-")
14
+ // Remove special characters except alphanumeric and dashes
15
+ .replaceAll(/[^a-zA-Z0-9-]/g, "-")
16
+ // Remove multiple consecutive dashes
17
+ .replaceAll(/-+/g, "-")
18
+ // Remove leading and trailing dashes
19
+ .replaceAll(/^-|-$/g, "")
20
+ .toLowerCase());
21
+ };
22
+ //# sourceMappingURL=kebabCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kebabCase.js","sourceRoot":"","sources":["../../src/String/kebabCase.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAe,EAAU,EAAE;IACnD,OAAO,CACL,OAAO;QACL,8CAA8C;SAC7C,UAAU,CAAC,iBAAiB,EAAE,OAAO,CAAC;QACvC,6EAA6E;SAC5E,UAAU,CAAC,sBAAsB,EAAE,OAAO,CAAC;QAC5C,6CAA6C;SAC5C,UAAU,CAAC,SAAS,EAAE,GAAG,CAAC;QAC3B,2DAA2D;SAC1D,UAAU,CAAC,gBAAgB,EAAE,GAAG,CAAC;QAClC,qCAAqC;SACpC,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC;QACvB,qCAAqC;SACpC,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC;SACxB,WAAW,EAAE,CACjB,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Calculates the Levenshtein distance between two strings
3
+ * Returns the minimum number of single-character edits (insertions, deletions, or substitutions)
4
+ * @param str1 - First string to compare
5
+ * @param str2 - Second string to compare
6
+ * @returns The Levenshtein distance
7
+ */
8
+ export declare const levenshteinDistance: (string1: string, string2: string) => number;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Calculates the Levenshtein distance between two strings
3
+ * Returns the minimum number of single-character edits (insertions, deletions, or substitutions)
4
+ * @param str1 - First string to compare
5
+ * @param str2 - Second string to compare
6
+ * @returns The Levenshtein distance
7
+ */
8
+ export const levenshteinDistance = (string1, string2) => {
9
+ const length1 = string1.length;
10
+ const length2 = string2.length;
11
+ // Return the length of the other string if one is empty
12
+ if (length1 === 0) {
13
+ return length2;
14
+ }
15
+ if (length2 === 0) {
16
+ return length1;
17
+ }
18
+ // Create a 2D array for dynamic programming
19
+ const matrix = Array.from({ length: length1 + 1 }, () => Array.from({ length: length2 + 1 }, () => 0));
20
+ // Initialize first column and row
21
+ for (let index = 0; index <= length1; index++) {
22
+ matrix[index][0] = index;
23
+ }
24
+ for (let index = 0; index <= length2; index++) {
25
+ matrix[0][index] = index;
26
+ }
27
+ // Calculate distances
28
+ for (let index = 1; index <= length1; index++) {
29
+ for (let index_ = 1; index_ <= length2; index_++) {
30
+ const cost = string1[index - 1] === string2[index_ - 1] ? 0 : 1;
31
+ matrix[index][index_] = Math.min(matrix[index - 1][index_] + 1, // deletion
32
+ matrix[index][index_ - 1] + 1, // insertion
33
+ matrix[index - 1][index_ - 1] + cost);
34
+ }
35
+ }
36
+ return matrix[length1][length2];
37
+ };
38
+ //# sourceMappingURL=levenshteinDistance.js.map