@arkyn/shared 3.0.1-beta.12 → 3.0.1-beta.120

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 (147) hide show
  1. package/README.md +452 -67
  2. package/dist/bundle.js +2439 -0
  3. package/dist/bundle.umd.cjs +6 -0
  4. package/dist/formats/formatDate.d.ts +43 -15
  5. package/dist/formats/formatDate.d.ts.map +1 -1
  6. package/dist/formats/formatDate.js +60 -25
  7. package/dist/formats/formatJsonObject.d.ts +6 -7
  8. package/dist/formats/formatJsonObject.d.ts.map +1 -1
  9. package/dist/formats/formatJsonObject.js +17 -17
  10. package/dist/formats/formatToCapitalizeFirstWordLetter.d.ts +17 -18
  11. package/dist/formats/formatToCapitalizeFirstWordLetter.d.ts.map +1 -1
  12. package/dist/formats/formatToCapitalizeFirstWordLetter.js +17 -18
  13. package/dist/formats/formatToCep.d.ts +5 -12
  14. package/dist/formats/formatToCep.d.ts.map +1 -1
  15. package/dist/formats/formatToCep.js +11 -16
  16. package/dist/formats/formatToCnpj.d.ts +3 -13
  17. package/dist/formats/formatToCnpj.d.ts.map +1 -1
  18. package/dist/formats/formatToCnpj.js +9 -17
  19. package/dist/formats/formatToCpf.d.ts +5 -13
  20. package/dist/formats/formatToCpf.d.ts.map +1 -1
  21. package/dist/formats/formatToCpf.js +11 -17
  22. package/dist/formats/formatToCurrency.d.ts +18 -14
  23. package/dist/formats/formatToCurrency.d.ts.map +1 -1
  24. package/dist/formats/formatToCurrency.js +21 -14
  25. package/dist/formats/formatToEllipsis.d.ts +8 -5
  26. package/dist/formats/formatToEllipsis.d.ts.map +1 -1
  27. package/dist/formats/formatToEllipsis.js +21 -7
  28. package/dist/formats/formatToHiddenDigits.d.ts +16 -16
  29. package/dist/formats/formatToHiddenDigits.d.ts.map +1 -1
  30. package/dist/formats/formatToHiddenDigits.js +19 -19
  31. package/dist/formats/formatToPhone.d.ts +1 -1
  32. package/dist/formats/formatToPhone.d.ts.map +1 -1
  33. package/dist/formats/formatToPhone.js +3 -3
  34. package/dist/generators/generateColorByString.d.ts +7 -4
  35. package/dist/generators/generateColorByString.d.ts.map +1 -1
  36. package/dist/generators/generateColorByString.js +10 -6
  37. package/dist/generators/generateId.d.ts +3 -3
  38. package/dist/generators/generateSlug.d.ts +10 -3
  39. package/dist/generators/generateSlug.d.ts.map +1 -1
  40. package/dist/generators/generateSlug.js +11 -4
  41. package/dist/index.d.ts +10 -16
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +12 -17
  44. package/dist/{services/truncateLargeFields.d.ts → parsers/parseLargeFields.d.ts} +9 -11
  45. package/dist/parsers/parseLargeFields.d.ts.map +1 -0
  46. package/dist/{services/truncateLargeFields.js → parsers/parseLargeFields.js} +12 -13
  47. package/dist/parsers/parseSensitiveData.d.ts +23 -0
  48. package/dist/parsers/parseSensitiveData.d.ts.map +1 -0
  49. package/dist/{services/maskSensitiveData.js → parsers/parseSensitiveData.js} +10 -12
  50. package/dist/parsers/parseToDate.d.ts +41 -0
  51. package/dist/parsers/parseToDate.d.ts.map +1 -0
  52. package/dist/parsers/parseToDate.js +67 -0
  53. package/dist/services/validateDateService.d.ts +85 -0
  54. package/dist/services/validateDateService.d.ts.map +1 -0
  55. package/dist/services/validateDateService.js +132 -0
  56. package/dist/{services → utilities}/calculateCardInstallment.d.ts +16 -18
  57. package/dist/utilities/calculateCardInstallment.d.ts.map +1 -0
  58. package/dist/{services → utilities}/calculateCardInstallment.js +12 -15
  59. package/dist/utilities/ensureQuotes.d.ts +21 -0
  60. package/dist/utilities/ensureQuotes.d.ts.map +1 -0
  61. package/dist/{services → utilities}/ensureQuotes.js +12 -4
  62. package/dist/utilities/isHtml.d.ts +22 -0
  63. package/dist/utilities/isHtml.d.ts.map +1 -0
  64. package/dist/utilities/isHtml.js +24 -0
  65. package/dist/{services → utilities}/removeCurrencySymbols.d.ts +6 -4
  66. package/dist/utilities/removeCurrencySymbols.d.ts.map +1 -0
  67. package/dist/{services → utilities}/removeCurrencySymbols.js +8 -7
  68. package/dist/utilities/removeNonNumeric.d.ts +16 -0
  69. package/dist/utilities/removeNonNumeric.d.ts.map +1 -0
  70. package/dist/utilities/removeNonNumeric.js +17 -0
  71. package/dist/utilities/stripHtmlTags.d.ts +19 -0
  72. package/dist/utilities/stripHtmlTags.d.ts.map +1 -0
  73. package/dist/utilities/stripHtmlTags.js +24 -0
  74. package/package.json +24 -7
  75. package/dist/formats/formatToCpfCnpj.d.ts +0 -24
  76. package/dist/formats/formatToCpfCnpj.d.ts.map +0 -1
  77. package/dist/formats/formatToCpfCnpj.js +0 -33
  78. package/dist/formats/formatToDate.d.ts +0 -32
  79. package/dist/formats/formatToDate.d.ts.map +0 -1
  80. package/dist/formats/formatToDate.js +0 -50
  81. package/dist/services/calculateCardInstallment.d.ts.map +0 -1
  82. package/dist/services/ensureQuotes.d.ts +0 -14
  83. package/dist/services/ensureQuotes.d.ts.map +0 -1
  84. package/dist/services/maskSensitiveData.d.ts +0 -26
  85. package/dist/services/maskSensitiveData.d.ts.map +0 -1
  86. package/dist/services/removeCurrencySymbols.d.ts.map +0 -1
  87. package/dist/services/removeNonNumeric.d.ts +0 -16
  88. package/dist/services/removeNonNumeric.d.ts.map +0 -1
  89. package/dist/services/removeNonNumeric.js +0 -16
  90. package/dist/services/stripHtmlTags.d.ts +0 -16
  91. package/dist/services/stripHtmlTags.d.ts.map +0 -1
  92. package/dist/services/stripHtmlTags.js +0 -16
  93. package/dist/services/truncateLargeFields.d.ts.map +0 -1
  94. package/dist/validations/validateCep.d.ts +0 -24
  95. package/dist/validations/validateCep.d.ts.map +0 -1
  96. package/dist/validations/validateCep.js +0 -33
  97. package/dist/validations/validateCnpj.d.ts +0 -22
  98. package/dist/validations/validateCnpj.d.ts.map +0 -1
  99. package/dist/validations/validateCnpj.js +0 -52
  100. package/dist/validations/validateCpf.d.ts +0 -24
  101. package/dist/validations/validateCpf.d.ts.map +0 -1
  102. package/dist/validations/validateCpf.js +0 -54
  103. package/dist/validations/validateDate.d.ts +0 -34
  104. package/dist/validations/validateDate.d.ts.map +0 -1
  105. package/dist/validations/validateDate.js +0 -73
  106. package/dist/validations/validatePassword.d.ts +0 -21
  107. package/dist/validations/validatePassword.d.ts.map +0 -1
  108. package/dist/validations/validatePassword.js +0 -34
  109. package/dist/validations/validatePhone.d.ts +0 -29
  110. package/dist/validations/validatePhone.d.ts.map +0 -1
  111. package/dist/validations/validatePhone.js +0 -44
  112. package/dist/validations/validateRg.d.ts +0 -22
  113. package/dist/validations/validateRg.d.ts.map +0 -1
  114. package/dist/validations/validateRg.js +0 -31
  115. package/src/formats/formatDate.ts +0 -92
  116. package/src/formats/formatJsonObject.ts +0 -90
  117. package/src/formats/formatJsonString.ts +0 -50
  118. package/src/formats/formatToCapitalizeFirstWordLetter.ts +0 -46
  119. package/src/formats/formatToCep.ts +0 -39
  120. package/src/formats/formatToCnpj.ts +0 -40
  121. package/src/formats/formatToCpf.ts +0 -40
  122. package/src/formats/formatToCpfCnpj.ts +0 -38
  123. package/src/formats/formatToCurrency.ts +0 -63
  124. package/src/formats/formatToDate.ts +0 -70
  125. package/src/formats/formatToEllipsis.ts +0 -25
  126. package/src/formats/formatToHiddenDigits.ts +0 -92
  127. package/src/formats/formatToPhone.ts +0 -170
  128. package/src/generators/generateColorByString.ts +0 -33
  129. package/src/generators/generateId.ts +0 -61
  130. package/src/generators/generateSlug.ts +0 -31
  131. package/src/index.ts +0 -37
  132. package/src/services/calculateCardInstallment.ts +0 -73
  133. package/src/services/ensureQuotes.ts +0 -25
  134. package/src/services/maskSensitiveData.ts +0 -68
  135. package/src/services/removeCurrencySymbols.ts +0 -29
  136. package/src/services/removeNonNumeric.ts +0 -20
  137. package/src/services/stripHtmlTags.ts +0 -20
  138. package/src/services/truncateLargeFields.ts +0 -69
  139. package/src/validations/validateCep.ts +0 -41
  140. package/src/validations/validateCnpj.ts +0 -65
  141. package/src/validations/validateCpf.ts +0 -62
  142. package/src/validations/validateDate.ts +0 -86
  143. package/src/validations/validatePassword.ts +0 -41
  144. package/src/validations/validatePhone.ts +0 -50
  145. package/src/validations/validateRg.ts +0 -37
  146. package/tsconfig.json +0 -20
  147. package/vitest.config.ts +0 -5
