@arkyn/shared 1.5.0 → 1.5.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 (179) hide show
  1. package/LICENSE.txt +24 -0
  2. package/README.md +113 -0
  3. package/dist/formats/formatDate.d.ts +43 -0
  4. package/dist/formats/formatDate.d.ts.map +1 -0
  5. package/dist/formats/formatDate.js +77 -0
  6. package/dist/formats/formatJsonObject.d.ts +31 -1
  7. package/dist/formats/formatJsonObject.d.ts.map +1 -1
  8. package/dist/formats/formatJsonObject.js +67 -26
  9. package/dist/formats/formatJsonString.d.ts +37 -1
  10. package/dist/formats/formatJsonString.d.ts.map +1 -1
  11. package/dist/formats/formatJsonString.js +38 -4
  12. package/dist/formats/formatToCep.d.ts +27 -1
  13. package/dist/formats/formatToCep.d.ts.map +1 -1
  14. package/dist/formats/formatToCep.js +31 -6
  15. package/dist/formats/formatToCnpj.d.ts +30 -0
  16. package/dist/formats/formatToCnpj.d.ts.map +1 -0
  17. package/dist/formats/formatToCnpj.js +35 -0
  18. package/dist/formats/formatToCpf.d.ts +30 -0
  19. package/dist/formats/formatToCpf.d.ts.map +1 -0
  20. package/dist/formats/formatToCpf.js +35 -0
  21. package/dist/formats/formatToCpfCnpj.d.ts +22 -1
  22. package/dist/formats/formatToCpfCnpj.d.ts.map +1 -1
  23. package/dist/formats/formatToCpfCnpj.js +27 -7
  24. package/dist/formats/formatToCurrency.d.ts +29 -0
  25. package/dist/formats/formatToCurrency.d.ts.map +1 -0
  26. package/dist/formats/formatToCurrency.js +41 -0
  27. package/dist/formats/formatToEllipsis.d.ts +14 -1
  28. package/dist/formats/formatToEllipsis.d.ts.map +1 -1
  29. package/dist/formats/formatToEllipsis.js +20 -3
  30. package/dist/formats/formatToHiddenDigits.d.ts +30 -2
  31. package/dist/formats/formatToHiddenDigits.d.ts.map +1 -1
  32. package/dist/formats/formatToHiddenDigits.js +49 -3
  33. package/dist/formats/formatToPhone.d.ts +32 -1
  34. package/dist/formats/formatToPhone.d.ts.map +1 -1
  35. package/dist/formats/formatToPhone.js +128 -6
  36. package/dist/generators/generateColorByString.d.ts +13 -1
  37. package/dist/generators/generateColorByString.d.ts.map +1 -1
  38. package/dist/generators/generateColorByString.js +15 -4
  39. package/dist/generators/generateId.d.ts +26 -4
  40. package/dist/generators/generateId.d.ts.map +1 -1
  41. package/dist/generators/generateId.js +11 -5
  42. package/dist/generators/generateSlug.d.ts +15 -1
  43. package/dist/generators/generateSlug.d.ts.map +1 -1
  44. package/dist/generators/generateSlug.js +16 -2
  45. package/dist/index.d.ts +9 -10
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +10 -12
  48. package/dist/services/calculateCardInstallment.d.ts +31 -5
  49. package/dist/services/calculateCardInstallment.d.ts.map +1 -1
  50. package/dist/services/calculateCardInstallment.js +52 -11
  51. package/dist/services/maskSensitiveData.d.ts +24 -1
  52. package/dist/services/maskSensitiveData.d.ts.map +1 -1
  53. package/dist/services/maskSensitiveData.js +24 -2
  54. package/dist/services/removeCurrencySymbols.d.ts +20 -0
  55. package/dist/services/removeCurrencySymbols.d.ts.map +1 -0
  56. package/dist/services/removeCurrencySymbols.js +23 -0
  57. package/dist/services/removeNonNumeric.d.ts +15 -0
  58. package/dist/services/removeNonNumeric.d.ts.map +1 -0
  59. package/dist/services/removeNonNumeric.js +16 -0
  60. package/dist/services/truncateLargeFields.d.ts +30 -1
  61. package/dist/services/truncateLargeFields.d.ts.map +1 -1
  62. package/dist/services/truncateLargeFields.js +34 -6
  63. package/dist/validations/validateCep.d.ts +24 -0
  64. package/dist/validations/validateCep.d.ts.map +1 -0
  65. package/dist/validations/validateCep.js +33 -0
  66. package/dist/validations/validateCnpj.d.ts +22 -0
  67. package/dist/validations/validateCnpj.d.ts.map +1 -0
  68. package/dist/validations/validateCnpj.js +52 -0
  69. package/dist/validations/validateCpf.d.ts +24 -0
  70. package/dist/validations/validateCpf.d.ts.map +1 -0
  71. package/dist/validations/validateCpf.js +54 -0
  72. package/dist/validations/validateDate.d.ts +27 -6
  73. package/dist/validations/validateDate.d.ts.map +1 -1
  74. package/dist/validations/validateDate.js +38 -12
  75. package/dist/validations/validatePassword.d.ts +21 -0
  76. package/dist/validations/validatePassword.d.ts.map +1 -0
  77. package/dist/validations/validatePassword.js +34 -0
  78. package/dist/validations/validatePhone.d.ts +27 -1
  79. package/dist/validations/validatePhone.d.ts.map +1 -1
  80. package/dist/validations/validatePhone.js +29 -4
  81. package/dist/validations/validateRg.d.ts +22 -0
  82. package/dist/validations/validateRg.d.ts.map +1 -0
  83. package/dist/validations/validateRg.js +31 -0
  84. package/package.json +7 -2
  85. package/src/formats/__test__/formatDate.spec.ts +88 -0
  86. package/src/formats/__test__/formatJsonObject.spec.ts +87 -0
  87. package/src/formats/__test__/formatJsonString.spec.ts +83 -0
  88. package/src/formats/__test__/formatToCep.spec.ts +37 -0
  89. package/src/formats/__test__/formatToCnpj.spec.ts +35 -0
  90. package/src/formats/__test__/formatToCpf.spec.ts +37 -0
  91. package/src/formats/__test__/formatToCpfCnpj.spec.ts +43 -0
  92. package/src/formats/__test__/formatToCurrency.spec.ts +50 -0
  93. package/src/formats/__test__/formatToEllipsis.spec.ts +44 -0
  94. package/src/formats/__test__/formatToHiddenDigits.spec.ts +58 -0
  95. package/src/formats/__test__/formatToPhone.spec.ts +58 -0
  96. package/src/formats/formatDate.ts +97 -0
  97. package/src/formats/formatJsonObject.ts +68 -26
  98. package/src/formats/formatJsonString.ts +40 -4
  99. package/src/formats/formatToCep.ts +35 -7
  100. package/src/formats/formatToCnpj.ts +39 -0
  101. package/src/formats/formatToCpf.ts +39 -0
  102. package/src/formats/formatToCpfCnpj.ts +31 -7
  103. package/src/formats/formatToCurrency.ts +53 -0
  104. package/src/formats/formatToEllipsis.ts +23 -3
  105. package/src/formats/formatToHiddenDigits.ts +75 -7
  106. package/src/formats/formatToPhone.ts +156 -6
  107. package/src/generators/__test__/generateColorByString.spec.ts +37 -0
  108. package/src/generators/__test__/generateId.spec.ts +44 -0
  109. package/src/generators/__test__/generateSlug.spec.ts +47 -0
  110. package/src/generators/generateColorByString.ts +18 -4
  111. package/src/generators/generateId.ts +36 -5
  112. package/src/generators/generateSlug.ts +17 -2
  113. package/src/index.ts +10 -13
  114. package/src/services/__test__/calculateCardInstallment.spec.ts +87 -0
  115. package/src/services/__test__/maskSensitiveData.spec.ts +102 -0
  116. package/src/services/__test__/removeCurrencySymbols.spec.ts +41 -0
  117. package/src/services/__test__/removeNonNumeric.spec.ts +33 -0
  118. package/src/services/__test__/truncateLargeFields.spec.ts +90 -0
  119. package/src/services/calculateCardInstallment.ts +57 -12
  120. package/src/services/maskSensitiveData.ts +29 -4
  121. package/src/services/removeCurrencySymbols.ts +25 -0
  122. package/src/services/removeNonNumeric.ts +18 -0
  123. package/src/services/truncateLargeFields.ts +40 -6
  124. package/src/validations/__test__/validateCep.spec.ts +40 -0
  125. package/src/validations/__test__/validateCnpj.spec.ts +42 -0
  126. package/src/validations/__test__/validateCpf.spec.ts +38 -0
  127. package/src/validations/__test__/validateDate.spec.ts +81 -0
  128. package/src/validations/__test__/validatePassword.spec.ts +43 -0
  129. package/src/validations/__test__/validatePhone.spec.ts +39 -0
  130. package/src/validations/__test__/validateRg.spec.ts +48 -0
  131. package/src/validations/validateCep.ts +40 -0
  132. package/src/validations/validateCnpj.ts +64 -0
  133. package/src/validations/validateCpf.ts +61 -0
  134. package/src/validations/validateDate.ts +39 -17
  135. package/src/validations/validatePassword.ts +41 -0
  136. package/src/validations/validatePhone.ts +31 -4
  137. package/src/validations/validateRg.ts +37 -0
  138. package/tsconfig.json +2 -2
  139. package/vitest.config.ts +5 -0
  140. package/dist/formats/formatBrazilianDateHour.d.ts +0 -3
  141. package/dist/formats/formatBrazilianDateHour.d.ts.map +0 -1
  142. package/dist/formats/formatBrazilianDateHour.js +0 -12
  143. package/dist/formats/formatBrazilianDateToDate.d.ts +0 -3
  144. package/dist/formats/formatBrazilianDateToDate.d.ts.map +0 -1
  145. package/dist/formats/formatBrazilianDateToDate.js +0 -9
  146. package/dist/formats/formatDateHour.d.ts +0 -3
  147. package/dist/formats/formatDateHour.d.ts.map +0 -1
  148. package/dist/formats/formatDateHour.js +0 -11
  149. package/dist/formats/formatToBRL.d.ts +0 -3
  150. package/dist/formats/formatToBRL.d.ts.map +0 -1
  151. package/dist/formats/formatToBRL.js +0 -8
  152. package/dist/formats/formatToCNPJ.d.ts +0 -3
  153. package/dist/formats/formatToCNPJ.d.ts.map +0 -1
  154. package/dist/formats/formatToCNPJ.js +0 -9
  155. package/dist/formats/formatToCPF.d.ts +0 -3
  156. package/dist/formats/formatToCPF.d.ts.map +0 -1
  157. package/dist/formats/formatToCPF.js +0 -9
  158. package/dist/parsers/parseToCharacters.d.ts +0 -17
  159. package/dist/parsers/parseToCharacters.d.ts.map +0 -1
  160. package/dist/parsers/parseToCharacters.js +0 -13
  161. package/dist/services/range.d.ts +0 -4
  162. package/dist/services/range.d.ts.map +0 -1
  163. package/dist/services/range.js +0 -9
  164. package/dist/validations/regex.d.ts +0 -15
  165. package/dist/validations/regex.d.ts.map +0 -1
  166. package/dist/validations/regex.js +0 -25
  167. package/dist/validations/validateCPF.d.ts +0 -3
  168. package/dist/validations/validateCPF.d.ts.map +0 -1
  169. package/dist/validations/validateCPF.js +0 -36
  170. package/src/formats/formatBrazilianDateHour.ts +0 -17
  171. package/src/formats/formatBrazilianDateToDate.ts +0 -13
  172. package/src/formats/formatDateHour.ts +0 -15
  173. package/src/formats/formatToBRL.ts +0 -10
  174. package/src/formats/formatToCNPJ.ts +0 -10
  175. package/src/formats/formatToCPF.ts +0 -10
  176. package/src/parsers/parseToCharacters.ts +0 -34
  177. package/src/services/range.ts +0 -15
  178. package/src/validations/regex.ts +0 -41
  179. package/src/validations/validateCPF.ts +0 -38
