@arkyn/shared 3.0.1-beta.14 → 3.0.1-beta.140

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 +3749 -0
  3. package/dist/bundle.umd.cjs +10 -0
  4. package/dist/formats/formatDate.d.ts +44 -16
  5. package/dist/formats/formatDate.d.ts.map +1 -1
  6. package/dist/formats/formatDate.js +61 -26
  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/formatToCep.d.ts +5 -12
  11. package/dist/formats/formatToCep.d.ts.map +1 -1
  12. package/dist/formats/formatToCep.js +11 -16
  13. package/dist/formats/formatToCnpj.d.ts +3 -13
  14. package/dist/formats/formatToCnpj.d.ts.map +1 -1
  15. package/dist/formats/formatToCnpj.js +9 -17
  16. package/dist/formats/formatToCpf.d.ts +5 -13
  17. package/dist/formats/formatToCpf.d.ts.map +1 -1
  18. package/dist/formats/formatToCpf.js +11 -17
  19. package/dist/formats/formatToCurrency.d.ts +18 -14
  20. package/dist/formats/formatToCurrency.d.ts.map +1 -1
  21. package/dist/formats/formatToCurrency.js +21 -14
  22. package/dist/formats/formatToEllipsis.d.ts +8 -5
  23. package/dist/formats/formatToEllipsis.d.ts.map +1 -1
  24. package/dist/formats/formatToEllipsis.js +21 -7
  25. package/dist/formats/formatToHiddenDigits.d.ts +16 -16
  26. package/dist/formats/formatToHiddenDigits.d.ts.map +1 -1
  27. package/dist/formats/formatToHiddenDigits.js +19 -19
  28. package/dist/formats/formatToPhone.d.ts +11 -22
  29. package/dist/formats/formatToPhone.d.ts.map +1 -1
  30. package/dist/formats/formatToPhone.js +31 -118
  31. package/dist/generators/generateColorByString.d.ts +7 -4
  32. package/dist/generators/generateColorByString.d.ts.map +1 -1
  33. package/dist/generators/generateColorByString.js +10 -6
  34. package/dist/generators/generateId.d.ts +3 -3
  35. package/dist/generators/generateSlug.d.ts +10 -3
  36. package/dist/generators/generateSlug.d.ts.map +1 -1
  37. package/dist/generators/generateSlug.js +11 -4
  38. package/dist/index.d.ts +11 -16
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +13 -17
  41. package/dist/{services/truncateLargeFields.d.ts → parsers/parseLargeFields.d.ts} +9 -11
  42. package/dist/parsers/parseLargeFields.d.ts.map +1 -0
  43. package/dist/{services/truncateLargeFields.js → parsers/parseLargeFields.js} +12 -13
  44. package/dist/parsers/parseSensitiveData.d.ts +23 -0
  45. package/dist/parsers/parseSensitiveData.d.ts.map +1 -0
  46. package/dist/{services/maskSensitiveData.js → parsers/parseSensitiveData.js} +10 -12
  47. package/dist/parsers/parseToDate.d.ts +41 -0
  48. package/dist/parsers/parseToDate.d.ts.map +1 -0
  49. package/dist/parsers/parseToDate.js +67 -0
  50. package/dist/services/validateDateService.d.ts +85 -0
  51. package/dist/services/validateDateService.d.ts.map +1 -0
  52. package/dist/services/validateDateService.js +132 -0
  53. package/dist/{services → utilities}/calculateCardInstallment.d.ts +16 -18
  54. package/dist/utilities/calculateCardInstallment.d.ts.map +1 -0
  55. package/dist/{services → utilities}/calculateCardInstallment.js +12 -15
  56. package/dist/utilities/ensureQuotes.d.ts +21 -0
  57. package/dist/utilities/ensureQuotes.d.ts.map +1 -0
  58. package/dist/{services → utilities}/ensureQuotes.js +12 -4
  59. package/dist/utilities/findCountryMask.d.ts +45 -0
  60. package/dist/utilities/findCountryMask.d.ts.map +1 -0
  61. package/dist/utilities/findCountryMask.js +73 -0
  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 +26 -6
  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