@@ -3,16 +3,20 @@
3
3
  * The function creates a hash from the string and uses it to calculate
4
4
  * RGB values, which are then converted to a hexadecimal color code.
5
5
  *
6
- * @param prop - The input string used to generate the color.
7
- * @returns A hexadecimal color code (e.g., "#a1b2c3") derived from the input string.
6
+ * @param {string} rawString - The input string used to generate the color.
7
+ *
8
+ * @returns {string} A hexadecimal color code (e.g., "#a1b2c3") derived from the input string.
9
+ *
8
10
  * @example
11
+ * ```typescript
9
12
  * const color = generateColorByString("example");
10
13
  * console.log(color); // Outputs a consistent hex color like "#5e8f9a"
14
+ * ```
11
15
  */
12
- const generateColorByString = (prop) => {
16
+ function generateColorByString(rawString) {
13
17
  var hash = 0;
14
- for (var i = 0; i < prop.length; i++) {
15
- hash = prop.charCodeAt(i) + ((hash << 5) - hash);
18
+ for (var i = 0; i < rawString.length; i++) {
19
+ hash = rawString.charCodeAt(i) + ((hash << 5) - hash);
16
20
  }
17
21
  var red = (hash & 0xff0000) >> 16;
18
22
  var green = (hash & 0x00ff00) >> 8;
@@ -21,5 +25,5 @@ const generateColorByString = (prop) => {
21
25
  var greenHex = green.toString(16).padStart(2, "0");
22
26
  var blueHex = blue.toString(16).padStart(2, "0");
23
27
  return "#" + redHex + greenHex + blueHex;
24
- };
28
+ }
25
29
  export { generateColorByString };
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * Generates a unique identifier (UUID) in the specified format and type.
3
3
  *
4
- * @param type - The desired output type of the UUID. Can be:
4
+ * @param {"text" | "binary"} type - The desired output type of the UUID. Can be:
5
5
  * - `"text"`: Returns the UUID as a string.
6
6
  * - `"binary"`: Returns the UUID as a `Uint8Array` in binary format.
7
- * @param format - The version of the UUID to generate. Can be:
7
+ * @param {"v4" | "v7"} format - The version of the UUID to generate. Can be:
8
8
  * - `"v4"`: Generates a random UUID (version 4).
9
9
  * - `"v7"`: Generates a time-ordered UUID (version 7).
10
- * @returns The generated UUID in the specified type and format.
10
+ * @returns {string | Uint8Array} The generated UUID in the specified type and format.
11
11
  * - If `type` is `"text"`, a string representation of the UUID is returned.
12
12
  * - If `type` is `"binary"`, a `Uint8Array` representation of the UUID is returned.
13
13
  * @throws {Error} If an invalid `type` or `format` is provided.
@@ -9,9 +9,16 @@
9
9
  * - Collapses multiple consecutive hyphens into a single hyphen.
10
10
  * - Trims leading and trailing hyphens.
11
11
  *
12
- * @param string - The input string to be converted into a slug.
13
- * @returns A URL-friendly slug derived from the input string.
12
+ * @param {string} rawString - The input string to be converted into a slug.
13
+ *
14
+ * @returns {string} A URL-friendly slug derived from the input string.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const slug = generateSlug("Hello, World! This is a Test.");
19
+ * console.log(slug); // Outputs: "hello-world-this-is-a-test"
20
+ * ```
14
21
  */
15
- declare function generateSlug(prop: string): string;
22
+ declare function generateSlug(rawString: string): string;
16
23
  export { generateSlug };
17
24
  //# sourceMappingURL=generateSlug.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateSlug.d.ts","sourceRoot":"","sources":["../../src/generators/generateSlug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,iBAAS,YAAY,CAAC,IAAI,EAAE,MAAM,UAajC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"generateSlug.d.ts","sourceRoot":"","sources":["../../src/generators/generateSlug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,iBAAS,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAa/C;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -9,11 +9,18 @@
9
9
  * - Collapses multiple consecutive hyphens into a single hyphen.
10
10
  * - Trims leading and trailing hyphens.
11
11
  *
12
- * @param string - The input string to be converted into a slug.
13
- * @returns A URL-friendly slug derived from the input string.
12
+ * @param {string} rawString - The input string to be converted into a slug.
13
+ *
14
+ * @returns {string} A URL-friendly slug derived from the input string.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const slug = generateSlug("Hello, World! This is a Test.");
19
+ * console.log(slug); // Outputs: "hello-world-this-is-a-test"
20
+ * ```
14
21
  */
15
- function generateSlug(prop) {
16
- let slug = prop.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
22
+ function generateSlug(rawString) {
23
+ let slug = rawString.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
17
24
  slug = slug
18
25
  .replace(/[^\w\s-]/g, "")
19
26
  .replace(/\s+/g, "-")
package/dist/index.d.ts CHANGED
@@ -5,27 +5,21 @@ export { formatToCapitalizeFirstWordLetter } from "./formats/formatToCapitalizeF
5
5
  export { formatToCep } from "./formats/formatToCep";
6
6
  export { formatToCnpj } from "./formats/formatToCnpj";
7
7
  export { formatToCpf } from "./formats/formatToCpf";
8
- export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
9
8
  export { formatToCurrency } from "./formats/formatToCurrency";
10
- export { formatToDate } from "./formats/formatToDate";
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 { calculateCardInstallment } from "./services/calculateCardInstallment";
18
- export { ensureQuotes } from "./services/ensureQuotes";
19
- export { maskSensitiveData } from "./services/maskSensitiveData";
20
- export { removeCurrencySymbols } from "./services/removeCurrencySymbols";
21
- export { removeNonNumeric } from "./services/removeNonNumeric";
22
- export { stripHtmlTags } from "./services/stripHtmlTags";
23
- export { truncateLargeFields } from "./services/truncateLargeFields";
24
- export { validateCep } from "./validations/validateCep";
25
- export { validateCnpj } from "./validations/validateCnpj";
26
- export { validateCpf } from "./validations/validateCpf";
27
- export { validateDate } from "./validations/validateDate";
28
- export { validatePassword } from "./validations/validatePassword";
29
- export { validatePhone } from "./validations/validatePhone";
30
- export { validateRg } from "./validations/validateRg";
15
+ export { parseLargeFields } from "./parsers/parseLargeFields";
16
+ export { parseSensitiveData } from "./parsers/parseSensitiveData";
17
+ export { parseToDate } from "./parsers/parseToDate";
18
+ export { ValidateDateService } from "./services/validateDateService";
19
+ export { calculateCardInstallment } from "./utilities/calculateCardInstallment";
20
+ export { ensureQuotes } from "./utilities/ensureQuotes";
21
+ export { isHtml } from "./utilities/isHtml";
22
+ export { removeCurrencySymbols } from "./utilities/removeCurrencySymbols";
23
+ export { removeNonNumeric } from "./utilities/removeNonNumeric";
24
+ export { stripHtmlTags } from "./utilities/stripHtmlTags";
31
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,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,iCAAiC,EAAE,MAAM,6CAA6C,CAAC;AAChG,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,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,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,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,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,iCAAiC,EAAE,MAAM,6CAA6C,CAAC;AAChG,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,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;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,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -6,9 +6,7 @@ export { formatToCapitalizeFirstWordLetter } from "./formats/formatToCapitalizeF
6
6
  export { formatToCep } from "./formats/formatToCep";
7
7
  export { formatToCnpj } from "./formats/formatToCnpj";
8
8
  export { formatToCpf } from "./formats/formatToCpf";
9
- export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
10
9
  export { formatToCurrency } from "./formats/formatToCurrency";
11
- export { formatToDate } from "./formats/formatToDate";
12
10
  export { formatToEllipsis } from "./formats/formatToEllipsis";
13
11
  export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
14
12
  export { formatToPhone } from "./formats/formatToPhone";
@@ -16,19 +14,16 @@ export { formatToPhone } from "./formats/formatToPhone";
16
14
  export { generateColorByString } from "./generators/generateColorByString";
17
15
  export { generateId } from "./generators/generateId";
18
16
  export { generateSlug } from "./generators/generateSlug";
17
+ // parsers
18
+ export { parseLargeFields } from "./parsers/parseLargeFields";
19
+ export { parseSensitiveData } from "./parsers/parseSensitiveData";
20
+ export { parseToDate } from "./parsers/parseToDate";
19
21
  // services
20
- export { calculateCardInstallment } from "./services/calculateCardInstallment";
21
- export { ensureQuotes } from "./services/ensureQuotes";
22
- export { maskSensitiveData } from "./services/maskSensitiveData";
23
- export { removeCurrencySymbols } from "./services/removeCurrencySymbols";
24
- export { removeNonNumeric } from "./services/removeNonNumeric";
25
- export { stripHtmlTags } from "./services/stripHtmlTags";
26
- export { truncateLargeFields } from "./services/truncateLargeFields";
27
- // utils
28
- export { validateCep } from "./validations/validateCep";
29
- export { validateCnpj } from "./validations/validateCnpj";
30
- export { validateCpf } from "./validations/validateCpf";
31
- export { validateDate } from "./validations/validateDate";
32
- export { validatePassword } from "./validations/validatePassword";
33
- export { validatePhone } from "./validations/validatePhone";
34
- export { validateRg } from "./validations/validateRg";
22
+ export { ValidateDateService } from "./services/validateDateService";
23
+ // utilities
24
+ export { calculateCardInstallment } from "./utilities/calculateCardInstallment";
25
+ export { ensureQuotes } from "./utilities/ensureQuotes";
26
+ export { isHtml } from "./utilities/isHtml";
27
+ export { removeCurrencySymbols } from "./utilities/removeCurrencySymbols";
28
+ export { removeNonNumeric } from "./utilities/removeNonNumeric";
29
+ export { stripHtmlTags } from "./utilities/stripHtmlTags";
@@ -1,4 +1,3 @@
1
- type TruncateLargeFieldsFunction = (jsonString: string, maxLength?: number) => string;
2
1
  /**
3
2
  * Truncates large string fields in a JSON string to a specified maximum length.
4
3
  *
@@ -6,9 +5,10 @@ type TruncateLargeFieldsFunction = (jsonString: string, maxLength?: number) => s
6
5
  * any string fields that exceed the specified maximum length. If a string field is truncated,
7
6
  * it is replaced with a message indicating the original length of the field.
8
7
  *
9
- * @param jsonString - The JSON string to process.
10
- * @param maxLength - The maximum allowed length for string fields. Defaults to 1000.
11
- * @returns A JSON string with large string fields truncated.
8
+ * @param {string} jsonString - The JSON string to process.
9
+ * @param {number} maxLength - The maximum allowed length for string fields. Defaults to 1000.
10
+ *
11
+ * @returns {string} A JSON string with large string fields truncated.
12
12
  *
13
13
  * @throws {Error} Throws an error if the input is not a valid JSON string.
14
14
  *
@@ -17,16 +17,14 @@ type TruncateLargeFieldsFunction = (jsonString: string, maxLength?: number) => s
17
17
  * const json = JSON.stringify({
18
18
  * name: "John",
19
19
  * description: "A very long description that exceeds the maximum length...",
20
- * nested: {
21
- * details: "Another long string that needs truncation."
22
- * }
20
+ * nested: { details: "Another long string that needs truncation." }
23
21
  * });
24
22
  *
25
- * const result = truncateLargeFields(json, 50);
23
+ * const result = parseLargeFields(json, 50);
26
24
  * console.log(result);
27
25
  * // Output: '{"name":"John","description":"To large information: field as 57 characters","nested":{"details":"To large information: field as 43 characters"}}'
28
26
  * ```
29
27
  */
30
- declare const truncateLargeFields: TruncateLargeFieldsFunction;
31
- export { truncateLargeFields };
32
- //# sourceMappingURL=truncateLargeFields.d.ts.map
28
+ declare function parseLargeFields(jsonString: string, maxLength?: number): string;
29
+ export { parseLargeFields };
30
+ //# sourceMappingURL=parseLargeFields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseLargeFields.d.ts","sourceRoot":"","sources":["../../src/parsers/parseLargeFields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,iBAAS,gBAAgB,CACvB,UAAU,EAAE,MAAM,EAClB,SAAS,GAAE,MAAa,GACvB,MAAM,CA6BR;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -5,9 +5,10 @@
5
5
  * any string fields that exceed the specified maximum length. If a string field is truncated,
6
6
  * it is replaced with a message indicating the original length of the field.
7
7
  *
8
- * @param jsonString - The JSON string to process.
9
- * @param maxLength - The maximum allowed length for string fields. Defaults to 1000.
10
- * @returns A JSON string with large string fields truncated.
8
+ * @param {string} jsonString - The JSON string to process.
9
+ * @param {number} maxLength - The maximum allowed length for string fields. Defaults to 1000.
10
+ *
11
+ * @returns {string} A JSON string with large string fields truncated.
11
12
  *
12
13
  * @throws {Error} Throws an error if the input is not a valid JSON string.
13
14
  *
@@ -16,17 +17,15 @@
16
17
  * const json = JSON.stringify({
17
18
  * name: "John",
18
19
  * description: "A very long description that exceeds the maximum length...",
19
- * nested: {
20
- * details: "Another long string that needs truncation."
21
- * }
20
+ * nested: { details: "Another long string that needs truncation." }
22
21
  * });
23
22
  *
24
- * const result = truncateLargeFields(json, 50);
23
+ * const result = parseLargeFields(json, 50);
25
24
  * console.log(result);
26
25
  * // Output: '{"name":"John","description":"To large information: field as 57 characters","nested":{"details":"To large information: field as 43 characters"}}'
27
26
  * ```
28
27
  */
29
- const truncateLargeFields = (jsonString, maxLength = 1000) => {
28
+ function parseLargeFields(jsonString, maxLength = 1000) {
30
29
  function truncateValue(value) {
31
30
  if (typeof value === "string" && value.length > maxLength) {
32
31
  return `To large information: field as ${value.length} characters`;
@@ -35,15 +34,15 @@ const truncateLargeFields = (jsonString, maxLength = 1000) => {
35
34
  }
36
35
  function recursiveTruncate(obj) {
37
36
  if (Array.isArray(obj)) {
38
- return obj.map((item) => recursiveTruncate(item)); // Corrigido para processar elementos do array
37
+ return obj.map((item) => recursiveTruncate(item));
39
38
  }
40
39
  else if (obj !== null && typeof obj === "object") {
41
40
  return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
42
41
  key,
43
- recursiveTruncate(value), // Corrigido para aplicar recursão corretamente
42
+ recursiveTruncate(value),
44
43
  ]));
45
44
  }
46
- return truncateValue(obj); // Corrigido para truncar valores diretamente
45
+ return truncateValue(obj);
47
46
  }
48
47
  try {
49
48
  const parsedJson = JSON.parse(jsonString);
@@ -53,5 +52,5 @@ const truncateLargeFields = (jsonString, maxLength = 1000) => {
53
52
  catch (error) {
54
53
  throw new Error("Invalid JSON string");
55
54
  }
56
- };
57
- export { truncateLargeFields };
55
+ }
56
+ export { parseLargeFields };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Masks sensitive data in a JSON string by replacing the values of specified keys with "****".
3
+ *
4
+ * @param {string} jsonString - The JSON string to be processed.
5
+ * @param {string[]} sensitiveKeys - An array of keys whose values should be masked. Defaults to `["password", "confirmPassword", "creditCard"]`.
6
+ *
7
+ * @returns {string} 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: { creditCard: "1234-5678-9012-3456" },
15
+ * });
16
+ *
17
+ * const result = parseSensitiveData(jsonString, ["password", "creditCard"]);
18
+ * console.log(result); // Output: '{"username":"user123","password":"****","profile":{"creditCard":"****"}}'
19
+ * ```
20
+ */
21
+ declare function parseSensitiveData(jsonString: string, sensitiveKeys?: string[]): string;
22
+ export { parseSensitiveData };
23
+ //# sourceMappingURL=parseSensitiveData.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseSensitiveData.d.ts","sourceRoot":"","sources":["../../src/parsers/parseSensitiveData.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,iBAAS,kBAAkB,CACzB,UAAU,EAAE,MAAM,EAClB,aAAa,GAAE,MAAM,EAAkD,GACtE,MAAM,CAkCR;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
@@ -1,26 +1,24 @@
1
1
  /**
2
2
  * Masks sensitive data in a JSON string by replacing the values of specified keys with "****".
3
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.
4
+ * @param {string} jsonString - The JSON string to be processed.
5
+ * @param {string[]} sensitiveKeys - An array of keys whose values should be masked. Defaults to `["password", "confirmPassword", "creditCard"]`.
6
+ *
7
+ * @returns {string} A JSON string with sensitive data masked. If the input is not a valid JSON string, it returns the original string.
7
8
  *
8
9
  * @example
9
10
  * ```typescript
10
11
  * const jsonString = JSON.stringify({
11
12
  * username: "user123",
12
13
  * password: "secret",
13
- * profile: {
14
- * creditCard: "1234-5678-9012-3456",
15
- * },
14
+ * profile: { creditCard: "1234-5678-9012-3456" },
16
15
  * });
17
16
  *
18
- * const result = maskSensitiveData(jsonString, ["password", "creditCard"]);
19
- * console.log(result);
20
- * // Output: '{"username":"user123","password":"****","profile":{"creditCard":"****"}}'
17
+ * const result = parseSensitiveData(jsonString, ["password", "creditCard"]);
18
+ * console.log(result); // Output: '{"username":"user123","password":"****","profile":{"creditCard":"****"}}'
21
19
  * ```
22
20
  */
23
- const maskSensitiveData = (jsonString, sensitiveKeys = ["password", "confirmPassword", "creditCard"]) => {
21
+ function parseSensitiveData(jsonString, sensitiveKeys = ["password", "confirmPassword", "creditCard"]) {
24
22
  function maskValue(key, value) {
25
23
  if (sensitiveKeys.includes(key))
26
24
  return "****";
@@ -56,5 +54,5 @@ const maskSensitiveData = (jsonString, sensitiveKeys = ["password", "confirmPass
56
54
  catch (error) {
57
55
  return jsonString;
58
56
  }
59
- };
60
- export { maskSensitiveData };
57
+ }
58
+ export { parseSensitiveData };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Converts a date and time input into a JavaScript `Date` object, formatted according to the specified input format and timezone.
3
+ *
4
+ * @remarks
5
+ * **Note:** This function works with UTC+0 by default. The returned Date object is not automatically converted to the machine's local timezone.
6
+ * To adjust the timezone, you must manually specify the `timezone` parameter (e.g., -3 for UTC-3).
7
+ *
8
+ * @param {[string, string]} dateTime - An array containing the date and optional time.
9
+ * - The first element is the date string.
10
+ * - The second element is the time string (default is "00:00:00")
11
+ * @param {"brazilianDate" | "isoDate" | "timestamp"} inputFormat - The format of the input date.
12
+ * - "brazilianDate": Expects the date in "DD/MM/YYYY" or "D/M/YYYY" format.
13
+ * - "isoDate": Expects the date in "MM-DD-YYYY" or "M-D-YYYY" format.
14
+ * - "timestamp": Expects the date in "YYYY-MM-DD" or "YYYY-M-D" format.
15
+ * @param {number} [timezone=0] - The timezone offset in hours to apply to the date.
16
+ * - Defaults to 0 (UTC).
17
+ *
18
+ * @returns {Date} A `Date` object representing the parsed date and time, adjusted for the specified timezone.
19
+ *
20
+ * @throws {Error} If the `inputFormat` is invalid.
21
+ * @throws {Error} If the provided date or time is invalid.
22
+ *
23
+ * @example Format a Brazilian date to Date
24
+ * ```typescript
25
+ * const date = parseToDate(["25/12/2023", "15:30:00"], "brazilianDate", -3);
26
+ * console.log(date); // Outputs a Date object for "2023-12-25T12:30:00.000Z" (UTC)
27
+ * ```
28
+ * @example Format an ISO date to Date
29
+ * ```typescript
30
+ * const date = parseToDate(["12-25-2023", "15:30:00"], "isoDate", 2);
31
+ * console.log(date); // Outputs a Date object for "2023-12-25T13:30:00.000Z" (UTC)
32
+ * ```
33
+ * @example Format a timestamp date to Date
34
+ * ```typescript
35
+ * const date = parseToDate(["2023-12-25", "15:30:00"], "timestamp");
36
+ * console.log(date); // Outputs a Date object for "2023-12-25T15:30:00.000Z" (UTC)
37
+ * ```
38
+ */
39
+ declare function parseToDate([date, time]: [string, string?], inputFormat: "brazilianDate" | "isoDate" | "timestamp", timezone?: number): Date;
40
+ export { parseToDate };
41
+ //# sourceMappingURL=parseToDate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseToDate.d.ts","sourceRoot":"","sources":["../../src/parsers/parseToDate.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,iBAAS,WAAW,CAClB,CAAC,IAAI,EAAE,IAAiB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAC5C,WAAW,EAAE,eAAe,GAAG,SAAS,GAAG,WAAW,EACtD,QAAQ,GAAE,MAAU,GACnB,IAAI,CAkCN;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,67 @@
1
+ import { ValidateDateService } from "../services/validateDateService";
2
+ /**
3
+ * Converts a date and time input into a JavaScript `Date` object, formatted according to the specified input format and timezone.
4
+ *
5
+ * @remarks
6
+ * **Note:** This function works with UTC+0 by default. The returned Date object is not automatically converted to the machine's local timezone.
7
+ * To adjust the timezone, you must manually specify the `timezone` parameter (e.g., -3 for UTC-3).
8
+ *
9
+ * @param {[string, string]} dateTime - An array containing the date and optional time.
10
+ * - The first element is the date string.
11
+ * - The second element is the time string (default is "00:00:00")
12
+ * @param {"brazilianDate" | "isoDate" | "timestamp"} inputFormat - The format of the input date.
13
+ * - "brazilianDate": Expects the date in "DD/MM/YYYY" or "D/M/YYYY" format.
14
+ * - "isoDate": Expects the date in "MM-DD-YYYY" or "M-D-YYYY" format.
15
+ * - "timestamp": Expects the date in "YYYY-MM-DD" or "YYYY-M-D" format.
16
+ * @param {number} [timezone=0] - The timezone offset in hours to apply to the date.
17
+ * - Defaults to 0 (UTC).
18
+ *
19
+ * @returns {Date} A `Date` object representing the parsed date and time, adjusted for the specified timezone.
20
+ *
21
+ * @throws {Error} If the `inputFormat` is invalid.
22
+ * @throws {Error} If the provided date or time is invalid.
23
+ *
24
+ * @example Format a Brazilian date to Date
25
+ * ```typescript
26
+ * const date = parseToDate(["25/12/2023", "15:30:00"], "brazilianDate", -3);
27
+ * console.log(date); // Outputs a Date object for "2023-12-25T12:30:00.000Z" (UTC)
28
+ * ```
29
+ * @example Format an ISO date to Date
30
+ * ```typescript
31
+ * const date = parseToDate(["12-25-2023", "15:30:00"], "isoDate", 2);
32
+ * console.log(date); // Outputs a Date object for "2023-12-25T13:30:00.000Z" (UTC)
33
+ * ```
34
+ * @example Format a timestamp date to Date
35
+ * ```typescript
36
+ * const date = parseToDate(["2023-12-25", "15:30:00"], "timestamp");
37
+ * console.log(date); // Outputs a Date object for "2023-12-25T15:30:00.000Z" (UTC)
38
+ * ```
39
+ */
40
+ function parseToDate([date, time = "00:00:00"], inputFormat, timezone = 0) {
41
+ const validateDateService = new ValidateDateService();
42
+ validateDateService.validateInputFormat(inputFormat);
43
+ const dateParts = date.split(/[-/]/).map(Number);
44
+ const timeParts = time.split(".")[0].split(":").map(Number);
45
+ let day, month, year;
46
+ const [hours = 0, minutes = 0, seconds = 0] = timeParts;
47
+ switch (inputFormat) {
48
+ case "brazilianDate":
49
+ [day, month, year] = dateParts;
50
+ validateDateService.validateDateParts(year, month, day);
51
+ break;
52
+ case "isoDate":
53
+ [month, day, year] = dateParts;
54
+ validateDateService.validateDateParts(year, month, day);
55
+ break;
56
+ case "timestamp":
57
+ [year, month, day] = dateParts;
58
+ validateDateService.validateDateParts(year, month, day);
59
+ break;
60
+ }
61
+ const formattedDate = new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds));
62
+ if (isNaN(formattedDate.getTime()))
63
+ throw new Error("Invalid date");
64
+ formattedDate.setUTCHours(formattedDate.getUTCHours() + timezone);
65
+ return formattedDate;
66
+ }
67
+ export { parseToDate };
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Service for validating date components and input formats.
3
+ *
4
+ * This service provides methods to validate date parts (year, month, day) and
5
+ * input format strings used in date parsing operations. It includes leap year
6
+ * validation and month-specific day validation.
7
+ *
8
+ * @remarks
9
+ * The service validates:
10
+ * - Year must be exactly 4 digits (1000-9999)
11
+ * - Month must be between 1 and 12
12
+ * - Day must be between 1 and 31
13
+ * - Day must be valid for the specific month (e.g., no February 30)
14
+ * - Leap year rules for February 29
15
+ *
16
+ * @example Validate a valid date
17
+ * ```typescript
18
+ * const service = new ValidateDateService();
19
+ * service.validateDateParts(2024, 1, 15); // No error thrown
20
+ * ```
21
+ *
22
+ * @example Validate an invalid date
23
+ * ```typescript
24
+ * const service = new ValidateDateService();
25
+ * service.validateDateParts(2023, 2, 29); // Throws: "Day 29 is not valid for February 2023 (non-leap year)"
26
+ * ```
27
+ *
28
+ * @example Validate input format
29
+ * ```typescript
30
+ * const service = new ValidateDateService();
31
+ * service.validateInputFormat("brazilianDate"); // No error thrown
32
+ * service.validateInputFormat("invalidFormat"); // Throws: "Invalid input format: invalidFormat"
33
+ * ```
34
+ */
35
+ declare class ValidateDateService {
36
+ private isLeapYear;
37
+ private getDaysInMonth;
38
+ private validateDayInMonth;
39
+ /**
40
+ * Validates the components of a date (year, month, and day).
41
+ *
42
+ * @param {number} year - The year to validate (must be 4 digits).
43
+ * @param {number} month - The month to validate (must be between 1 and 12).
44
+ * @param {number} day - The day to validate (must be between 1 and 31, and valid for the month).
45
+ *
46
+ * @throws {Error} "Year should be four digits" - If the year doesn't have exactly 4 digits.
47
+ * @throws {Error} "Month should be between 1 and 12" - If the month is out of valid range.
48
+ * @throws {Error} "Day should be between 1 and 31" - If the day is out of valid range.
49
+ * @throws {Error} Month-specific error - If the day is invalid for the specific month.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const service = new ValidateDateService();
54
+ * service.validateDateParts(2024, 2, 29); // Valid leap year date
55
+ * service.validateDateParts(2023, 2, 29); // Throws error - not a leap year
56
+ * service.validateDateParts(2024, 4, 31); // Throws error - April has only 30 days
57
+ * ```
58
+ */
59
+ validateDateParts(year: number, month: number, day: number): void;
60
+ /**
61
+ * Validates that a given format string is supported.
62
+ *
63
+ * @param {string} format - The format string to validate.
64
+ *
65
+ * @throws {Error} "Invalid input format: {format}" - If the format is not one of the valid formats.
66
+ *
67
+ * @remarks
68
+ * Valid formats are:
69
+ * - "brazilianDate": DD/MM/YYYY format
70
+ * - "isoDate": MM-DD-YYYY format
71
+ * - "timestamp": YYYY-MM-DD format
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const service = new ValidateDateService();
76
+ * service.validateInputFormat("brazilianDate"); // Valid
77
+ * service.validateInputFormat("isoDate"); // Valid
78
+ * service.validateInputFormat("timestamp"); // Valid
79
+ * service.validateInputFormat("customFormat"); // Throws error
80
+ * ```
81
+ */
82
+ validateInputFormat(format: string): void;
83
+ }
84
+ export { ValidateDateService };
85
+ //# sourceMappingURL=validateDateService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateDateService.d.ts","sourceRoot":"","sources":["../../src/services/validateDateService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,cAAM,mBAAmB;IACvB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,kBAAkB;IA2B1B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAcjE;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAM1C;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}