@arkyn/shared 1.4.52 → 2.0.1-beta.1

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 (219) hide show
  1. package/dist/formats/__test__/formatDate.spec.d.ts +2 -0
  2. package/dist/formats/__test__/formatDate.spec.d.ts.map +1 -0
  3. package/dist/formats/__test__/formatDate.spec.js +41 -0
  4. package/dist/formats/__test__/formatJsonObject.spec.d.ts +2 -0
  5. package/dist/formats/__test__/formatJsonObject.spec.d.ts.map +1 -0
  6. package/dist/formats/__test__/formatJsonObject.spec.js +76 -0
  7. package/dist/formats/__test__/formatJsonString.spec.d.ts +2 -0
  8. package/dist/formats/__test__/formatJsonString.spec.d.ts.map +1 -0
  9. package/dist/formats/__test__/formatJsonString.spec.js +71 -0
  10. package/dist/formats/__test__/formatToCep.spec.d.ts +2 -0
  11. package/dist/formats/__test__/formatToCep.spec.d.ts.map +1 -0
  12. package/dist/formats/__test__/formatToCep.spec.js +30 -0
  13. package/dist/formats/__test__/formatToCnpj.spec.d.ts +2 -0
  14. package/dist/formats/__test__/formatToCnpj.spec.d.ts.map +1 -0
  15. package/dist/formats/__test__/formatToCnpj.spec.js +27 -0
  16. package/dist/formats/__test__/formatToCpfCnpj.spec.d.ts +2 -0
  17. package/dist/formats/__test__/formatToCpfCnpj.spec.d.ts.map +1 -0
  18. package/dist/formats/__test__/formatToCpfCnpj.spec.js +32 -0
  19. package/dist/formats/__test__/formatToCurrency.spec.d.ts +2 -0
  20. package/dist/formats/__test__/formatToCurrency.spec.d.ts.map +1 -0
  21. package/dist/formats/__test__/formatToCurrency.spec.js +39 -0
  22. package/dist/formats/__test__/formatToEllipsis.spec.d.ts +2 -0
  23. package/dist/formats/__test__/formatToEllipsis.spec.d.ts.map +1 -0
  24. package/dist/formats/__test__/formatToEllipsis.spec.js +36 -0
  25. package/dist/formats/__test__/formatToHiddenDigits.spec.d.ts +2 -0
  26. package/dist/formats/__test__/formatToHiddenDigits.spec.d.ts.map +1 -0
  27. package/dist/formats/__test__/formatToHiddenDigits.spec.js +47 -0
  28. package/dist/formats/__test__/formatToPhone.spec.d.ts +2 -0
  29. package/dist/formats/__test__/formatToPhone.spec.d.ts.map +1 -0
  30. package/dist/formats/__test__/formatToPhone.spec.js +38 -0
  31. package/dist/formats/formatDate.d.ts +43 -0
  32. package/dist/formats/formatDate.d.ts.map +1 -0
  33. package/dist/formats/formatDate.js +77 -0
  34. package/dist/formats/formatJsonObject.d.ts +31 -1
  35. package/dist/formats/formatJsonObject.d.ts.map +1 -1
  36. package/dist/formats/formatJsonObject.js +67 -26
  37. package/dist/formats/formatJsonString.d.ts +37 -1
  38. package/dist/formats/formatJsonString.d.ts.map +1 -1
  39. package/dist/formats/formatJsonString.js +38 -4
  40. package/dist/formats/formatToCep.d.ts +27 -1
  41. package/dist/formats/formatToCep.d.ts.map +1 -1
  42. package/dist/formats/formatToCep.js +31 -6
  43. package/dist/formats/formatToCnpj.d.ts +30 -0
  44. package/dist/formats/formatToCnpj.d.ts.map +1 -0
  45. package/dist/formats/formatToCnpj.js +35 -0
  46. package/dist/formats/formatToCpf.d.ts +30 -0
  47. package/dist/formats/formatToCpf.d.ts.map +1 -0
  48. package/dist/formats/formatToCpf.js +35 -0
  49. package/dist/formats/formatToCpfCnpj.d.ts +22 -1
  50. package/dist/formats/formatToCpfCnpj.d.ts.map +1 -1
  51. package/dist/formats/formatToCpfCnpj.js +27 -7
  52. package/dist/formats/formatToCurrency.d.ts +29 -0
  53. package/dist/formats/formatToCurrency.d.ts.map +1 -0
  54. package/dist/formats/formatToCurrency.js +41 -0
  55. package/dist/formats/formatToEllipsis.d.ts +14 -1
  56. package/dist/formats/formatToEllipsis.d.ts.map +1 -1
  57. package/dist/formats/formatToEllipsis.js +20 -3
  58. package/dist/formats/formatToHiddenDigits.d.ts +30 -2
  59. package/dist/formats/formatToHiddenDigits.d.ts.map +1 -1
  60. package/dist/formats/formatToHiddenDigits.js +49 -3
  61. package/dist/formats/formatToPhone.d.ts +32 -1
  62. package/dist/formats/formatToPhone.d.ts.map +1 -1
  63. package/dist/formats/formatToPhone.js +128 -6
  64. package/dist/generators/__test__/generateColorByString.spec.d.ts +2 -0
  65. package/dist/generators/__test__/generateColorByString.spec.d.ts.map +1 -0
  66. package/dist/generators/__test__/generateColorByString.spec.js +31 -0
  67. package/dist/generators/__test__/generateId.spec.d.ts +2 -0
  68. package/dist/generators/__test__/generateId.spec.d.ts.map +1 -0
  69. package/dist/generators/__test__/generateId.spec.js +30 -0
  70. package/dist/generators/__test__/generateSlug.spec.d.ts +2 -0
  71. package/dist/generators/__test__/generateSlug.spec.d.ts.map +1 -0
  72. package/dist/generators/__test__/generateSlug.spec.js +38 -0
  73. package/dist/generators/generateColorByString.d.ts +13 -1
  74. package/dist/generators/generateColorByString.d.ts.map +1 -1
  75. package/dist/generators/generateColorByString.js +15 -4
  76. package/dist/generators/generateId.d.ts +26 -4
  77. package/dist/generators/generateId.d.ts.map +1 -1
  78. package/dist/generators/generateId.js +11 -5
  79. package/dist/generators/generateSlug.d.ts +15 -1
  80. package/dist/generators/generateSlug.d.ts.map +1 -1
  81. package/dist/generators/generateSlug.js +16 -2
  82. package/dist/index.d.ts +7 -10
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +7 -15
  85. package/dist/{validations/regex.d.ts → regex/index.d.ts} +1 -1
  86. package/dist/regex/index.d.ts.map +1 -0
  87. package/dist/services/__test__/calculateCardInstallment.spec.d.ts +2 -0
  88. package/dist/services/__test__/calculateCardInstallment.spec.d.ts.map +1 -0
  89. package/dist/services/__test__/calculateCardInstallment.spec.js +71 -0
  90. package/dist/services/__test__/maskSensitiveData.spec.d.ts +2 -0
  91. package/dist/services/__test__/maskSensitiveData.spec.d.ts.map +1 -0
  92. package/dist/services/__test__/maskSensitiveData.spec.js +79 -0
  93. package/dist/services/__test__/removeCurrencySymbols.spec.d.ts +2 -0
  94. package/dist/services/__test__/removeCurrencySymbols.spec.d.ts.map +1 -0
  95. package/dist/services/__test__/removeCurrencySymbols.spec.js +34 -0
  96. package/dist/services/__test__/removeNonNumeric.spec.d.ts +2 -0
  97. package/dist/services/__test__/removeNonNumeric.spec.d.ts.map +1 -0
  98. package/dist/services/__test__/removeNonNumeric.spec.js +27 -0
  99. package/dist/services/__test__/truncateLargeFields.spec.d.ts +2 -0
  100. package/dist/services/__test__/truncateLargeFields.spec.d.ts.map +1 -0
  101. package/dist/services/__test__/truncateLargeFields.spec.js +65 -0
  102. package/dist/services/calculateCardInstallment.d.ts +31 -5
  103. package/dist/services/calculateCardInstallment.d.ts.map +1 -1
  104. package/dist/services/calculateCardInstallment.js +52 -11
  105. package/dist/services/maskSensitiveData.d.ts +24 -1
  106. package/dist/services/maskSensitiveData.d.ts.map +1 -1
  107. package/dist/services/maskSensitiveData.js +24 -2
  108. package/dist/services/removeCurrencySymbols.d.ts +20 -0
  109. package/dist/services/removeCurrencySymbols.d.ts.map +1 -0
  110. package/dist/services/removeCurrencySymbols.js +23 -0
  111. package/dist/services/removeNonNumeric.d.ts +15 -0
  112. package/dist/services/removeNonNumeric.d.ts.map +1 -0
  113. package/dist/services/removeNonNumeric.js +16 -0
  114. package/dist/services/truncateLargeFields.d.ts +30 -1
  115. package/dist/services/truncateLargeFields.d.ts.map +1 -1
  116. package/dist/services/truncateLargeFields.js +34 -6
  117. package/dist/validations/__test__/validateCpf.spec.d.ts +2 -0
  118. package/dist/validations/__test__/validateCpf.spec.d.ts.map +1 -0
  119. package/dist/validations/__test__/validateCpf.spec.js +31 -0
  120. package/dist/validations/__test__/validateDate.spec.d.ts +2 -0
  121. package/dist/validations/__test__/validateDate.spec.d.ts.map +1 -0
  122. package/dist/validations/__test__/validateDate.spec.js +44 -0
  123. package/dist/validations/__test__/validatePhone.spec.d.ts +2 -0
  124. package/dist/validations/__test__/validatePhone.spec.d.ts.map +1 -0
  125. package/dist/validations/__test__/validatePhone.spec.js +32 -0
  126. package/dist/validations/validateCpf.d.ts +24 -0
  127. package/dist/validations/validateCpf.d.ts.map +1 -0
  128. package/dist/validations/validateCpf.js +56 -0
  129. package/dist/validations/validateDate.d.ts +27 -6
  130. package/dist/validations/validateDate.d.ts.map +1 -1
  131. package/dist/validations/validateDate.js +32 -6
  132. package/dist/validations/validatePhone.d.ts +27 -1
  133. package/dist/validations/validatePhone.d.ts.map +1 -1
  134. package/dist/validations/validatePhone.js +27 -2
  135. package/package.json +4 -2
  136. package/src/formats/__test__/formatDate.spec.ts +88 -0
  137. package/src/formats/__test__/formatJsonObject.spec.ts +87 -0
  138. package/src/formats/__test__/formatJsonString.spec.ts +83 -0
  139. package/src/formats/__test__/formatToCep.spec.ts +37 -0
  140. package/src/formats/__test__/formatToCnpj.spec.ts +35 -0
  141. package/src/formats/__test__/formatToCpfCnpj.spec.ts +43 -0
  142. package/src/formats/__test__/formatToCurrency.spec.ts +50 -0
  143. package/src/formats/__test__/formatToEllipsis.spec.ts +44 -0
  144. package/src/formats/__test__/formatToHiddenDigits.spec.ts +58 -0
  145. package/src/formats/__test__/formatToPhone.spec.ts +58 -0
  146. package/src/formats/formatDate.ts +97 -0
  147. package/src/formats/formatJsonObject.ts +68 -26
  148. package/src/formats/formatJsonString.ts +40 -4
  149. package/src/formats/formatToCep.ts +35 -7
  150. package/src/formats/formatToCnpj.ts +39 -0
  151. package/src/formats/formatToCpf.ts +39 -0
  152. package/src/formats/formatToCpfCnpj.ts +31 -7
  153. package/src/formats/formatToCurrency.ts +53 -0
  154. package/src/formats/formatToEllipsis.ts +23 -3
  155. package/src/formats/formatToHiddenDigits.ts +75 -7
  156. package/src/formats/formatToPhone.ts +156 -6
  157. package/src/generators/__test__/generateColorByString.spec.ts +37 -0
  158. package/src/generators/__test__/generateId.spec.ts +44 -0
  159. package/src/generators/__test__/generateSlug.spec.ts +47 -0
  160. package/src/generators/generateColorByString.ts +18 -4
  161. package/src/generators/generateId.ts +36 -5
  162. package/src/generators/generateSlug.ts +17 -2
  163. package/src/index.ts +7 -15
  164. package/src/services/__test__/calculateCardInstallment.spec.ts +87 -0
  165. package/src/services/__test__/maskSensitiveData.spec.ts +102 -0
  166. package/src/services/__test__/removeCurrencySymbols.spec.ts +41 -0
  167. package/src/services/__test__/removeNonNumeric.spec.ts +33 -0
  168. package/src/services/__test__/truncateLargeFields.spec.ts +90 -0
  169. package/src/services/calculateCardInstallment.ts +57 -12
  170. package/src/services/maskSensitiveData.ts +29 -4
  171. package/src/services/removeCurrencySymbols.ts +25 -0
  172. package/src/services/removeNonNumeric.ts +18 -0
  173. package/src/services/truncateLargeFields.ts +40 -6
  174. package/src/validations/__test__/validateCpf.spec.ts +38 -0
  175. package/src/validations/__test__/validateDate.spec.ts +81 -0
  176. package/src/validations/__test__/validatePhone.spec.ts +39 -0
  177. package/src/validations/validateCpf.ts +64 -0
  178. package/src/validations/validateDate.ts +33 -11
  179. package/src/validations/validatePhone.ts +29 -2
  180. package/vitest.config.ts +5 -0
  181. package/dist/formats/formatBrazilianDateHour.d.ts +0 -3
  182. package/dist/formats/formatBrazilianDateHour.d.ts.map +0 -1
  183. package/dist/formats/formatBrazilianDateHour.js +0 -12
  184. package/dist/formats/formatBrazilianDateToDate.d.ts +0 -3
  185. package/dist/formats/formatBrazilianDateToDate.d.ts.map +0 -1
  186. package/dist/formats/formatBrazilianDateToDate.js +0 -9
  187. package/dist/formats/formatDateHour.d.ts +0 -3
  188. package/dist/formats/formatDateHour.d.ts.map +0 -1
  189. package/dist/formats/formatDateHour.js +0 -11
  190. package/dist/formats/formatToBRL.d.ts +0 -3
  191. package/dist/formats/formatToBRL.d.ts.map +0 -1
  192. package/dist/formats/formatToBRL.js +0 -8
  193. package/dist/formats/formatToCNPJ.d.ts +0 -3
  194. package/dist/formats/formatToCNPJ.d.ts.map +0 -1
  195. package/dist/formats/formatToCNPJ.js +0 -9
  196. package/dist/formats/formatToCPF.d.ts +0 -3
  197. package/dist/formats/formatToCPF.d.ts.map +0 -1
  198. package/dist/formats/formatToCPF.js +0 -9
  199. package/dist/parsers/parseToCharacters.d.ts +0 -17
  200. package/dist/parsers/parseToCharacters.d.ts.map +0 -1
  201. package/dist/parsers/parseToCharacters.js +0 -13
  202. package/dist/services/range.d.ts +0 -4
  203. package/dist/services/range.d.ts.map +0 -1
  204. package/dist/services/range.js +0 -9
  205. package/dist/validations/regex.d.ts.map +0 -1
  206. package/dist/validations/validateCPF.d.ts +0 -3
  207. package/dist/validations/validateCPF.d.ts.map +0 -1
  208. package/dist/validations/validateCPF.js +0 -36
  209. package/src/formats/formatBrazilianDateHour.ts +0 -17
  210. package/src/formats/formatBrazilianDateToDate.ts +0 -13
  211. package/src/formats/formatDateHour.ts +0 -15
  212. package/src/formats/formatToBRL.ts +0 -10
  213. package/src/formats/formatToCNPJ.ts +0 -10
  214. package/src/formats/formatToCPF.ts +0 -10
  215. package/src/parsers/parseToCharacters.ts +0 -34
  216. package/src/services/range.ts +0 -15
  217. package/src/validations/validateCPF.ts +0 -38
  218. /package/dist/{validations/regex.js → regex/index.js} +0 -0
  219. /package/src/{validations/regex.ts → regex/index.ts} +0 -0