@@ -1,14 +0,0 @@
1
- type EnsureQuotesFunction = (rawValue: string) => string;
2
- /**
3
- * Ensures that a given rawValue string is enclosed in quotes.
4
- *
5
- * This function checks if the input string is already enclosed in either single
6
- * quotes (`'`) or double quotes (`"`). If the string is already quoted, it is
7
- * returned as-is. Otherwise, the function wraps the string in double quotes.
8
- *
9
- * @param url - The URL string to be checked and potentially quoted.
10
- * @returns The input string, either unchanged if it is already quoted, or wrapped in double quotes.
11
- */
12
- declare const ensureQuotes: EnsureQuotesFunction;
13
- export { ensureQuotes };
14
- //# sourceMappingURL=ensureQuotes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ensureQuotes.d.ts","sourceRoot":"","sources":["../../src/services/ensureQuotes.ts"],"names":[],"mappings":"AAAA,KAAK,oBAAoB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;AAEzD;;;;;;;;;GASG;AAEH,QAAA,MAAM,YAAY,EAAE,oBASnB,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,26 +0,0 @@
1
- type MaskSensitiveDataFunction = (jsonString: string, sensitiveKeys?: string[]) => string;
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;
25
- export { maskSensitiveData };
26
- //# sourceMappingURL=maskSensitiveData.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"maskSensitiveData.d.ts","sourceRoot":"","sources":["../../src/services/maskSensitiveData.ts"],"names":[],"mappings":"AAAA,KAAK,yBAAyB,GAAG,CAC/B,UAAU,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,MAAM,EAAE,KACrB,MAAM,CAAC;AAEZ;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,QAAA,MAAM,iBAAiB,EAAE,yBAqCxB,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"removeCurrencySymbols.d.ts","sourceRoot":"","sources":["../../src/services/removeCurrencySymbols.ts"],"names":[],"mappings":"AAAA,KAAK,6BAA6B,GAAG,CAAC,cAAc,EAAE,MAAM,KAAK,MAAM,CAAC;AAExE;;;;;;;;;;;;;;;;GAgBG;AAEH,QAAA,MAAM,qBAAqB,EAAE,6BAM5B,CAAC;AAEF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
@@ -1,16 +0,0 @@
1
- type RemoveNonNumericFunction = (formattedValue: string) => string;
2
- /**
3
- * Removes all non-numeric characters from a given string.
4
- *
5
- * @param prop - The input string from which non-numeric characters will be removed.
6
- * @returns A new string containing only numeric characters from the input.
7
- *
8
- * @example
9
- * ```typescript
10
- * const result = removeNonNumeric("abc123def456");
11
- * console.log(result); // Output: "123456"
12
- * ```
13
- */
14
- declare const removeNonNumeric: RemoveNonNumericFunction;
15
- export { removeNonNumeric };
16
- //# sourceMappingURL=removeNonNumeric.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"removeNonNumeric.d.ts","sourceRoot":"","sources":["../../src/services/removeNonNumeric.ts"],"names":[],"mappings":"AAAA,KAAK,wBAAwB,GAAG,CAAC,cAAc,EAAE,MAAM,KAAK,MAAM,CAAC;AAEnE;;;;;;;;;;;GAWG;AAEH,QAAA,MAAM,gBAAgB,EAAE,wBAEvB,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Removes all non-numeric characters from a given string.
3
- *
4
- * @param prop - The input string from which non-numeric characters will be removed.
5
- * @returns A new string containing only numeric characters from the input.
6
- *
7
- * @example
8
- * ```typescript
9
- * const result = removeNonNumeric("abc123def456");
10
- * console.log(result); // Output: "123456"
11
- * ```
12
- */
13
- const removeNonNumeric = (prop) => {
14
- return prop.replace(/[^0-9]/g, "");
15
- };
16
- export { removeNonNumeric };
@@ -1,16 +0,0 @@
1
- type StripHtmlTagsFunction = (rawHtml: string) => string;
2
- /**
3
- * Strips HTML tags from a string.
4
- *
5
- * This function removes all HTML tags from the provided string by replacing any content
6
- * that matches the HTML tag pattern with an empty string.
7
- *
8
- * @param rawHtml - The HTML string to be processed
9
- * @returns The input string with all HTML tags removed
10
- *
11
- * @example
12
- * stripHtmlTags("<p>Hello <strong>World</strong></p>"); // "Hello World"
13
- */
14
- declare const stripHtmlTags: StripHtmlTagsFunction;
15
- export { stripHtmlTags };
16
- //# sourceMappingURL=stripHtmlTags.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stripHtmlTags.d.ts","sourceRoot":"","sources":["../../src/services/stripHtmlTags.ts"],"names":[],"mappings":"AAAA,KAAK,qBAAqB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;AAEzD;;;;;;;;;;;GAWG;AAEH,QAAA,MAAM,aAAa,EAAE,qBAEpB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Strips HTML tags from a string.
3
- *
4
- * This function removes all HTML tags from the provided string by replacing any content
5
- * that matches the HTML tag pattern with an empty string.
6
- *
7
- * @param rawHtml - The HTML string to be processed
8
- * @returns The input string with all HTML tags removed
9
- *
10
- * @example
11
- * stripHtmlTags("<p>Hello <strong>World</strong></p>"); // "Hello World"
12
- */
13
- const stripHtmlTags = (rawHtml) => {
14
- return rawHtml.replace(/<\/?[^>]+(>|$)/g, "");
15
- };
16
- export { stripHtmlTags };
@@ -1 +0,0 @@
1
- {"version":3,"file":"truncateLargeFields.d.ts","sourceRoot":"","sources":["../../src/services/truncateLargeFields.ts"],"names":[],"mappings":"AAAA,KAAK,2BAA2B,GAAG,CACjC,UAAU,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,MAAM,KACf,MAAM,CAAC;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,QAAA,MAAM,mBAAmB,EAAE,2BAgC1B,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
@@ -1,24 +0,0 @@
1
- type ValidateCepFunction = (rawCep: string) => boolean;
2
- /**
3
- * Removes all non-digit characters from the CEP.
4
- * @param cep - Raw CEP string.
5
- * @returns Only numeric characters.
6
- */
7
- /**
8
- * Validates a Brazilian CEP (Código de Endereçamento Postal).
9
- *
10
- * A valid CEP has 8 numeric digits.
11
- *
12
- * @param rawCep - CEP string, may include formatting (e.g., "12345-678").
13
- * @returns `true` if the CEP is valid, otherwise `false`.
14
- *
15
- * @example
16
- * ```ts
17
- * validateCep("12345-678"); // true
18
- * validateCep("12345678"); // true
19
- * validateCep("ABCDE-123"); // false
20
- * ```
21
- */
22
- declare const validateCep: ValidateCepFunction;
23
- export { validateCep };
24
- //# sourceMappingURL=validateCep.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validateCep.d.ts","sourceRoot":"","sources":["../../src/validations/validateCep.ts"],"names":[],"mappings":"AAEA,KAAK,mBAAmB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;AAEvD;;;;GAIG;AAEH;;;;;;;;;;;;;;GAcG;AAEH,QAAA,MAAM,WAAW,EAAE,mBAYlB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -1,33 +0,0 @@
1
- import { removeNonNumeric } from "../services/removeNonNumeric";
2
- /**
3
- * Removes all non-digit characters from the CEP.
4
- * @param cep - Raw CEP string.
5
- * @returns Only numeric characters.
6
- */
7
- /**
8
- * Validates a Brazilian CEP (Código de Endereçamento Postal).
9
- *
10
- * A valid CEP has 8 numeric digits.
11
- *
12
- * @param rawCep - CEP string, may include formatting (e.g., "12345-678").
13
- * @returns `true` if the CEP is valid, otherwise `false`.
14
- *
15
- * @example
16
- * ```ts
17
- * validateCep("12345-678"); // true
18
- * validateCep("12345678"); // true
19
- * validateCep("ABCDE-123"); // false
20
- * ```
21
- */
22
- const validateCep = (rawCep) => {
23
- if (!rawCep)
24
- return false;
25
- const validFormat = /^[0-9-]+$/.test(rawCep);
26
- if (!validFormat)
27
- return false;
28
- const cep = removeNonNumeric(rawCep);
29
- const CEP_LENGTH = 8;
30
- const isOnlyDigits = /^\d{8}$/.test(cep);
31
- return cep.length === CEP_LENGTH && isOnlyDigits;
32
- };
33
- export { validateCep };
@@ -1,22 +0,0 @@
1
- type ValidateCnpjFunction = (rawCnpj: string) => boolean;
2
- /**
3
- * Validates a Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica) number.
4
- *
5
- * This function performs:
6
- * - Sanitization (removes non-digit characters).
7
- * - Length check (must be 14 digits).
8
- * - Repeating digits check (invalid if all digits are the same).
9
- * - Verifies the two check digits with the proper weights.
10
- *
11
- * @param rawCnpj - CNPJ string, possibly formatted.
12
- * @returns `true` if valid, otherwise `false`.
13
- *
14
- * @example
15
- * ```ts
16
- * validateCnpj("12.345.678/0001-95"); // false
17
- * validateCnpj("11.444.777/0001-61"); // true
18
- * ```
19
- */
20
- declare const validateCnpj: ValidateCnpjFunction;
21
- export { validateCnpj };
22
- //# sourceMappingURL=validateCnpj.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validateCnpj.d.ts","sourceRoot":"","sources":["../../src/validations/validateCnpj.ts"],"names":[],"mappings":"AAEA,KAAK,oBAAoB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;AAyBzD;;;;;;;;;;;;;;;;;GAiBG;AAEH,QAAA,MAAM,YAAY,EAAE,oBAgBnB,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,52 +0,0 @@
1
- import { removeNonNumeric } from "../services/removeNonNumeric";
2
- function isInvalidLength(cnpj) {
3
- const CNPJ_LENGTH = 14;
4
- return cnpj.length !== CNPJ_LENGTH;
5
- }
6
- function hasAllDigitsEqual(cnpj) {
7
- const [firstDigit] = cnpj;
8
- return [...cnpj].every((digit) => digit === firstDigit);
9
- }
10
- function calculateDigit(cnpj, multipliers) {
11
- let total = 0;
12
- for (let i = 0; i < multipliers.length; i++) {
13
- total += parseInt(cnpj[i]) * multipliers[i];
14
- }
15
- const rest = total % 11;
16
- return rest < 2 ? 0 : 11 - rest;
17
- }
18
- function extractDigit(cnpj) {
19
- return cnpj.slice(12);
20
- }
21
- /**
22
- * Validates a Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica) number.
23
- *
24
- * This function performs:
25
- * - Sanitization (removes non-digit characters).
26
- * - Length check (must be 14 digits).
27
- * - Repeating digits check (invalid if all digits are the same).
28
- * - Verifies the two check digits with the proper weights.
29
- *
30
- * @param rawCnpj - CNPJ string, possibly formatted.
31
- * @returns `true` if valid, otherwise `false`.
32
- *
33
- * @example
34
- * ```ts
35
- * validateCnpj("12.345.678/0001-95"); // false
36
- * validateCnpj("11.444.777/0001-61"); // true
37
- * ```
38
- */
39
- const validateCnpj = (rawCnpj) => {
40
- if (!rawCnpj)
41
- return false;
42
- const cnpj = removeNonNumeric(rawCnpj);
43
- if (isInvalidLength(cnpj))
44
- return false;
45
- if (hasAllDigitsEqual(cnpj))
46
- return false;
47
- const base = cnpj.slice(0, 12);
48
- const digit1 = calculateDigit(base, [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]);
49
- const digit2 = calculateDigit(base + digit1, [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]);
50
- return extractDigit(cnpj) === `${digit1}${digit2}`;
51
- };
52
- export { validateCnpj };
@@ -1,24 +0,0 @@
1
- type ValidateCpfFunction = (rawCpf: string) => boolean;
2
- /**
3
- * Validates a Brazilian CPF (Cadastro de Pessoas Físicas) number.
4
- *
5
- * The CPF is a unique identifier assigned to Brazilian citizens and residents.
6
- * This function checks if the provided CPF is valid by performing the following steps:
7
- * - Removes any non-digit characters from the input.
8
- * - Verifies if the CPF has the correct length (11 digits).
9
- * - Ensures that all digits are not the same (e.g., "111.111.111-11" is invalid).
10
- * - Calculates the first and second verification digits using the CPF algorithm.
11
- * - Compares the calculated verification digits with the ones provided in the CPF.
12
- *
13
- * @param rawCpf - The raw CPF string, which may include formatting characters (e.g., dots or dashes).
14
- * @returns `true` if the CPF is valid, otherwise `false`.
15
- *
16
- * @example
17
- * ```typescript
18
- * validateCpf("123.456.789-09"); // false
19
- * validateCpf("111.444.777-35"); // true
20
- * ```
21
- */
22
- declare const validateCpf: ValidateCpfFunction;
23
- export { validateCpf };
24
- //# sourceMappingURL=validateCpf.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validateCpf.d.ts","sourceRoot":"","sources":["../../src/validations/validateCpf.ts"],"names":[],"mappings":"AAEA,KAAK,mBAAmB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;AAyBvD;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,QAAA,MAAM,WAAW,EAAE,mBAWlB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -1,54 +0,0 @@
1
- import { removeNonNumeric } from "../services/removeNonNumeric";
2
- function isInvalidLength(cpf) {
3
- const CPF_LENGTH = 11;
4
- return cpf.length !== CPF_LENGTH;
5
- }
6
- function hasAllDigitsEqual(cpf) {
7
- const [firstCpfDigit] = cpf;
8
- return [...cpf].every((digit) => digit === firstCpfDigit);
9
- }
10
- function calculateDigit(cpf, factor) {
11
- let total = 0;
12
- for (const digit of cpf) {
13
- if (factor > 1)
14
- total += parseInt(digit) * factor--;
15
- }
16
- const rest = total % 11;
17
- return rest < 2 ? 0 : 11 - rest;
18
- }
19
- function extractDigit(cpf) {
20
- return cpf.slice(9);
21
- }
22
- /**
23
- * Validates a Brazilian CPF (Cadastro de Pessoas Físicas) number.
24
- *
25
- * The CPF is a unique identifier assigned to Brazilian citizens and residents.
26
- * This function checks if the provided CPF is valid by performing the following steps:
27
- * - Removes any non-digit characters from the input.
28
- * - Verifies if the CPF has the correct length (11 digits).
29
- * - Ensures that all digits are not the same (e.g., "111.111.111-11" is invalid).
30
- * - Calculates the first and second verification digits using the CPF algorithm.
31
- * - Compares the calculated verification digits with the ones provided in the CPF.
32
- *
33
- * @param rawCpf - The raw CPF string, which may include formatting characters (e.g., dots or dashes).
34
- * @returns `true` if the CPF is valid, otherwise `false`.
35
- *
36
- * @example
37
- * ```typescript
38
- * validateCpf("123.456.789-09"); // false
39
- * validateCpf("111.444.777-35"); // true
40
- * ```
41
- */
42
- const validateCpf = (rawCpf) => {
43
- if (!rawCpf)
44
- return false;
45
- const cpf = removeNonNumeric(rawCpf);
46
- if (isInvalidLength(cpf))
47
- return false;
48
- if (hasAllDigitsEqual(cpf))
49
- return false;
50
- const digit1 = calculateDigit(cpf, 10);
51
- const digit2 = calculateDigit(cpf, 11);
52
- return extractDigit(cpf) === `${digit1}${digit2}`;
53
- };
54
- export { validateCpf };
@@ -1,34 +0,0 @@
1
- type ValidateDateConfig = {
2
- inputFormat?: "DD/MM/YYYY" | "MM-DD-YYYY" | "YYYY-MM-DD";
3
- minYear?: number;
4
- maxYear?: number;
5
- };
6
- type ValidateDateFunction = (rawDate: string, config?: ValidateDateConfig) => boolean;
7
- /**
8
- * Validates a date string based on the provided format and configuration.
9
- *
10
- * @param rawDate - The date string to validate.
11
- * @param config - Optional configuration object to customize validation.
12
- * @param config.inputFormat - The expected format of the input date.
13
- * Supported formats are "DD/MM/YYYY", "MM-DD-YYYY", and "YYYY-MM-DD".
14
- * Defaults to "DD/MM/YYYY".
15
- * @param config.minYear - The minimum allowed year for the date. Defaults to 1900.
16
- * @param config.maxYear - The maximum allowed year for the date. Defaults to 3000.
17
- *
18
- * @returns `true` if the date is valid according to the specified format and configuration, otherwise `false`.
19
- *
20
- * @throws {Error} If an invalid date format is provided in the configuration.
21
- *
22
- * @example
23
- * ```typescript
24
- * validateDate("31/12/2023"); // true
25
- * validateDate("12-31-2023", { inputFormat: "MM-DD-YYYY" }); // true
26
- * validateDate("2023-12-31", { inputFormat: "YYYY-MM-DD", minYear: 2000, maxYear: 2100 }); // true
27
- * validateDate("29/02/2024", { inputFormat: "DD/MM/YYYY" }); // true (leap year)
28
- * validateDate("29/02/2023", { inputFormat: "DD/MM/YYYY" }); // false (not a leap year)
29
- * validateDate("31/04/2023", { inputFormat: "DD/MM/YYYY" }); // false (April has 30 days)
30
- * ```
31
- */
32
- declare const validateDate: ValidateDateFunction;
33
- export { validateDate };
34
- //# sourceMappingURL=validateDate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validateDate.d.ts","sourceRoot":"","sources":["../../src/validations/validateDate.ts"],"names":[],"mappings":"AAAA,KAAK,kBAAkB,GAAG;IACxB,WAAW,CAAC,EAAE,YAAY,GAAG,YAAY,GAAG,YAAY,CAAC;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,oBAAoB,GAAG,CAC1B,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,kBAAkB,KACxB,OAAO,CAAC;AAEb;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,QAAA,MAAM,YAAY,EAAE,oBA8CnB,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,73 +0,0 @@
1
- /**
2
- * Validates a date string based on the provided format and configuration.
3
- *
4
- * @param rawDate - The date string to validate.
5
- * @param config - Optional configuration object to customize validation.
6
- * @param config.inputFormat - The expected format of the input date.
7
- * Supported formats are "DD/MM/YYYY", "MM-DD-YYYY", and "YYYY-MM-DD".
8
- * Defaults to "DD/MM/YYYY".
9
- * @param config.minYear - The minimum allowed year for the date. Defaults to 1900.
10
- * @param config.maxYear - The maximum allowed year for the date. Defaults to 3000.
11
- *
12
- * @returns `true` if the date is valid according to the specified format and configuration, otherwise `false`.
13
- *
14
- * @throws {Error} If an invalid date format is provided in the configuration.
15
- *
16
- * @example
17
- * ```typescript
18
- * validateDate("31/12/2023"); // true
19
- * validateDate("12-31-2023", { inputFormat: "MM-DD-YYYY" }); // true
20
- * validateDate("2023-12-31", { inputFormat: "YYYY-MM-DD", minYear: 2000, maxYear: 2100 }); // true
21
- * validateDate("29/02/2024", { inputFormat: "DD/MM/YYYY" }); // true (leap year)
22
- * validateDate("29/02/2023", { inputFormat: "DD/MM/YYYY" }); // false (not a leap year)
23
- * validateDate("31/04/2023", { inputFormat: "DD/MM/YYYY" }); // false (April has 30 days)
24
- * ```
25
- */
26
- const validateDate = (rawDate, config) => {
27
- let day, month, year;
28
- const inputFormat = config?.inputFormat || "DD/MM/YYYY";
29
- const minYear = config?.minYear || 1900;
30
- const maxYear = config?.maxYear || 3000;
31
- if (inputFormat === "DD/MM/YYYY") {
32
- const dateRegex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
33
- if (!dateRegex.test(rawDate))
34
- return false;
35
- [, day, month, year] = rawDate.match(dateRegex) || [];
36
- }
37
- else if (inputFormat === "MM-DD-YYYY") {
38
- const dateRegex = /^(\d{2})-(\d{2})-(\d{4})$/;
39
- if (!dateRegex.test(rawDate))
40
- return false;
41
- [, month, day, year] = rawDate.match(dateRegex) || [];
42
- }
43
- else if (inputFormat === "YYYY-MM-DD") {
44
- const dateRegex = /^(\d{4})-(\d{2})-(\d{2})$/;
45
- if (!dateRegex.test(rawDate))
46
- return false;
47
- [, year, month, day] = rawDate.match(dateRegex) || [];
48
- }
49
- else {
50
- throw new Error("Invalid date format");
51
- }
52
- const dayNum = parseInt(day, 10);
53
- const monthNum = parseInt(month, 10);
54
- const yearNum = parseInt(year, 10);
55
- if (dayNum < 1 || dayNum > 31)
56
- return false;
57
- if (monthNum < 1 || monthNum > 12)
58
- return false;
59
- const daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
60
- if (monthNum === 2) {
61
- const isLeapYear = (yearNum % 4 === 0 && yearNum % 100 !== 0) || yearNum % 400 === 0;
62
- if (dayNum > (isLeapYear ? 29 : 28))
63
- return false;
64
- }
65
- else if (dayNum > daysInMonth[monthNum - 1]) {
66
- return false;
67
- }
68
- if (yearNum < minYear || yearNum > maxYear)
69
- return false;
70
- const isValidDate = new Date(yearNum, monthNum - 1, dayNum).getDate() === dayNum;
71
- return isValidDate;
72
- };
73
- export { validateDate };
@@ -1,21 +0,0 @@
1
- type ValidatePasswordFunction = (rawPassword: string) => boolean;
2
- /**
3
- * Validates a password based on the following rules:
4
- * - At least 8 characters
5
- * - At least 1 uppercase letter
6
- * - At least 1 letter (any case)
7
- * - At least 1 number
8
- * - At least 1 special character
9
- *
10
- * @param rawPassword - The raw password string.
11
- * @returns `true` if password is valid, otherwise `false`.
12
- *
13
- * @example
14
- * ```ts
15
- * validatePassword("Senha@123"); // true
16
- * validatePassword("senha123"); // false (no uppercase, no special char)
17
- * ```
18
- */
19
- declare const validatePassword: ValidatePasswordFunction;
20
- export { validatePassword };
21
- //# sourceMappingURL=validatePassword.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validatePassword.d.ts","sourceRoot":"","sources":["../../src/validations/validatePassword.ts"],"names":[],"mappings":"AAAA,KAAK,wBAAwB,GAAG,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;AAEjE;;;;;;;;;;;;;;;;GAgBG;AAEH,QAAA,MAAM,gBAAgB,EAAE,wBAkBvB,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -1,34 +0,0 @@
1
- /**
2
- * Validates a password based on the following rules:
3
- * - At least 8 characters
4
- * - At least 1 uppercase letter
5
- * - At least 1 letter (any case)
6
- * - At least 1 number
7
- * - At least 1 special character
8
- *
9
- * @param rawPassword - The raw password string.
10
- * @returns `true` if password is valid, otherwise `false`.
11
- *
12
- * @example
13
- * ```ts
14
- * validatePassword("Senha@123"); // true
15
- * validatePassword("senha123"); // false (no uppercase, no special char)
16
- * ```
17
- */
18
- const validatePassword = (rawPassword) => {
19
- if (!rawPassword)
20
- return false;
21
- const hasMinLength = rawPassword.length >= 8;
22
- const hasUppercase = /[A-Z]/.test(rawPassword);
23
- const hasLetter = /[a-z]/.test(rawPassword);
24
- const hasNumber = /\d/.test(rawPassword);
25
- const hasSpecialChar = /[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(rawPassword);
26
- return [
27
- hasMinLength,
28
- hasUppercase,
29
- hasLetter,
30
- hasNumber,
31
- hasSpecialChar,
32
- ].every((condition) => condition);
33
- };
34
- export { validatePassword };
@@ -1,29 +0,0 @@
1
- type ValidatePhoneFunction = (rawPhone: string) => boolean;
2
- /**
3
- * Validates a phone number against a list of country-specific formats.
4
- *
5
- * The function iterates through a predefined list of countries and checks if the
6
- * provided phone number matches the format for any of the countries. It uses
7
- * regular expressions to validate the phone number based on the country's code,
8
- * prefix, and mask.
9
- *
10
- * Special handling is applied for Brazilian phone numbers (ISO code "BR"), which
11
- * allows for an optional ninth digit.
12
- *
13
- * @param rawPhone - The phone number to validate as a string.
14
- * @returns `true` if the phone number matches any country's format, otherwise `false`.
15
- *
16
- * @example
17
- * ```typescript
18
- * import { validatePhone } from "./validatePhone";
19
- *
20
- * validatePhone("+55 32912345678"); // true for a valid Brazilian phone number
21
- * validatePhone("+55 3212345678"); // true for a valid Brazilian phone number
22
- * validatePhone("+1-684 1234567"); // true for a valid American Samoa phone number
23
- * validatePhone("+5532912345678"); // false for an invalid Brazilian phone number
24
- * validatePhone("+55 1234567890"); // false for an invalid Brazilian phone number
25
- * ```
26
- */
27
- declare const validatePhone: ValidatePhoneFunction;
28
- export { validatePhone };
29
- //# sourceMappingURL=validatePhone.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validatePhone.d.ts","sourceRoot":"","sources":["../../src/validations/validatePhone.ts"],"names":[],"mappings":"AAEA,KAAK,qBAAqB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,QAAA,MAAM,aAAa,EAAE,qBAiBpB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -1,44 +0,0 @@
1
- import { countries } from "@arkyn/templates";
2
- /**
3
- * Validates a phone number against a list of country-specific formats.
4
- *
5
- * The function iterates through a predefined list of countries and checks if the
6
- * provided phone number matches the format for any of the countries. It uses
7
- * regular expressions to validate the phone number based on the country's code,
8
- * prefix, and mask.
9
- *
10
- * Special handling is applied for Brazilian phone numbers (ISO code "BR"), which
11
- * allows for an optional ninth digit.
12
- *
13
- * @param rawPhone - The phone number to validate as a string.
14
- * @returns `true` if the phone number matches any country's format, otherwise `false`.
15
- *
16
- * @example
17
- * ```typescript
18
- * import { validatePhone } from "./validatePhone";
19
- *
20
- * validatePhone("+55 32912345678"); // true for a valid Brazilian phone number
21
- * validatePhone("+55 3212345678"); // true for a valid Brazilian phone number
22
- * validatePhone("+1-684 1234567"); // true for a valid American Samoa phone number
23
- * validatePhone("+5532912345678"); // false for an invalid Brazilian phone number
24
- * validatePhone("+55 1234567890"); // false for an invalid Brazilian phone number
25
- * ```
26
- */
27
- const validatePhone = (rawPhone) => {
28
- for (const country of countries) {
29
- const countryCode = country.code;
30
- const prefix = country.prefix ? `-${country.prefix}` : "";
31
- const digitCount = country.mask.replace(/[^_]/g, "").length;
32
- if (country.iso === "BR") {
33
- const brazilRegex = new RegExp(`^\\${countryCode} \\d{2}9?\\d{8}$`);
34
- if (brazilRegex.test(rawPhone))
35
- return true;
36
- continue;
37
- }
38
- const regex = new RegExp(`^\\${countryCode}${prefix} \\d{${digitCount}}$`);
39
- if (regex.test(rawPhone))
40
- return true;
41
- }
42
- return false;
43
- };
44
- export { validatePhone };
@@ -1,22 +0,0 @@
1
- type ValidateRgFunction = (rawRg: string) => boolean;
2
- /**
3
- * Validates a Brazilian RG (Registro Geral) in a generic way.
4
- *
5
- * This function does a basic structure validation:
6
- * - Removes non-alphanumeric characters.
7
- * - Ensures length is reasonable (7–9 digits).
8
- * - Optionally allows for a final letter (verifier).
9
- *
10
- * @param rawRg - RG string, possibly formatted.
11
- * @returns `true` if format seems valid, otherwise `false`.
12
- *
13
- * @example
14
- * ```ts
15
- * validateRg("12.345.678-9"); // true
16
- * validateRg("MG-12.345.678"); // false (not supported)
17
- * validateRg("12345678X"); // true
18
- * ```
19
- */
20
- declare const validateRg: ValidateRgFunction;
21
- export { validateRg };
22
- //# sourceMappingURL=validateRg.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validateRg.d.ts","sourceRoot":"","sources":["../../src/validations/validateRg.ts"],"names":[],"mappings":"AAAA,KAAK,kBAAkB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAErD;;;;;;;;;;;;;;;;;GAiBG;AAEH,QAAA,MAAM,UAAU,EAAE,kBAajB,CAAC;AAEF,OAAO,EAAE,UAAU,EAAE,CAAC"}