@@ -1,28 +1,50 @@
1
- type Format = "DD/MM/YYYY" | "MM-DD-YYYY" | "YYYY-MM-DD";
1
+ import type { ValidateDateFunction } from "@arkyn/types";
2
2
 
3
- type Config = {
4
- minYear?: number;
5
- maxYear?: number;
6
- };
3
+ /**
4
+ * Validates a date string based on the provided format and configuration.
5
+ *
6
+ * @param rawDate - The date string to validate.
7
+ * @param config - Optional configuration object to customize validation.
8
+ * @param config.inputFormat - The expected format of the input date.
9
+ * Supported formats are "DD/MM/YYYY", "MM-DD-YYYY", and "YYYY-MM-DD".
10
+ * Defaults to "DD/MM/YYYY".
11
+ * @param config.minYear - The minimum allowed year for the date. Defaults to 1900.
12
+ * @param config.maxYear - The maximum allowed year for the date. Defaults to 3000.
13
+ *
14
+ * @returns `true` if the date is valid according to the specified format and configuration, otherwise `false`.
15
+ *
16
+ * @throws {Error} If an invalid date format is provided in the configuration.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * validateDate("31/12/2023"); // true
21
+ * validateDate("12-31-2023", { inputFormat: "MM-DD-YYYY" }); // true
22
+ * validateDate("2023-12-31", { inputFormat: "YYYY-MM-DD", minYear: 2000, maxYear: 2100 }); // true
23
+ * validateDate("29/02/2024", { inputFormat: "DD/MM/YYYY" }); // true (leap year)
24
+ * validateDate("29/02/2023", { inputFormat: "DD/MM/YYYY" }); // false (not a leap year)
25
+ * validateDate("31/04/2023", { inputFormat: "DD/MM/YYYY" }); // false (April has 30 days)
26
+ * ```
27
+ */
7
28
 
