@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.
- package/LICENSE.txt +24 -0
- package/README.md +113 -0
- package/dist/formats/formatDate.d.ts +43 -0
- package/dist/formats/formatDate.d.ts.map +1 -0
- package/dist/formats/formatDate.js +77 -0
- package/dist/formats/formatJsonObject.d.ts +31 -1
- package/dist/formats/formatJsonObject.d.ts.map +1 -1
- package/dist/formats/formatJsonObject.js +67 -26
- package/dist/formats/formatJsonString.d.ts +37 -1
- package/dist/formats/formatJsonString.d.ts.map +1 -1
- package/dist/formats/formatJsonString.js +38 -4
- package/dist/formats/formatToCep.d.ts +27 -1
- package/dist/formats/formatToCep.d.ts.map +1 -1
- package/dist/formats/formatToCep.js +31 -6
- package/dist/formats/formatToCnpj.d.ts +30 -0
- package/dist/formats/formatToCnpj.d.ts.map +1 -0
- package/dist/formats/formatToCnpj.js +35 -0
- package/dist/formats/formatToCpf.d.ts +30 -0
- package/dist/formats/formatToCpf.d.ts.map +1 -0
- package/dist/formats/formatToCpf.js +35 -0
- package/dist/formats/formatToCpfCnpj.d.ts +22 -1
- package/dist/formats/formatToCpfCnpj.d.ts.map +1 -1
- package/dist/formats/formatToCpfCnpj.js +27 -7
- package/dist/formats/formatToCurrency.d.ts +29 -0
- package/dist/formats/formatToCurrency.d.ts.map +1 -0
- package/dist/formats/formatToCurrency.js +41 -0
- package/dist/formats/formatToEllipsis.d.ts +14 -1
- package/dist/formats/formatToEllipsis.d.ts.map +1 -1
- package/dist/formats/formatToEllipsis.js +20 -3
- package/dist/formats/formatToHiddenDigits.d.ts +30 -2
- package/dist/formats/formatToHiddenDigits.d.ts.map +1 -1
- package/dist/formats/formatToHiddenDigits.js +49 -3
- package/dist/formats/formatToPhone.d.ts +32 -1
- package/dist/formats/formatToPhone.d.ts.map +1 -1
- package/dist/formats/formatToPhone.js +128 -6
- package/dist/generators/generateColorByString.d.ts +13 -1
- package/dist/generators/generateColorByString.d.ts.map +1 -1
- package/dist/generators/generateColorByString.js +15 -4
- package/dist/generators/generateId.d.ts +26 -4
- package/dist/generators/generateId.d.ts.map +1 -1
- package/dist/generators/generateId.js +11 -5
- package/dist/generators/generateSlug.d.ts +15 -1
- package/dist/generators/generateSlug.d.ts.map +1 -1
- package/dist/generators/generateSlug.js +16 -2
- package/dist/index.d.ts +9 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -12
- package/dist/services/calculateCardInstallment.d.ts +31 -5
- package/dist/services/calculateCardInstallment.d.ts.map +1 -1
- package/dist/services/calculateCardInstallment.js +52 -11
- package/dist/services/maskSensitiveData.d.ts +24 -1
- package/dist/services/maskSensitiveData.d.ts.map +1 -1
- package/dist/services/maskSensitiveData.js +24 -2
- package/dist/services/removeCurrencySymbols.d.ts +20 -0
- package/dist/services/removeCurrencySymbols.d.ts.map +1 -0
- package/dist/services/removeCurrencySymbols.js +23 -0
- package/dist/services/removeNonNumeric.d.ts +15 -0
- package/dist/services/removeNonNumeric.d.ts.map +1 -0
- package/dist/services/removeNonNumeric.js +16 -0
- package/dist/services/truncateLargeFields.d.ts +30 -1
- package/dist/services/truncateLargeFields.d.ts.map +1 -1
- package/dist/services/truncateLargeFields.js +34 -6
- package/dist/validations/validateCep.d.ts +24 -0
- package/dist/validations/validateCep.d.ts.map +1 -0
- package/dist/validations/validateCep.js +33 -0
- package/dist/validations/validateCnpj.d.ts +22 -0
- package/dist/validations/validateCnpj.d.ts.map +1 -0
- package/dist/validations/validateCnpj.js +52 -0
- package/dist/validations/validateCpf.d.ts +24 -0
- package/dist/validations/validateCpf.d.ts.map +1 -0
- package/dist/validations/validateCpf.js +54 -0
- package/dist/validations/validateDate.d.ts +27 -6
- package/dist/validations/validateDate.d.ts.map +1 -1
- package/dist/validations/validateDate.js +38 -12
- package/dist/validations/validatePassword.d.ts +21 -0
- package/dist/validations/validatePassword.d.ts.map +1 -0
- package/dist/validations/validatePassword.js +34 -0
- package/dist/validations/validatePhone.d.ts +27 -1
- package/dist/validations/validatePhone.d.ts.map +1 -1
- package/dist/validations/validatePhone.js +29 -4
- package/dist/validations/validateRg.d.ts +22 -0
- package/dist/validations/validateRg.d.ts.map +1 -0
- package/dist/validations/validateRg.js +31 -0
- package/package.json +7 -2
- package/src/formats/__test__/formatDate.spec.ts +88 -0
- package/src/formats/__test__/formatJsonObject.spec.ts +87 -0
- package/src/formats/__test__/formatJsonString.spec.ts +83 -0
- package/src/formats/__test__/formatToCep.spec.ts +37 -0
- package/src/formats/__test__/formatToCnpj.spec.ts +35 -0
- package/src/formats/__test__/formatToCpf.spec.ts +37 -0
- package/src/formats/__test__/formatToCpfCnpj.spec.ts +43 -0
- package/src/formats/__test__/formatToCurrency.spec.ts +50 -0
- package/src/formats/__test__/formatToEllipsis.spec.ts +44 -0
- package/src/formats/__test__/formatToHiddenDigits.spec.ts +58 -0
- package/src/formats/__test__/formatToPhone.spec.ts +58 -0
- package/src/formats/formatDate.ts +97 -0
- package/src/formats/formatJsonObject.ts +68 -26
- package/src/formats/formatJsonString.ts +40 -4
- package/src/formats/formatToCep.ts +35 -7
- package/src/formats/formatToCnpj.ts +39 -0
- package/src/formats/formatToCpf.ts +39 -0
- package/src/formats/formatToCpfCnpj.ts +31 -7
- package/src/formats/formatToCurrency.ts +53 -0
- package/src/formats/formatToEllipsis.ts +23 -3
- package/src/formats/formatToHiddenDigits.ts +75 -7
- package/src/formats/formatToPhone.ts +156 -6
- package/src/generators/__test__/generateColorByString.spec.ts +37 -0
- package/src/generators/__test__/generateId.spec.ts +44 -0
- package/src/generators/__test__/generateSlug.spec.ts +47 -0
- package/src/generators/generateColorByString.ts +18 -4
- package/src/generators/generateId.ts +36 -5
- package/src/generators/generateSlug.ts +17 -2
- package/src/index.ts +10 -13
- package/src/services/__test__/calculateCardInstallment.spec.ts +87 -0
- package/src/services/__test__/maskSensitiveData.spec.ts +102 -0
- package/src/services/__test__/removeCurrencySymbols.spec.ts +41 -0
- package/src/services/__test__/removeNonNumeric.spec.ts +33 -0
- package/src/services/__test__/truncateLargeFields.spec.ts +90 -0
- package/src/services/calculateCardInstallment.ts +57 -12
- package/src/services/maskSensitiveData.ts +29 -4
- package/src/services/removeCurrencySymbols.ts +25 -0
- package/src/services/removeNonNumeric.ts +18 -0
- package/src/services/truncateLargeFields.ts +40 -6
- package/src/validations/__test__/validateCep.spec.ts +40 -0
- package/src/validations/__test__/validateCnpj.spec.ts +42 -0
- package/src/validations/__test__/validateCpf.spec.ts +38 -0
- package/src/validations/__test__/validateDate.spec.ts +81 -0
- package/src/validations/__test__/validatePassword.spec.ts +43 -0
- package/src/validations/__test__/validatePhone.spec.ts +39 -0
- package/src/validations/__test__/validateRg.spec.ts +48 -0
- package/src/validations/validateCep.ts +40 -0
- package/src/validations/validateCnpj.ts +64 -0
- package/src/validations/validateCpf.ts +61 -0
- package/src/validations/validateDate.ts +39 -17
- package/src/validations/validatePassword.ts +41 -0
- package/src/validations/validatePhone.ts +31 -4
- package/src/validations/validateRg.ts +37 -0
- package/tsconfig.json +2 -2
- package/vitest.config.ts +5 -0
- package/dist/formats/formatBrazilianDateHour.d.ts +0 -3
- package/dist/formats/formatBrazilianDateHour.d.ts.map +0 -1
- package/dist/formats/formatBrazilianDateHour.js +0 -12
- package/dist/formats/formatBrazilianDateToDate.d.ts +0 -3
- package/dist/formats/formatBrazilianDateToDate.d.ts.map +0 -1
- package/dist/formats/formatBrazilianDateToDate.js +0 -9
- package/dist/formats/formatDateHour.d.ts +0 -3
- package/dist/formats/formatDateHour.d.ts.map +0 -1
- package/dist/formats/formatDateHour.js +0 -11
- package/dist/formats/formatToBRL.d.ts +0 -3
- package/dist/formats/formatToBRL.d.ts.map +0 -1
- package/dist/formats/formatToBRL.js +0 -8
- package/dist/formats/formatToCNPJ.d.ts +0 -3
- package/dist/formats/formatToCNPJ.d.ts.map +0 -1
- package/dist/formats/formatToCNPJ.js +0 -9
- package/dist/formats/formatToCPF.d.ts +0 -3
- package/dist/formats/formatToCPF.d.ts.map +0 -1
- package/dist/formats/formatToCPF.js +0 -9
- package/dist/parsers/parseToCharacters.d.ts +0 -17
- package/dist/parsers/parseToCharacters.d.ts.map +0 -1
- package/dist/parsers/parseToCharacters.js +0 -13
- package/dist/services/range.d.ts +0 -4
- package/dist/services/range.d.ts.map +0 -1
- package/dist/services/range.js +0 -9
- package/dist/validations/regex.d.ts +0 -15
- package/dist/validations/regex.d.ts.map +0 -1
- package/dist/validations/regex.js +0 -25
- package/dist/validations/validateCPF.d.ts +0 -3
- package/dist/validations/validateCPF.d.ts.map +0 -1
- package/dist/validations/validateCPF.js +0 -36
- package/src/formats/formatBrazilianDateHour.ts +0 -17
- package/src/formats/formatBrazilianDateToDate.ts +0 -13
- package/src/formats/formatDateHour.ts +0 -15
- package/src/formats/formatToBRL.ts +0 -10
- package/src/formats/formatToCNPJ.ts +0 -10
- package/src/formats/formatToCPF.ts +0 -10
- package/src/parsers/parseToCharacters.ts +0 -34
- package/src/services/range.ts +0 -15
- package/src/validations/regex.ts +0 -41
- package/src/validations/validateCPF.ts +0 -38
|
@@ -1,28 +1,50 @@
|
|
|
1
|
-
type
|
|
1
|
+
import type { ValidateDateFunction } from "@arkyn/types";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
29
|
+
const validateDate: ValidateDateFunction = (rawDate, config) => {
|
|
9
30
|
let day: string, month: string, year: string;
|
|
10
31
|
|
|
11
|
-
const
|
|
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 (
|
|
36
|
+
if (inputFormat === "DD/MM/YYYY") {
|
|
15
37
|
const dateRegex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
|
|
16
|
-
if (!dateRegex.test(
|
|
17
|
-
[, day, month, year] =
|
|
18
|
-
} else if (
|
|
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(
|
|
21
|
-
[, month, day, year] =
|
|
22
|
-
} else if (
|
|
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(
|
|
25
|
-
[, year, month, day] =
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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
package/vitest.config.ts
ADDED
|
@@ -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 +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 +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 +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 +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 +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,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 };
|
package/dist/services/range.d.ts
DELETED
|
@@ -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"}
|
package/dist/services/range.js
DELETED
|
@@ -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 +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 };
|
package/src/services/range.ts
DELETED
|
@@ -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 };
|