@@ -1,5 +1,19 @@
1
- function generateSlug(string) {
2
- let slug = string.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
1
+ /**
2
+ * Generates a URL-friendly slug from a given string.
3
+ *
4
+ * The function performs the following transformations:
5
+ * - Normalizes the string to remove diacritical marks (e.g., accents).
6
+ * - Removes non-alphanumeric characters except for spaces and hyphens.
7
+ * - Replaces spaces with hyphens.
8
+ * - Converts the string to lowercase.
9
+ * - Collapses multiple consecutive hyphens into a single hyphen.
10
+ * - Trims leading and trailing hyphens.
11
+ *
12
+ * @param string - The input string to be converted into a slug.
13
+ * @returns A URL-friendly slug derived from the input string.
14
+ */
15
+ function generateSlug(prop) {
16
+ let slug = prop.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
3
17
  slug = slug
4
18
  .replace(/[^\w\s-]/g, "")
5
19
  .replace(/\s+/g, "-")
package/dist/index.d.ts CHANGED
@@ -1,26 +1,23 @@
1
- export { formatBrazilianDateHour } from "./formats/formatBrazilianDateHour";
2
- export { formatBrazilianDateToDate } from "./formats/formatBrazilianDateToDate";
3
- export { formatDateHour } from "./formats/formatDateHour";
1
+ export { formatDate } from "./formats/formatDate";
4
2
  export { formatJsonObject } from "./formats/formatJsonObject";
5
3
  export { formatJsonString } from "./formats/formatJsonString";
6
- export { formatToBRL } from "./formats/formatToBRL";
7
4
  export { formatToCep } from "./formats/formatToCep";
8
- export { formatToCNPJ } from "./formats/formatToCNPJ";
9
- export { formatToCPF } from "./formats/formatToCPF";
5
+ export { formatToCnpj } from "./formats/formatToCnpj";
6
+ export { formatToCpf } from "./formats/formatToCpf";
10
7
  export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
8
+ export { formatToCurrency } from "./formats/formatToCurrency";
11
9
  export { formatToEllipsis } from "./formats/formatToEllipsis";
12
10
  export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
13
11
  export { formatToPhone } from "./formats/formatToPhone";
14
12
  export { generateColorByString } from "./generators/generateColorByString";
15
13
  export { generateId } from "./generators/generateId";
16
14
  export { generateSlug } from "./generators/generateSlug";
17
- export { parseToCharacters } from "./parsers/parseToCharacters";
15
+ export { regex } from "./regex";
18
16
  export { calculateCardInstallment } from "./services/calculateCardInstallment";
19
17
  export { maskSensitiveData } from "./services/maskSensitiveData";
20
- export { normalizeRange, within } from "./services/range";
18
+ export { removeNonNumeric } from "./services/removeNonNumeric";
21
19
  export { truncateLargeFields } from "./services/truncateLargeFields";
22
- export { regex } from "./validations/regex";
23
- export { validateCPF } from "./validations/validateCPF";
20
+ export { validateCpf } from "./validations/validateCpf";
24
21
  export { validateDate } from "./validations/validateDate";
25
22
  export { validatePhone } from "./validations/validatePhone";
26
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC"}
package/dist/index.js CHANGED
@@ -1,30 +1,22 @@
1
- // formats
2
- export { formatBrazilianDateHour } from "./formats/formatBrazilianDateHour";
3
- export { formatBrazilianDateToDate } from "./formats/formatBrazilianDateToDate";
4
- export { formatDateHour } from "./formats/formatDateHour";
1
+ export { formatDate } from "./formats/formatDate";
5
2
  export { formatJsonObject } from "./formats/formatJsonObject";
6
3
  export { formatJsonString } from "./formats/formatJsonString";
7
- export { formatToBRL } from "./formats/formatToBRL";
8
4
  export { formatToCep } from "./formats/formatToCep";
9
- export { formatToCNPJ } from "./formats/formatToCNPJ";
10
- export { formatToCPF } from "./formats/formatToCPF";
5
+ export { formatToCnpj } from "./formats/formatToCnpj";
6
+ export { formatToCpf } from "./formats/formatToCpf";
11
7
  export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
8
+ export { formatToCurrency } from "./formats/formatToCurrency";
12
9
  export { formatToEllipsis } from "./formats/formatToEllipsis";
13
10
  export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
14
11
  export { formatToPhone } from "./formats/formatToPhone";
15
- // generators
16
12
  export { generateColorByString } from "./generators/generateColorByString";
17
13
  export { generateId } from "./generators/generateId";
18
14
  export { generateSlug } from "./generators/generateSlug";
19
- // parsers
20
- export { parseToCharacters } from "./parsers/parseToCharacters";
21
- // services
15
+ export { regex } from "./regex";
22
16
  export { calculateCardInstallment } from "./services/calculateCardInstallment";
23
17
  export { maskSensitiveData } from "./services/maskSensitiveData";
24
- export { normalizeRange, within } from "./services/range";
18
+ export { removeNonNumeric } from "./services/removeNonNumeric";
25
19
  export { truncateLargeFields } from "./services/truncateLargeFields";
26
- // validations
27
- export { regex } from "./validations/regex";
28
- export { validateCPF } from "./validations/validateCPF";
20
+ export { validateCpf } from "./validations/validateCpf";
29
21
  export { validateDate } from "./validations/validateDate";
30
22
  export { validatePhone } from "./validations/validatePhone";
@@ -12,4 +12,4 @@ declare const regex: {
12
12
  DATE: RegExp;
13
13
  };
14
14
  export { regex };
15
- //# sourceMappingURL=regex.d.ts.map
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/regex/index.ts"],"names":[],"mappings":"AA0BA,QAAA,MAAM,KAAK;;;;;;;;;;;;CAYV,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=calculateCardInstallment.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculateCardInstallment.spec.d.ts","sourceRoot":"","sources":["../../../src/services/__test__/calculateCardInstallment.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,71 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { calculateCardInstallment } from "../calculateCardInstallment";
3
+ describe("calculateCardInstallment", () => {
4
+ it("should calculate the total and installment price with default fees", () => {
5
+ const result = calculateCardInstallment({
6
+ cashPrice: 1000,
7
+ numberInstallments: 12,
8
+ });
9
+ expect(result).toEqual({
10
+ totalPrice: 1241.08,
11
+ installmentPrice: 103.42,
12
+ });
13
+ });
14
+ it("should calculate the total and installment price with custom fees", () => {
15
+ const result = calculateCardInstallment({
16
+ cashPrice: 1000,
17
+ numberInstallments: 12,
18
+ fees: 0.02,
19
+ });
20
+ expect(result).toEqual({
21
+ totalPrice: 1134.72,
22
+ installmentPrice: 94.56,
23
+ });
24
+ });
25
+ it("should calculate correctly for a single installment (no interest)", () => {
26
+ const result = calculateCardInstallment({
27
+ cashPrice: 1000,
28
+ numberInstallments: 1,
29
+ fees: 0,
30
+ });
31
+ expect(result).toEqual({
32
+ totalPrice: 1000,
33
+ installmentPrice: 1000,
34
+ });
35
+ });
36
+ it("should calculate correctly for zero fees", () => {
37
+ const result = calculateCardInstallment({
38
+ cashPrice: 500,
39
+ numberInstallments: 5,
40
+ fees: 0,
41
+ });
42
+ expect(result).toEqual({
43
+ totalPrice: 500,
44
+ installmentPrice: 100,
45
+ });
46
+ });
47
+ it("should handle edge case with zero installments", () => {
48
+ expect(() => calculateCardInstallment({
49
+ cashPrice: 1000,
50
+ numberInstallments: 0,
51
+ })).toThrow("Number of installments must be greater than 0");
52
+ });
53
+ it("should handle edge case with negative fees", () => {
54
+ expect(() => calculateCardInstallment({
55
+ cashPrice: 1000,
56
+ numberInstallments: 12,
57
+ fees: -0.01,
58
+ })).toThrow("Fees must be greater than or equal to 0");
59
+ });
60
+ it("should handle large numbers for cash price and installments", () => {
61
+ const result = calculateCardInstallment({
62
+ cashPrice: 1000000,
63
+ numberInstallments: 24,
64
+ fees: 0.01,
65
+ });
66
+ expect(result).toEqual({
67
+ totalPrice: 1129763.33,
68
+ installmentPrice: 47073.47,
69
+ });
70
+ });
71
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=maskSensitiveData.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maskSensitiveData.spec.d.ts","sourceRoot":"","sources":["../../../src/services/__test__/maskSensitiveData.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,79 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { maskSensitiveData } from "../maskSensitiveData";
3
+ describe("maskSensitiveData", () => {
4
+ it("should mask sensitive keys in a flat JSON object", () => {
5
+ const jsonString = JSON.stringify({
6
+ username: "user123",
7
+ password: "secret",
8
+ email: "user@example.com",
9
+ });
10
+ const result = maskSensitiveData(jsonString, ["password"]);
11
+ expect(result).toBe('{"username":"user123","password":"****","email":"user@example.com"}');
12
+ });
13
+ it("should mask sensitive keys in nested objects", () => {
14
+ const jsonString = JSON.stringify({
15
+ profile: {
16
+ username: "user123",
17
+ creditCard: "1234-5678-9012-3456",
18
+ },
19
+ });
20
+ const result = maskSensitiveData(jsonString, ["creditCard"]);
21
+ expect(result).toBe('{"profile":{"username":"user123","creditCard":"****"}}');
22
+ });
23
+ it("should mask sensitive keys in arrays", () => {
24
+ const jsonString = JSON.stringify({
25
+ users: [
26
+ { username: "user1", password: "pass1" },
27
+ { username: "user2", password: "pass2" },
28
+ ],
29
+ });
30
+ const result = maskSensitiveData(jsonString, ["password"]);
31
+ expect(result).toBe('{"users":[{"username":"user1","password":"****"},{"username":"user2","password":"****"}]}');
32
+ });
33
+ it("should handle non-JSON strings gracefully", () => {
34
+ const invalidJson = "not a json string";
35
+ const result = maskSensitiveData(invalidJson, ["password"]);
36
+ expect(result).toBe("not a json string");
37
+ });
38
+ it("should handle empty JSON objects", () => {
39
+ const jsonString = JSON.stringify({});
40
+ const result = maskSensitiveData(jsonString, ["password"]);
41
+ expect(result).toBe("{}");
42
+ });
43
+ it("should handle empty arrays", () => {
44
+ const jsonString = JSON.stringify([]);
45
+ const result = maskSensitiveData(jsonString, ["password"]);
46
+ expect(result).toBe("[]");
47
+ });
48
+ it("should use default sensitive keys if none are provided", () => {
49
+ const jsonString = JSON.stringify({
50
+ username: "user123",
51
+ password: "secret",
52
+ confirmPassword: "secret",
53
+ creditCard: "1234-5678-9012-3456",
54
+ });
55
+ const result = maskSensitiveData(jsonString);
56
+ expect(result).toBe('{"username":"user123","password":"****","confirmPassword":"****","creditCard":"****"}');
57
+ });
58
+ it("should not mask keys that are not in the sensitive keys list", () => {
59
+ const jsonString = JSON.stringify({
60
+ username: "user123",
61
+ email: "user@example.com",
62
+ });
63
+ const result = maskSensitiveData(jsonString, ["password"]);
64
+ expect(result).toBe('{"username":"user123","email":"user@example.com"}');
65
+ });
66
+ it("should handle deeply nested objects", () => {
67
+ const jsonString = JSON.stringify({
68
+ level1: {
69
+ level2: {
70
+ level3: {
71
+ password: "secret",
72
+ },
73
+ },
74
+ },
75
+ });
76
+ const result = maskSensitiveData(jsonString, ["password"]);
77
+ expect(result).toBe('{"level1":{"level2":{"level3":{"password":"****"}}}}');
78
+ });
79
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=removeCurrencySymbols.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removeCurrencySymbols.spec.d.ts","sourceRoot":"","sources":["../../../src/services/__test__/removeCurrencySymbols.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,34 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { removeCurrencySymbols } from "../removeCurrencySymbols";
3
+ describe("removeCurrencySymbols", () => {
4
+ it("should remove common currency symbols from the string", () => {
5
+ expect(removeCurrencySymbols("R$13,45")).toBe("13,45");
6
+ expect(removeCurrencySymbols("$123.45")).toBe("123.45");
7
+ expect(removeCurrencySymbols("€99.99")).toBe("99.99");
8
+ expect(removeCurrencySymbols("¥1,000")).toBe("1,000");
9
+ });
10
+ it("should handle strings without currency symbols", () => {
11
+ expect(removeCurrencySymbols("123.45")).toBe("123.45");
12
+ expect(removeCurrencySymbols("1,000")).toBe("1,000");
13
+ });
14
+ it("should handle strings with multiple currency symbols", () => {
15
+ expect(removeCurrencySymbols("R$ $123.45")).toBe("123.45");
16
+ expect(removeCurrencySymbols("€¥99,99")).toBe("99,99");
17
+ });
18
+ it("should handle strings with leading and trailing whitespace", () => {
19
+ expect(removeCurrencySymbols(" $123.45 ")).toBe("123.45");
20
+ expect(removeCurrencySymbols("\t€99.99\n")).toBe("99.99");
21
+ });
22
+ it("should return an empty string if the input is only currency symbols", () => {
23
+ expect(removeCurrencySymbols("R$")).toBe("");
24
+ expect(removeCurrencySymbols("$")).toBe("");
25
+ expect(removeCurrencySymbols("€")).toBe("");
26
+ });
27
+ it("should handle an empty string input", () => {
28
+ expect(removeCurrencySymbols("")).toBe("");
29
+ });
30
+ it("should handle strings with special characters but no currency symbols", () => {
31
+ expect(removeCurrencySymbols("123-45")).toBe("123-45");
32
+ expect(removeCurrencySymbols("1,000.00")).toBe("1,000.00");
33
+ });
34
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=removeNonNumeric.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removeNonNumeric.spec.d.ts","sourceRoot":"","sources":["../../../src/services/__test__/removeNonNumeric.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { removeNonNumeric } from "../removeNonNumeric";
3
+ describe("removeNonNumeric", () => {
4
+ it("should remove all non-numeric characters from a string", () => {
5
+ expect(removeNonNumeric("abc123def456")).toBe("123456");
6
+ expect(removeNonNumeric("!@#123$%^456&*()")).toBe("123456");
7
+ expect(removeNonNumeric("a1b2c3")).toBe("123");
8
+ });
9
+ it("should return an empty string if there are no numeric characters", () => {
10
+ expect(removeNonNumeric("abcdef")).toBe("");
11
+ expect(removeNonNumeric("!@#$%^&*()")).toBe("");
12
+ });
13
+ it("should return the same string if it contains only numeric characters", () => {
14
+ expect(removeNonNumeric("123456")).toBe("123456");
15
+ expect(removeNonNumeric("000123")).toBe("000123");
16
+ });
17
+ it("should handle an empty string input", () => {
18
+ expect(removeNonNumeric("")).toBe("");
19
+ });
20
+ it("should handle strings with spaces and remove them", () => {
21
+ expect(removeNonNumeric("123 456 789")).toBe("123456789");
22
+ expect(removeNonNumeric(" 1 2 3 ")).toBe("123");
23
+ });
24
+ it("should handle strings with special characters and preserve only numbers", () => {
25
+ expect(removeNonNumeric("12-34.56/78")).toBe("12345678");
26
+ });
27
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=truncateLargeFields.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truncateLargeFields.spec.d.ts","sourceRoot":"","sources":["../../../src/services/__test__/truncateLargeFields.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,65 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { truncateLargeFields } from "../truncateLargeFields";
3
+ describe("truncateLargeFields", () => {
4
+ it("should truncate string fields exceeding the maxLength", () => {
5
+ const json = JSON.stringify({
6
+ name: "John",
7
+ description: "A very long description that exceeds the maximum length...",
8
+ });
9
+ const result = truncateLargeFields(json, 20);
10
+ expect(result).toBe('{"name":"John","description":"To large information: field as 58 characters"}');
11
+ });
12
+ it("should handle nested objects and truncate large string fields", () => {
13
+ const json = JSON.stringify({
14
+ nested: {
15
+ details: "Another long string that needs truncation.",
16
+ },
17
+ });
18
+ const result = truncateLargeFields(json, 20);
19
+ expect(result).toBe('{"nested":{"details":"To large information: field as 42 characters"}}');
20
+ });
21
+ it("should handle arrays and truncate large string fields within them", () => {
22
+ const json = JSON.stringify({
23
+ items: ["short", "A very long string in an array that exceeds the limit"],
24
+ });
25
+ const result = truncateLargeFields(json, 20);
26
+ expect(result).toBe('{"items":["short","To large information: field as 53 characters"]}');
27
+ });
28
+ it("should not modify fields that are within the maxLength", () => {
29
+ const json = JSON.stringify({
30
+ name: "John",
31
+ description: "Short description",
32
+ });
33
+ const result = truncateLargeFields(json, 20);
34
+ expect(result).toBe('{"name":"John","description":"Short description"}');
35
+ });
36
+ it("should throw an error for invalid JSON strings", () => {
37
+ const invalidJson = "{ name: 'John' }"; // Invalid JSON
38
+ expect(() => truncateLargeFields(invalidJson, 20)).toThrow("Invalid JSON string");
39
+ });
40
+ it("should handle empty JSON objects", () => {
41
+ const json = JSON.stringify({});
42
+ const result = truncateLargeFields(json, 20);
43
+ expect(result).toBe("{}");
44
+ });
45
+ it("should handle empty arrays", () => {
46
+ const json = JSON.stringify([]);
47
+ const result = truncateLargeFields(json, 20);
48
+ expect(result).toBe("[]");
49
+ });
50
+ it("should handle non-string fields without modification", () => {
51
+ const json = JSON.stringify({
52
+ number: 123,
53
+ boolean: true,
54
+ nullValue: null,
55
+ });
56
+ const result = truncateLargeFields(json, 20);
57
+ expect(result).toBe('{"number":123,"boolean":true,"nullValue":null}');
58
+ });
59
+ it("should use the default maxLength of 1000 if not provided", () => {
60
+ const longString = "a".repeat(1500);
61
+ const json = JSON.stringify({ longField: longString });
62
+ const result = truncateLargeFields(json);
63
+ expect(result).toBe(`{"longField":"To large information: field as 1500 characters"}`);
64
+ });
65
+ });
@@ -1,7 +1,33 @@
1
- import type { CalculateCardInstallmentProps } from "@arkyn/types";
2
- declare function calculateCardInstallment(args: CalculateCardInstallmentProps): {
3
- total_price: number;
4
- installment_price: number;
5
- };
1
+ import type { CalculateCardInstallmentFunction } from "@arkyn/types";
2
+ /**
3
+ * Calculates the installment price and total price for a card payment plan.
4
+ *
5
+ * @remarks
6
+ * **Important:** When the interest amount (`fees`) is equal to 0 or the number of installments (`numberInstallments`) is equal to 1, no interest will be charged.
7
+ *
8
+ * @throws Will throw an error if the number of installments is less than or equal to 0.
9
+ * @throws Will throw an error if the fees are less than 0.
10
+ *
11
+ * @param props - The input parameters for the calculation.
12
+ * @param props.cashPrice - The total cash price of the product or service.
13
+ * @param props.numberInstallments - The number of installments for the payment plan.
14
+ * @param props.fees - The interest rate per installment (default is 0.0349).
15
+ *
16
+ * @returns An object containing:
17
+ * - `totalPrice`: The total price to be paid, rounded to two decimal places.
18
+ * - `installmentPrice`: The price of each installment, rounded to two decimal places.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const result = calculateCardInstallment({
23
+ * cashPrice: 1000,
24
+ * numberInstallments: 12,
25
+ * fees: 0.02,
26
+ * });
27
+ * console.log(result);
28
+ * // Output: { totalPrice: 1124.62, installmentPrice: 93.72 }
29
+ * ```
30
+ */
31
+ declare const calculateCardInstallment: CalculateCardInstallmentFunction;
6
32
  export { calculateCardInstallment };
7
33
  //# sourceMappingURL=calculateCardInstallment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"calculateCardInstallment.d.ts","sourceRoot":"","sources":["../../src/services/calculateCardInstallment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAElE,iBAAS,wBAAwB,CAAC,IAAI,EAAE,6BAA6B;;;EAgBpE;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
1
+ {"version":3,"file":"calculateCardInstallment.d.ts","sourceRoot":"","sources":["../../src/services/calculateCardInstallment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,cAAc,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,QAAA,MAAM,wBAAwB,EAAE,gCA+B/B,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
@@ -1,14 +1,55 @@
1
- function calculateCardInstallment(args) {
2
- const { cash_price, number_installments, fees = 0.0349 } = args;
3
- let installment_price = 0;
4
- let total_price = 0;
5
- let numerator = Math.pow(1 + fees, number_installments) * fees;
6
- let denominator = Math.pow(1 + fees, number_installments) - 1;
7
- installment_price = cash_price * (numerator / denominator);
8
- total_price = number_installments * installment_price;
1
+ /**
2
+ * Calculates the installment price and total price for a card payment plan.
3
+ *
4
+ * @remarks
5
+ * **Important:** When the interest amount (`fees`) is equal to 0 or the number of installments (`numberInstallments`) is equal to 1, no interest will be charged.
6
+ *
7
+ * @throws Will throw an error if the number of installments is less than or equal to 0.
8
+ * @throws Will throw an error if the fees are less than 0.
9
+ *
10
+ * @param props - The input parameters for the calculation.
11
+ * @param props.cashPrice - The total cash price of the product or service.
12
+ * @param props.numberInstallments - The number of installments for the payment plan.
13
+ * @param props.fees - The interest rate per installment (default is 0.0349).
14
+ *
15
+ * @returns An object containing:
16
+ * - `totalPrice`: The total price to be paid, rounded to two decimal places.
17
+ * - `installmentPrice`: The price of each installment, rounded to two decimal places.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const result = calculateCardInstallment({
22
+ * cashPrice: 1000,
23
+ * numberInstallments: 12,
24
+ * fees: 0.02,
25
+ * });
26
+ * console.log(result);
27
+ * // Output: { totalPrice: 1124.62, installmentPrice: 93.72 }
28
+ * ```
29
+ */
30
+ const calculateCardInstallment = (props) => {
31
+ const { cashPrice, numberInstallments, fees = 0.0349 } = props;
32
+ if (fees === 0 || numberInstallments === 1) {
33
+ return {
34
+ totalPrice: cashPrice,
35
+ installmentPrice: cashPrice / numberInstallments,
36
+ };
37
+ }
38
+ if (numberInstallments <= 0) {
39
+ throw new Error("Number of installments must be greater than 0");
40
+ }
41
+ if (fees < 0) {
42
+ throw new Error("Fees must be greater than or equal to 0");
43
+ }
44
+ let installmentPrice = 0;
45
+ let totalPrice = 0;
46
+ let numerator = Math.pow(1 + fees, numberInstallments) * fees;
47
+ let denominator = Math.pow(1 + fees, numberInstallments) - 1;
48
+ installmentPrice = cashPrice * (numerator / denominator);
49
+ totalPrice = numberInstallments * installmentPrice;
9
50
  return {
10
- total_price: +total_price.toFixed(2),
11
- installment_price: +installment_price.toFixed(2),
51
+ totalPrice: +totalPrice.toFixed(2),
52
+ installmentPrice: +installmentPrice.toFixed(2),
12
53
  };
13
- }
54
+ };
14
55
  export { calculateCardInstallment };
@@ -1,3 +1,26 @@
1
- declare function maskSensitiveData(jsonString: string, sensitiveKeys?: string[]): string;
1
+ import type { MaskSensitiveDataFunction } from "@arkyn/types";
2
+ /**
3
+ * Masks sensitive data in a JSON string by replacing the values of specified keys with "****".
4
+ *
5
+ * @param jsonString - The JSON string to be processed.
6
+ * @param sensitiveKeys - An array of keys whose values should be masked. Defaults to `["password", "confirmPassword", "creditCard"]`.
7
+ * @returns A JSON string with sensitive data masked. If the input is not a valid JSON string, it returns the original string.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const jsonString = JSON.stringify({
12
+ * username: "user123",
13
+ * password: "secret",
14
+ * profile: {
15
+ * creditCard: "1234-5678-9012-3456",
16
+ * },
17
+ * });
18
+ *
19
+ * const result = maskSensitiveData(jsonString, ["password", "creditCard"]);
20
+ * console.log(result);
21
+ * // Output: '{"username":"user123","password":"****","profile":{"creditCard":"****"}}'
22
+ * ```
23
+ */
24
+ declare const maskSensitiveData: MaskSensitiveDataFunction;
2
25
  export { maskSensitiveData };
3
26
  //# sourceMappingURL=maskSensitiveData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"maskSensitiveData.d.ts","sourceRoot":"","sources":["../../src/services/maskSensitiveData.ts"],"names":[],"mappings":"AAAA,iBAAS,iBAAiB,CACxB,UAAU,EAAE,MAAM,EAClB,aAAa,WAAgD,GAC5D,MAAM,CAkCR;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"maskSensitiveData.d.ts","sourceRoot":"","sources":["../../src/services/maskSensitiveData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,QAAA,MAAM,iBAAiB,EAAE,yBAqCxB,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1,4 +1,26 @@
1
- function maskSensitiveData(jsonString, sensitiveKeys = ["password", "confirmPassword", "creditCard"]) {
1
+ /**
2
+ * Masks sensitive data in a JSON string by replacing the values of specified keys with "****".
3
+ *
4
+ * @param jsonString - The JSON string to be processed.
5
+ * @param sensitiveKeys - An array of keys whose values should be masked. Defaults to `["password", "confirmPassword", "creditCard"]`.
6
+ * @returns A JSON string with sensitive data masked. If the input is not a valid JSON string, it returns the original string.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const jsonString = JSON.stringify({
11
+ * username: "user123",
12
+ * password: "secret",
13
+ * profile: {
14
+ * creditCard: "1234-5678-9012-3456",
15
+ * },
16
+ * });
17
+ *
18
+ * const result = maskSensitiveData(jsonString, ["password", "creditCard"]);
19
+ * console.log(result);
20
+ * // Output: '{"username":"user123","password":"****","profile":{"creditCard":"****"}}'
21
+ * ```
22
+ */
23
+ const maskSensitiveData = (jsonString, sensitiveKeys = ["password", "confirmPassword", "creditCard"]) => {
2
24
  function maskValue(key, value) {
3
25
  if (sensitiveKeys.includes(key))
4
26
  return "****";
@@ -34,5 +56,5 @@ function maskSensitiveData(jsonString, sensitiveKeys = ["password", "confirmPass
34
56
  catch (error) {
35
57
  return jsonString;
36
58
  }
37
- }
59
+ };
38
60
  export { maskSensitiveData };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Removes currency symbols from a given formatted string.
3
+ *
4
+ * This function takes a string that may contain currency symbols
5
+ * and removes them using a regular expression. The resulting string
6
+ * is also trimmed of any leading or trailing whitespace.
7
+ *
8
+ * @param formattedValue - The input string containing currency symbols.
9
+ * @returns A string with all currency symbols removed and trimmed of whitespace.
10
+ *
11
+ * @example
12
+ * removeCurrencySymbols("R$13,45"); // "13,45"
13
+ * removeCurrencySymbols("$123.45"); // "123.45"
14
+ * removeCurrencySymbols("€99.99"); // "99.99"
15
+ * removeCurrencySymbols("¥1,000"); // "1,000"
16
+ * removeCurrencySymbols("123.45"); // "123.45" (no symbols to remove)
17
+ */
18
+ declare const removeCurrencySymbols: (formattedValue: string) => string;
19
+ export { removeCurrencySymbols };
20
+ //# sourceMappingURL=removeCurrencySymbols.d.ts.map