8
- function validateDate(date: string, format: Format, config?: Config): boolean {
29
+ const validateDate: ValidateDateFunction = (rawDate, config) => {
9
30
  let day: string, month: string, year: string;
10
31
 
11
- const minYear = config?.minYear || 0;
32
+ const inputFormat = config?.inputFormat || "DD/MM/YYYY";
33
+ const minYear = config?.minYear || 1900;
12
34
  const maxYear = config?.maxYear || 3000;
13
35
 
14
- if (format === "DD/MM/YYYY") {
36
+ if (inputFormat === "DD/MM/YYYY") {
15
37
  const dateRegex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
16
- if (!dateRegex.test(date)) return false;
17
- [, day, month, year] = date.match(dateRegex) || [];
18
- } else if (format === "MM-DD-YYYY") {
38
+ if (!dateRegex.test(rawDate)) return false;
39
+ [, day, month, year] = rawDate.match(dateRegex) || [];
40
+ } else if (inputFormat === "MM-DD-YYYY") {
19
41
  const dateRegex = /^(\d{2})-(\d{2})-(\d{4})$/;
20
- if (!dateRegex.test(date)) return false;
21
- [, month, day, year] = date.match(dateRegex) || [];
22
- } else if (format === "YYYY-MM-DD") {
42
+ if (!dateRegex.test(rawDate)) return false;
43
+ [, month, day, year] = rawDate.match(dateRegex) || [];
44
+ } else if (inputFormat === "YYYY-MM-DD") {
23
45
  const dateRegex = /^(\d{4})-(\d{2})-(\d{2})$/;
24
- if (!dateRegex.test(date)) return false;
25
- [, year, month, day] = date.match(dateRegex) || [];
46
+ if (!dateRegex.test(rawDate)) return false;
47
+ [, year, month, day] = rawDate.match(dateRegex) || [];
26
48
  } else {
27
49
  throw new Error("Invalid date format");
28
50
  }
@@ -50,6 +72,6 @@ function validateDate(date: string, format: Format, config?: Config): boolean {
50
72
  new Date(yearNum, monthNum - 1, dayNum).getDate() === dayNum;
51
73
 
52
74
  return isValidDate;
53
- }
75
+ };
54
76
 
55
77
  export { validateDate };
@@ -0,0 +1,41 @@
1
+ import type { ValidatePasswordFunction } from "@arkyn/types";
2
+
3
+ /**
4
+ * Validates a password based on the following rules:
5
+ * - At least 8 characters
6
+ * - At least 1 uppercase letter
7
+ * - At least 1 letter (any case)
8
+ * - At least 1 number
9
+ * - At least 1 special character
10
+ *
11
+ * @param rawPassword - The raw password string.
12
+ * @returns `true` if password is valid, otherwise `false`.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * validatePassword("Senha@123"); // true
17
+ * validatePassword("senha123"); // false (no uppercase, no special char)
18
+ * ```
19
+ */
20
+
21
+ const validatePassword: ValidatePasswordFunction = (rawPassword) => {
22
+ if (!rawPassword) return false;
23
+
24
+ const hasMinLength = rawPassword.length >= 8;
25
+ const hasUppercase = /[A-Z]/.test(rawPassword);
26
+ const hasLetter = /[a-z]/.test(rawPassword);
27
+ const hasNumber = /\d/.test(rawPassword);
28
+ const hasSpecialChar = /[!@#$%^&*(),.?":{}|<>_\-+=~`[\]\\\/]/.test(
29
+ rawPassword
30
+ );
31
+
32
+ return [
33
+ hasMinLength,
34
+ hasUppercase,
35
+ hasLetter,
36
+ hasNumber,
37
+ hasSpecialChar,
38
+ ].every((condition) => condition);
39
+ };
40
+
41
+ export { validatePassword };
@@ -1,6 +1,33 @@
1
1
  import { countries } from "@arkyn/templates";
2
+ import type { ValidatePhoneFunction } from "@arkyn/types";
2
3
 
3
- function validatePhone(phone: string): boolean {
4
+ /**
5
+ * Validates a phone number against a list of country-specific formats.
6
+ *
7
+ * The function iterates through a predefined list of countries and checks if the
8
+ * provided phone number matches the format for any of the countries. It uses
9
+ * regular expressions to validate the phone number based on the country's code,
10
+ * prefix, and mask.
11
+ *
12
+ * Special handling is applied for Brazilian phone numbers (ISO code "BR"), which
13
+ * allows for an optional ninth digit.
14
+ *
15
+ * @param rawPhone - The phone number to validate as a string.
16
+ * @returns `true` if the phone number matches any country's format, otherwise `false`.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { validatePhone } from "./validatePhone";
21
+ *
22
+ * validatePhone("+55 32912345678"); // true for a valid Brazilian phone number
23
+ * validatePhone("+55 3212345678"); // true for a valid Brazilian phone number
24
+ * validatePhone("+1-684 1234567"); // true for a valid American Samoa phone number
25
+ * validatePhone("+5532912345678"); // false for an invalid Brazilian phone number
26
+ * validatePhone("+55 1234567890"); // false for an invalid Brazilian phone number
27
+ * ```
28
+ */
29
+
30
+ const validatePhone: ValidatePhoneFunction = (rawPhone) => {
4
31
  for (const country of countries) {
5
32
  const countryCode = country.code;
6
33
  const prefix = country.prefix ? `-${country.prefix}` : "";
@@ -8,15 +35,15 @@ function validatePhone(phone: string): boolean {
8
35
 
9
36
  if (country.iso === "BR") {
10
37
  const brazilRegex = new RegExp(`^\\${countryCode} \\d{2}9?\\d{8}$`);
11
- if (brazilRegex.test(phone)) return true;
38
+ if (brazilRegex.test(rawPhone)) return true;
12
39
  continue;
13
40
  }
14
41
 
15
42
  const regex = new RegExp(`^\\${countryCode}${prefix} \\d{${digitCount}}$`);
16
- if (regex.test(phone)) return true;
43
+ if (regex.test(rawPhone)) return true;
17
44
  }
18
45
 
19
46
  return false;
20
- }
47
+ };
21
48
 
22
49
  export { validatePhone };
@@ -0,0 +1,37 @@
1
+ import type { ValidateRgFunction } from "@arkyn/types";
2
+
3
+ /**
4
+ * Validates a Brazilian RG (Registro Geral) in a generic way.
5
+ *
6
+ * This function does a basic structure validation:
7
+ * - Removes non-alphanumeric characters.
8
+ * - Ensures length is reasonable (7–9 digits).
9
+ * - Optionally allows for a final letter (verifier).
10
+ *
11
+ * @param rawRg - RG string, possibly formatted.
12
+ * @returns `true` if format seems valid, otherwise `false`.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * validateRg("12.345.678-9"); // true
17
+ * validateRg("MG-12.345.678"); // false (not supported)
18
+ * validateRg("12345678X"); // true
19
+ * ```
20
+ */
21
+
22
+ const validateRg: ValidateRgFunction = (rawRg) => {
23
+ if (!rawRg) return false;
24
+
25
+ const validFormat = /^[0-9a-zA-Z.-]+$/.test(rawRg);
26
+ if (!validFormat) return false;
27
+
28
+ const rg = rawRg.replace(/[^a-zA-Z0-9]/g, "");
29
+
30
+ if (rg.length < 7 || rg.length > 9) return false;
31
+
32
+ const isValidFormat = /^[0-9]{7,8}[0-9Xx]?$/.test(rg);
33
+
34
+ return isValidFormat;
35
+ };
36
+
37
+ export { validateRg };
package/tsconfig.json CHANGED
@@ -15,6 +15,6 @@
15
15
  "types": ["bun-types"],
16
16
  "verbatimModuleSyntax": true
17
17
  },
18
- "exclude": ["dist", "node_modules"],
19
- "include": ["src/**/*.ts"]
18
+ "exclude": ["dist", "node_modules", "**/__test__"],
19
+ "include": ["src/**/*.ts", "src/**/*.ts"]
20
20
  }
@@ -0,0 +1,5 @@
1
+ import { defineConfig } from "vite";
2
+
3
+ export default defineConfig({
4
+ resolve: { mainFields: ["module"] },
5
+ });
@@ -1,3 +0,0 @@
1
- declare function formatBrazilianDateHour(date: string, hour: string): Date;
2
- export { formatBrazilianDateHour };
3
- //# sourceMappingURL=formatBrazilianDateHour.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatBrazilianDateHour.d.ts","sourceRoot":"","sources":["../../src/formats/formatBrazilianDateHour.ts"],"names":[],"mappings":"AAEA,iBAAS,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAY1D;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -1,12 +0,0 @@
1
- import { regex } from "../validations/regex";
2
- function formatBrazilianDateHour(date, hour) {
3
- if (regex.HOUR.test(hour) === false)
4
- throw new Error("Invalid hour format");
5
- const [day, month, year] = date.split("/").map(Number);
6
- const dateHour = new Date(`${year}-${month}-${day}`);
7
- const [hours, minutes] = hour.split(":").map(Number);
8
- dateHour.setUTCHours(hours);
9
- dateHour.setUTCMinutes(minutes);
10
- return dateHour;
11
- }
12
- export { formatBrazilianDateHour };
@@ -1,3 +0,0 @@
1
- declare function formatBrazilianDateToDate(brazilianData: string): Date;
2
- export { formatBrazilianDateToDate };
3
- //# sourceMappingURL=formatBrazilianDateToDate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatBrazilianDateToDate.d.ts","sourceRoot":"","sources":["../../src/formats/formatBrazilianDateToDate.ts"],"names":[],"mappings":"AAEA,iBAAS,yBAAyB,CAAC,aAAa,EAAE,MAAM,QAQvD;AAED,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
@@ -1,9 +0,0 @@
1
- import { regex } from "../validations/regex";
2
- function formatBrazilianDateToDate(brazilianData) {
3
- if (regex.DATE.test(brazilianData) === false)
4
- throw new Error("Invalid date format");
5
- const [day, month, year] = brazilianData.split("/").map(Number);
6
- const formattedDate = `${year}-${month}-${day}`;
7
- return new Date(formattedDate);
8
- }
9
- export { formatBrazilianDateToDate };
@@ -1,3 +0,0 @@
1
- declare function formatDateHour(date: string, hour: string): Date;
2
- export { formatDateHour };
3
- //# sourceMappingURL=formatDateHour.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatDateHour.d.ts","sourceRoot":"","sources":["../../src/formats/formatDateHour.ts"],"names":[],"mappings":"AAEA,iBAAS,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAUjD;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,11 +0,0 @@
1
- import { regex } from "../validations/regex";
2
- function formatDateHour(date, hour) {
3
- if (regex.HOUR.test(hour) === false)
4
- throw new Error("Invalid hour format");
5
- const dateHour = new Date(date);
6
- const [hours, minutes] = hour.split(":").map(Number);
7
- dateHour.setUTCHours(hours);
8
- dateHour.setUTCMinutes(minutes);
9
- return dateHour;
10
- }
11
- export { formatDateHour };
@@ -1,3 +0,0 @@
1
- declare function formatToBRL(value: number, showPrefix?: boolean): string;
2
- export { formatToBRL };
3
- //# sourceMappingURL=formatToBRL.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatToBRL.d.ts","sourceRoot":"","sources":["../../src/formats/formatToBRL.ts"],"names":[],"mappings":"AAAA,iBAAS,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,UAAO,UAOpD;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -1,8 +0,0 @@
1
- function formatToBRL(value, showPrefix = true) {
2
- const format = new Intl.NumberFormat("pt-BR", {
3
- style: "currency",
4
- currency: "BRL",
5
- }).format(value);
6
- return showPrefix ? format : format.replace("R$", "").trim();
7
- }
8
- export { formatToBRL };
@@ -1,3 +0,0 @@
1
- declare function formatToCNPJ(value: string): string;
2
- export { formatToCNPJ };
3
- //# sourceMappingURL=formatToCNPJ.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatToCNPJ.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCNPJ.ts"],"names":[],"mappings":"AAAA,iBAAS,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO3C;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,9 +0,0 @@
1
- function formatToCNPJ(value) {
2
- const cleaned = value.replace(/\D/g, "");
3
- const match = cleaned.match(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/);
4
- if (match) {
5
- return `${match[1]}.${match[2]}.${match[3]}/${match[4]}-${match[5]}`;
6
- }
7
- return value;
8
- }
9
- export { formatToCNPJ };
@@ -1,3 +0,0 @@
1
- declare function formatToCPF(value: string): string;
2
- export { formatToCPF };
3
- //# sourceMappingURL=formatToCPF.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatToCPF.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCPF.ts"],"names":[],"mappings":"AAAA,iBAAS,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO1C;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -1,9 +0,0 @@
1
- function formatToCPF(value) {
2
- const cleaned = value.replace(/\D/g, "");
3
- const match = cleaned.match(/^(\d{3})(\d{3})(\d{3})(\d{2})$/);
4
- if (match) {
5
- return `${match[1]}.${match[2]}.${match[3]}-${match[4]}`;
6
- }
7
- return value;
8
- }
9
- export { formatToCPF };
@@ -1,17 +0,0 @@
1
- type DigitCharacterNode = {
2
- kind: "digit";
3
- digit: number;
4
- character: string;
5
- };
6
- type OtherCharacterNode = {
7
- kind: "other";
8
- character: string;
9
- };
10
- type RootCharacterNode = {
11
- kind: "root";
12
- digits: number;
13
- children: (DigitCharacterNode | OtherCharacterNode)[];
14
- };
15
- declare const parseToCharacters: (value: string) => RootCharacterNode;
16
- export { parseToCharacters };
17
- //# sourceMappingURL=parseToCharacters.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseToCharacters.d.ts","sourceRoot":"","sources":["../../src/parsers/parseToCharacters.ts"],"names":[],"mappings":"AAEA,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,CAAC,kBAAkB,GAAG,kBAAkB,CAAC,EAAE,CAAC;CACvD,CAAC;AAEF,QAAA,MAAM,iBAAiB,GAAI,OAAO,MAAM,KAAG,iBAY1C,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1,13 +0,0 @@
1
- const DIGIT = /^\d$/;
2
- const parseToCharacters = (value) => {
3
- let digits = 0;
4
- const children = value
5
- .split("")
6
- .map((character) => {
7
- if (DIGIT.test(character))
8
- return { character, kind: "digit", digit: ++digits };
9
- return { character, kind: "other" };
10
- });
11
- return { digits, children, kind: "root" };
12
- };
13
- export { parseToCharacters };
@@ -1,4 +0,0 @@
1
- declare const normalizeRange: (range: number | [number, number], limit: number) => [number, number];
2
- declare const within: (range: [number, number], value: number) => boolean;
3
- export { normalizeRange, within };
4
- //# sourceMappingURL=range.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/services/range.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,cAAc,GAClB,OAAO,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,OAAO,MAAM,KACZ,CAAC,MAAM,EAAE,MAAM,CAMjB,CAAC;AAEF,QAAA,MAAM,MAAM,GAAI,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,MAAM,KAAG,OACjB,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC"}
@@ -1,9 +0,0 @@
1
- const normalizeRange = (range, limit) => {
2
- if (Array.isArray(range))
3
- return range;
4
- if (range >= 0)
5
- return [0, range];
6
- return [limit + 1 - Math.abs(range), limit];
7
- };
8
- const within = (range, value) => value >= range[0] && value <= range[1];
9
- export { normalizeRange, within };
@@ -1,15 +0,0 @@
1
- declare const regex: {
2
- URL: RegExp;
3
- HOUR: RegExp;
4
- RG: RegExp;
5
- PHONE: RegExp;
6
- PASSWORD: RegExp;
7
- DATEHOUR: RegExp;
8
- CPF: RegExp;
9
- CNPJ: RegExp;
10
- CEP: RegExp;
11
- CPFCNPJ: RegExp;
12
- DATE: RegExp;
13
- };
14
- export { regex };
15
- //# sourceMappingURL=regex.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/validations/regex.ts"],"names":[],"mappings":"AA0BA,QAAA,MAAM,KAAK;;;;;;;;;;;;CAYV,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -1,25 +0,0 @@
1
- const CEP = /^(\d{8}|\d{2}\.?\d{3}\-\d{3})$/;
2
- const CNPJ = /(^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$)/;
3
- const CPF = /(^\d{3}\.\d{3}\.\d{3}\-\d{2}$)/;
4
- const DATE = /^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/\d{4}$/;
5
- const DATEHOUR = /^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/\d{4}\s(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9])$/;
6
- const HOUR = /^(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9])$/;
7
- const PASSWORD = /(?=^.{8,}$)((?=.*\w)(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[|!"$%&\/\(\)\?\^\'\\\+\-\*]))^.*/;
8
- const PHONE = /([0-9]{2})?(\s|-)?(9?[0-9]{4})-?([0-9]{4}$)/;
9
- const RG = /(^\d{1,2}).?(\d{3}).?(\d{3})-?(\d{1}|X|x$)/;
10
- const URL = /^(((https?|ftp):\/\/)?([\w\-\.])+(\.)([\w]){2,4}([\w\/+=%&_\.~?\-]*))*$/;
11
- const CPFCNPJ = /^(?:(\d{3}\.\d{3}\.\d{3}-\d{2})|(\d{11})|(\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2})|(\d{14}))$/;
12
- const regex = {
13
- URL,
14
- HOUR,
15
- RG,
16
- PHONE,
17
- PASSWORD,
18
- DATEHOUR,
19
- CPF,
20
- CNPJ,
21
- CEP,
22
- CPFCNPJ,
23
- DATE,
24
- };
25
- export { regex };
@@ -1,3 +0,0 @@
1
- declare function validateCPF(rawCpf: string): boolean;
2
- export { validateCPF };
3
- //# sourceMappingURL=validateCPF.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validateCPF.d.ts","sourceRoot":"","sources":["../../src/validations/validateCPF.ts"],"names":[],"mappings":"AA2BA,iBAAS,WAAW,CAAC,MAAM,EAAE,MAAM,WAQlC;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -1,36 +0,0 @@
1
- function removeNonDigits(cpf) {
2
- return cpf.replace(/\D/g, "");
3
- }
4
- function isInvalidLength(cpf) {
5
- const CPF_LENGTH = 11;
6
- return cpf.length !== CPF_LENGTH;
7
- }
8
- function hasAllDigitsEqual(cpf) {
9
- const [firstCpfDigit] = cpf;
10
- return [...cpf].every((digit) => digit === firstCpfDigit);
11
- }
12
- function calculateDigit(cpf, factor) {
13
- let total = 0;
14
- for (const digit of cpf) {
15
- if (factor > 1)
16
- total += parseInt(digit) * factor--;
17
- }
18
- const rest = total % 11;
19
- return rest < 2 ? 0 : 11 - rest;
20
- }
21
- function extractDigit(cpf) {
22
- return cpf.slice(9);
23
- }
24
- function validateCPF(rawCpf) {
25
- if (!rawCpf)
26
- return false;
27
- const cpf = removeNonDigits(rawCpf);
28
- if (isInvalidLength(cpf))
29
- return false;
30
- if (hasAllDigitsEqual(cpf))
31
- return false;
32
- const digit1 = calculateDigit(cpf, 10);
33
- const digit2 = calculateDigit(cpf, 11);
34
- return extractDigit(cpf) === `${digit1}${digit2}`;
35
- }
36
- export { validateCPF };
@@ -1,17 +0,0 @@
1
- import { regex } from "../validations/regex";
2
-
3
- function formatBrazilianDateHour(date: string, hour: string) {
4
- if (regex.HOUR.test(hour) === false) throw new Error("Invalid hour format");
5
-
6
- const [day, month, year] = date.split("/").map(Number);
7
-
8
- const dateHour = new Date(`${year}-${month}-${day}`);
9
- const [hours, minutes] = hour.split(":").map(Number);
10
-
11
- dateHour.setUTCHours(hours);
12
- dateHour.setUTCMinutes(minutes);
13
-
14
- return dateHour;
15
- }
16
-
17
- export { formatBrazilianDateHour };
@@ -1,13 +0,0 @@
1
- import { regex } from "../validations/regex";
2
-
3
- function formatBrazilianDateToDate(brazilianData: string) {
4
- if (regex.DATE.test(brazilianData) === false)
5
- throw new Error("Invalid date format");
6
-
7
- const [day, month, year] = brazilianData.split("/").map(Number);
8
- const formattedDate = `${year}-${month}-${day}`;
9
-
10
- return new Date(formattedDate);
11
- }
12
-
13
- export { formatBrazilianDateToDate };
@@ -1,15 +0,0 @@
1
- import { regex } from "../validations/regex";
2
-
3
- function formatDateHour(date: string, hour: string = "00:00") {
4
- if (regex.HOUR.test(hour) === false) throw new Error("Invalid hour format");
5
-
6
- const dateHour = new Date(date);
7
- const [hours, minutes] = hour.split(":").map(Number);
8
-
9
- dateHour.setUTCHours(hours);
10
- dateHour.setUTCMinutes(minutes);
11
-
12
- return dateHour;
13
- }
14
-
15
- export { formatDateHour };
@@ -1,10 +0,0 @@
1
- function formatToBRL(value: number, showPrefix = true) {
2
- const format = new Intl.NumberFormat("pt-BR", {
3
- style: "currency",
4
- currency: "BRL",
5
- }).format(value);
6
-
7
- return showPrefix ? format : format.replace("R$", "").trim();
8
- }
9
-
10
- export { formatToBRL };
@@ -1,10 +0,0 @@
1
- function formatToCNPJ(value: string): string {
2
- const cleaned = value.replace(/\D/g, "");
3
- const match = cleaned.match(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/);
4
- if (match) {
5
- return `${match[1]}.${match[2]}.${match[3]}/${match[4]}-${match[5]}`;
6
- }
7
- return value;
8
- }
9
-
10
- export { formatToCNPJ };
@@ -1,10 +0,0 @@
1
- function formatToCPF(value: string): string {
2
- const cleaned = value.replace(/\D/g, "");
3
- const match = cleaned.match(/^(\d{3})(\d{3})(\d{3})(\d{2})$/);
4
- if (match) {
5
- return `${match[1]}.${match[2]}.${match[3]}-${match[4]}`;
6
- }
7
- return value;
8
- }
9
-
10
- export { formatToCPF };
@@ -1,34 +0,0 @@
1
- const DIGIT = /^\d$/;
2
-
3
- type DigitCharacterNode = {
4
- kind: "digit";
5
- digit: number;
6
- character: string;
7
- };
8
-
9
- type OtherCharacterNode = {
10
- kind: "other";
11
- character: string;
12
- };
13
-
14
- type RootCharacterNode = {
15
- kind: "root";
16
- digits: number;
17
- children: (DigitCharacterNode | OtherCharacterNode)[];
18
- };
19
-
20
- const parseToCharacters = (value: string): RootCharacterNode => {
21
- let digits = 0;
22
-
23
- const children = value
24
- .split("")
25
- .map((character: string): DigitCharacterNode | OtherCharacterNode => {
26
- if (DIGIT.test(character))
27
- return { character, kind: "digit", digit: ++digits };
28
- return { character, kind: "other" };
29
- });
30
-
31
- return { digits, children, kind: "root" };
32
- };
33
-
34
- export { parseToCharacters };
@@ -1,15 +0,0 @@
1
- const normalizeRange = (
2
- range: number | [number, number],
3
- limit: number
4
- ): [number, number] => {
5
- if (Array.isArray(range)) return range;
6
-
7
- if (range >= 0) return [0, range];
8
-
9
- return [limit + 1 - Math.abs(range), limit];
10
- };
11
-
12
- const within = (range: [number, number], value: number): boolean =>
13
- value >= range[0] && value <= range[1];
14
-
15
- export { normalizeRange, within };