@arkyn/shared 1.5.0 → 1.5.2
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,5 +1,6 @@
|
|
|
1
1
|
import { v4, v7 } from "uuid";
|
|
2
2
|
function hexToBin(hex) {
|
|
3
|
+
hex = hex.replace(/-/g, "");
|
|
3
4
|
const buffer = new Uint8Array(hex.length / 2);
|
|
4
5
|
for (let i = 0; i < hex.length; i += 2) {
|
|
5
6
|
buffer[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
@@ -14,10 +15,15 @@ function uuidV7() {
|
|
|
14
15
|
const uuid = v7();
|
|
15
16
|
return { text: uuid, binary: hexToBin(uuid) };
|
|
16
17
|
}
|
|
17
|
-
function generateId(type) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
function generateId(type, format) {
|
|
19
|
+
if (type === "text" && format === "v4")
|
|
20
|
+
return uuidV4().text;
|
|
21
|
+
if (type === "binary" && format === "v4")
|
|
22
|
+
return uuidV4().binary;
|
|
23
|
+
if (type === "text" && format === "v7")
|
|
24
|
+
return uuidV7().text;
|
|
25
|
+
if (type === "binary" && format === "v7")
|
|
26
|
+
return uuidV7().binary;
|
|
27
|
+
throw new Error("Invalid type or format");
|
|
22
28
|
}
|
|
23
29
|
export { generateId };
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Generates a URL-friendly slug from a given string.
|
|
3
|
+
*
|
|
4
|
+
* The function performs the following transformations:
|
|
5
|
+
* - Normalizes the string to remove diacritical marks (e.g., accents).
|
|
6
|
+
* - Removes non-alphanumeric characters except for spaces and hyphens.
|
|
7
|
+
* - Replaces spaces with hyphens.
|
|
8
|
+
* - Converts the string to lowercase.
|
|
9
|
+
* - Collapses multiple consecutive hyphens into a single hyphen.
|
|
10
|
+
* - Trims leading and trailing hyphens.
|
|
11
|
+
*
|
|
12
|
+
* @param string - The input string to be converted into a slug.
|
|
13
|
+
* @returns A URL-friendly slug derived from the input string.
|
|
14
|
+
*/
|
|
15
|
+
declare function generateSlug(prop: string): string;
|
|
2
16
|
export { generateSlug };
|
|
3
17
|
//# sourceMappingURL=generateSlug.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateSlug.d.ts","sourceRoot":"","sources":["../../src/generators/generateSlug.ts"],"names":[],"mappings":"AAAA,iBAAS,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"generateSlug.d.ts","sourceRoot":"","sources":["../../src/generators/generateSlug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,iBAAS,YAAY,CAAC,IAAI,EAAE,MAAM,UAajC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Generates a URL-friendly slug from a given string.
|
|
3
|
+
*
|
|
4
|
+
* The function performs the following transformations:
|
|
5
|
+
* - Normalizes the string to remove diacritical marks (e.g., accents).
|
|
6
|
+
* - Removes non-alphanumeric characters except for spaces and hyphens.
|
|
7
|
+
* - Replaces spaces with hyphens.
|
|
8
|
+
* - Converts the string to lowercase.
|
|
9
|
+
* - Collapses multiple consecutive hyphens into a single hyphen.
|
|
10
|
+
* - Trims leading and trailing hyphens.
|
|
11
|
+
*
|
|
12
|
+
* @param string - The input string to be converted into a slug.
|
|
13
|
+
* @returns A URL-friendly slug derived from the input string.
|
|
14
|
+
*/
|
|
15
|
+
function generateSlug(prop) {
|
|
16
|
+
let slug = prop.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
3
17
|
slug = slug
|
|
4
18
|
.replace(/[^\w\s-]/g, "")
|
|
5
19
|
.replace(/\s+/g, "-")
|
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { formatBrazilianDateToDate } from "./formats/formatBrazilianDateToDate";
|
|
3
|
-
export { formatDateHour } from "./formats/formatDateHour";
|
|
1
|
+
export { formatDate } from "./formats/formatDate";
|
|
4
2
|
export { formatJsonObject } from "./formats/formatJsonObject";
|
|
5
3
|
export { formatJsonString } from "./formats/formatJsonString";
|
|
6
|
-
export { formatToBRL } from "./formats/formatToBRL";
|
|
7
4
|
export { formatToCep } from "./formats/formatToCep";
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
5
|
+
export { formatToCnpj } from "./formats/formatToCnpj";
|
|
6
|
+
export { formatToCpf } from "./formats/formatToCpf";
|
|
10
7
|
export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
|
|
8
|
+
export { formatToCurrency } from "./formats/formatToCurrency";
|
|
11
9
|
export { formatToEllipsis } from "./formats/formatToEllipsis";
|
|
12
10
|
export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
|
|
13
11
|
export { formatToPhone } from "./formats/formatToPhone";
|
|
14
12
|
export { generateColorByString } from "./generators/generateColorByString";
|
|
15
13
|
export { generateId } from "./generators/generateId";
|
|
16
14
|
export { generateSlug } from "./generators/generateSlug";
|
|
17
|
-
export { parseToCharacters } from "./parsers/parseToCharacters";
|
|
18
15
|
export { calculateCardInstallment } from "./services/calculateCardInstallment";
|
|
19
16
|
export { maskSensitiveData } from "./services/maskSensitiveData";
|
|
20
|
-
export {
|
|
17
|
+
export { removeNonNumeric } from "./services/removeNonNumeric";
|
|
21
18
|
export { truncateLargeFields } from "./services/truncateLargeFields";
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
19
|
+
export { validateCep } from "./validations/validateCep";
|
|
20
|
+
export { validateCnpj } from "./validations/validateCnpj";
|
|
21
|
+
export { validateCpf } from "./validations/validateCpf";
|
|
24
22
|
export { validateDate } from "./validations/validateDate";
|
|
25
23
|
export { validatePhone } from "./validations/validatePhone";
|
|
24
|
+
export { validateRg } from "./validations/validateRg";
|
|
26
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
// formats
|
|
2
|
-
export {
|
|
3
|
-
export { formatBrazilianDateToDate } from "./formats/formatBrazilianDateToDate";
|
|
4
|
-
export { formatDateHour } from "./formats/formatDateHour";
|
|
2
|
+
export { formatDate } from "./formats/formatDate";
|
|
5
3
|
export { formatJsonObject } from "./formats/formatJsonObject";
|
|
6
4
|
export { formatJsonString } from "./formats/formatJsonString";
|
|
7
|
-
export { formatToBRL } from "./formats/formatToBRL";
|
|
8
5
|
export { formatToCep } from "./formats/formatToCep";
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
6
|
+
export { formatToCnpj } from "./formats/formatToCnpj";
|
|
7
|
+
export { formatToCpf } from "./formats/formatToCpf";
|
|
11
8
|
export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
|
|
9
|
+
export { formatToCurrency } from "./formats/formatToCurrency";
|
|
12
10
|
export { formatToEllipsis } from "./formats/formatToEllipsis";
|
|
13
11
|
export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
|
|
14
12
|
export { formatToPhone } from "./formats/formatToPhone";
|
|
@@ -16,15 +14,15 @@ export { formatToPhone } from "./formats/formatToPhone";
|
|
|
16
14
|
export { generateColorByString } from "./generators/generateColorByString";
|
|
17
15
|
export { generateId } from "./generators/generateId";
|
|
18
16
|
export { generateSlug } from "./generators/generateSlug";
|
|
19
|
-
// parsers
|
|
20
|
-
export { parseToCharacters } from "./parsers/parseToCharacters";
|
|
21
17
|
// services
|
|
22
18
|
export { calculateCardInstallment } from "./services/calculateCardInstallment";
|
|
23
19
|
export { maskSensitiveData } from "./services/maskSensitiveData";
|
|
24
|
-
export {
|
|
20
|
+
export { removeNonNumeric } from "./services/removeNonNumeric";
|
|
25
21
|
export { truncateLargeFields } from "./services/truncateLargeFields";
|
|
26
|
-
//
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
22
|
+
// utils
|
|
23
|
+
export { validateCep } from "./validations/validateCep";
|
|
24
|
+
export { validateCnpj } from "./validations/validateCnpj";
|
|
25
|
+
export { validateCpf } from "./validations/validateCpf";
|
|
29
26
|
export { validateDate } from "./validations/validateDate";
|
|
30
27
|
export { validatePhone } from "./validations/validatePhone";
|
|
28
|
+
export { validateRg } from "./validations/validateRg";
|
|
@@ -1,7 +1,33 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { CalculateCardInstallmentFunction } from "@arkyn/types";
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the installment price and total price for a card payment plan.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* **Important:** When the interest amount (`fees`) is equal to 0 or the number of installments (`numberInstallments`) is equal to 1, no interest will be charged.
|
|
7
|
+
*
|
|
8
|
+
* @throws Will throw an error if the number of installments is less than or equal to 0.
|
|
9
|
+
* @throws Will throw an error if the fees are less than 0.
|
|
10
|
+
*
|
|
11
|
+
* @param props - The input parameters for the calculation.
|
|
12
|
+
* @param props.cashPrice - The total cash price of the product or service.
|
|
13
|
+
* @param props.numberInstallments - The number of installments for the payment plan.
|
|
14
|
+
* @param props.fees - The interest rate per installment (default is 0.0349).
|
|
15
|
+
*
|
|
16
|
+
* @returns An object containing:
|
|
17
|
+
* - `totalPrice`: The total price to be paid, rounded to two decimal places.
|
|
18
|
+
* - `installmentPrice`: The price of each installment, rounded to two decimal places.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const result = calculateCardInstallment({
|
|
23
|
+
* cashPrice: 1000,
|
|
24
|
+
* numberInstallments: 12,
|
|
25
|
+
* fees: 0.02,
|
|
26
|
+
* });
|
|
27
|
+
* console.log(result);
|
|
28
|
+
* // Output: { totalPrice: 1124.62, installmentPrice: 93.72 }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare const calculateCardInstallment: CalculateCardInstallmentFunction;
|
|
6
32
|
export { calculateCardInstallment };
|
|
7
33
|
//# sourceMappingURL=calculateCardInstallment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculateCardInstallment.d.ts","sourceRoot":"","sources":["../../src/services/calculateCardInstallment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"calculateCardInstallment.d.ts","sourceRoot":"","sources":["../../src/services/calculateCardInstallment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,cAAc,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,QAAA,MAAM,wBAAwB,EAAE,gCA+B/B,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -1,14 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Calculates the installment price and total price for a card payment plan.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* **Important:** When the interest amount (`fees`) is equal to 0 or the number of installments (`numberInstallments`) is equal to 1, no interest will be charged.
|
|
6
|
+
*
|
|
7
|
+
* @throws Will throw an error if the number of installments is less than or equal to 0.
|
|
8
|
+
* @throws Will throw an error if the fees are less than 0.
|
|
9
|
+
*
|
|
10
|
+
* @param props - The input parameters for the calculation.
|
|
11
|
+
* @param props.cashPrice - The total cash price of the product or service.
|
|
12
|
+
* @param props.numberInstallments - The number of installments for the payment plan.
|
|
13
|
+
* @param props.fees - The interest rate per installment (default is 0.0349).
|
|
14
|
+
*
|
|
15
|
+
* @returns An object containing:
|
|
16
|
+
* - `totalPrice`: The total price to be paid, rounded to two decimal places.
|
|
17
|
+
* - `installmentPrice`: The price of each installment, rounded to two decimal places.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const result = calculateCardInstallment({
|
|
22
|
+
* cashPrice: 1000,
|
|
23
|
+
* numberInstallments: 12,
|
|
24
|
+
* fees: 0.02,
|
|
25
|
+
* });
|
|
26
|
+
* console.log(result);
|
|
27
|
+
* // Output: { totalPrice: 1124.62, installmentPrice: 93.72 }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const calculateCardInstallment = (props) => {
|
|
31
|
+
const { cashPrice, numberInstallments, fees = 0.0349 } = props;
|
|
32
|
+
if (fees === 0 || numberInstallments === 1) {
|
|
33
|
+
return {
|
|
34
|
+
totalPrice: cashPrice,
|
|
35
|
+
installmentPrice: cashPrice / numberInstallments,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (numberInstallments <= 0) {
|
|
39
|
+
throw new Error("Number of installments must be greater than 0");
|
|
40
|
+
}
|
|
41
|
+
if (fees < 0) {
|
|
42
|
+
throw new Error("Fees must be greater than or equal to 0");
|
|
43
|
+
}
|
|
44
|
+
let installmentPrice = 0;
|
|
45
|
+
let totalPrice = 0;
|
|
46
|
+
let numerator = Math.pow(1 + fees, numberInstallments) * fees;
|
|
47
|
+
let denominator = Math.pow(1 + fees, numberInstallments) - 1;
|
|
48
|
+
installmentPrice = cashPrice * (numerator / denominator);
|
|
49
|
+
totalPrice = numberInstallments * installmentPrice;
|
|
9
50
|
return {
|
|
10
|
-
|
|
11
|
-
|
|
51
|
+
totalPrice: +totalPrice.toFixed(2),
|
|
52
|
+
installmentPrice: +installmentPrice.toFixed(2),
|
|
12
53
|
};
|
|
13
|
-
}
|
|
54
|
+
};
|
|
14
55
|
export { calculateCardInstallment };
|
|
@@ -1,3 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import type { MaskSensitiveDataFunction } from "@arkyn/types";
|
|
2
|
+
/**
|
|
3
|
+
* Masks sensitive data in a JSON string by replacing the values of specified keys with "****".
|
|
4
|
+
*
|
|
5
|
+
* @param jsonString - The JSON string to be processed.
|
|
6
|
+
* @param sensitiveKeys - An array of keys whose values should be masked. Defaults to `["password", "confirmPassword", "creditCard"]`.
|
|
7
|
+
* @returns A JSON string with sensitive data masked. If the input is not a valid JSON string, it returns the original string.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const jsonString = JSON.stringify({
|
|
12
|
+
* username: "user123",
|
|
13
|
+
* password: "secret",
|
|
14
|
+
* profile: {
|
|
15
|
+
* creditCard: "1234-5678-9012-3456",
|
|
16
|
+
* },
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* const result = maskSensitiveData(jsonString, ["password", "creditCard"]);
|
|
20
|
+
* console.log(result);
|
|
21
|
+
* // Output: '{"username":"user123","password":"****","profile":{"creditCard":"****"}}'
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare const maskSensitiveData: MaskSensitiveDataFunction;
|
|
2
25
|
export { maskSensitiveData };
|
|
3
26
|
//# sourceMappingURL=maskSensitiveData.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"maskSensitiveData.d.ts","sourceRoot":"","sources":["../../src/services/maskSensitiveData.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"maskSensitiveData.d.ts","sourceRoot":"","sources":["../../src/services/maskSensitiveData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,QAAA,MAAM,iBAAiB,EAAE,yBAqCxB,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1,4 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Masks sensitive data in a JSON string by replacing the values of specified keys with "****".
|
|
3
|
+
*
|
|
4
|
+
* @param jsonString - The JSON string to be processed.
|
|
5
|
+
* @param sensitiveKeys - An array of keys whose values should be masked. Defaults to `["password", "confirmPassword", "creditCard"]`.
|
|
6
|
+
* @returns A JSON string with sensitive data masked. If the input is not a valid JSON string, it returns the original string.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const jsonString = JSON.stringify({
|
|
11
|
+
* username: "user123",
|
|
12
|
+
* password: "secret",
|
|
13
|
+
* profile: {
|
|
14
|
+
* creditCard: "1234-5678-9012-3456",
|
|
15
|
+
* },
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* const result = maskSensitiveData(jsonString, ["password", "creditCard"]);
|
|
19
|
+
* console.log(result);
|
|
20
|
+
* // Output: '{"username":"user123","password":"****","profile":{"creditCard":"****"}}'
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const maskSensitiveData = (jsonString, sensitiveKeys = ["password", "confirmPassword", "creditCard"]) => {
|
|
2
24
|
function maskValue(key, value) {
|
|
3
25
|
if (sensitiveKeys.includes(key))
|
|
4
26
|
return "****";
|
|
@@ -34,5 +56,5 @@ function maskSensitiveData(jsonString, sensitiveKeys = ["password", "confirmPass
|
|
|
34
56
|
catch (error) {
|
|
35
57
|
return jsonString;
|
|
36
58
|
}
|
|
37
|
-
}
|
|
59
|
+
};
|
|
38
60
|
export { maskSensitiveData };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes currency symbols from a given formatted string.
|
|
3
|
+
*
|
|
4
|
+
* This function takes a string that may contain currency symbols
|
|
5
|
+
* and removes them using a regular expression. The resulting string
|
|
6
|
+
* is also trimmed of any leading or trailing whitespace.
|
|
7
|
+
*
|
|
8
|
+
* @param formattedValue - The input string containing currency symbols.
|
|
9
|
+
* @returns A string with all currency symbols removed and trimmed of whitespace.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* removeCurrencySymbols("R$13,45"); // "13,45"
|
|
13
|
+
* removeCurrencySymbols("$123.45"); // "123.45"
|
|
14
|
+
* removeCurrencySymbols("€99.99"); // "99.99"
|
|
15
|
+
* removeCurrencySymbols("¥1,000"); // "1,000"
|
|
16
|
+
* removeCurrencySymbols("123.45"); // "123.45" (no symbols to remove)
|
|
17
|
+
*/
|
|
18
|
+
declare const removeCurrencySymbols: (formattedValue: string) => string;
|
|
19
|
+
export { removeCurrencySymbols };
|
|
20
|
+
//# sourceMappingURL=removeCurrencySymbols.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeCurrencySymbols.d.ts","sourceRoot":"","sources":["../../src/services/removeCurrencySymbols.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,QAAA,MAAM,qBAAqB,GAAI,gBAAgB,MAAM,KAAG,MAIvD,CAAC;AAEF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes currency symbols from a given formatted string.
|
|
3
|
+
*
|
|
4
|
+
* This function takes a string that may contain currency symbols
|
|
5
|
+
* and removes them using a regular expression. The resulting string
|
|
6
|
+
* is also trimmed of any leading or trailing whitespace.
|
|
7
|
+
*
|
|
8
|
+
* @param formattedValue - The input string containing currency symbols.
|
|
9
|
+
* @returns A string with all currency symbols removed and trimmed of whitespace.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* removeCurrencySymbols("R$13,45"); // "13,45"
|
|
13
|
+
* removeCurrencySymbols("$123.45"); // "123.45"
|
|
14
|
+
* removeCurrencySymbols("€99.99"); // "99.99"
|
|
15
|
+
* removeCurrencySymbols("¥1,000"); // "1,000"
|
|
16
|
+
* removeCurrencySymbols("123.45"); // "123.45" (no symbols to remove)
|
|
17
|
+
*/
|
|
18
|
+
const removeCurrencySymbols = (formattedValue) => {
|
|
19
|
+
return formattedValue
|
|
20
|
+
.replace(/(?:R\$|\p{Sc}|[$€¥£])/gu, "") // Inclui "R$" e outros símbolos comuns
|
|
21
|
+
.trim();
|
|
22
|
+
};
|
|
23
|
+
export { removeCurrencySymbols };
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
declare function removeNonNumeric(prop: string): string;
|
|
14
|
+
export { removeNonNumeric };
|
|
15
|
+
//# sourceMappingURL=removeNonNumeric.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeNonNumeric.d.ts","sourceRoot":"","sources":["../../src/services/removeNonNumeric.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,iBAAS,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
function removeNonNumeric(prop) {
|
|
14
|
+
return prop.replace(/[^0-9]/g, "");
|
|
15
|
+
}
|
|
16
|
+
export { removeNonNumeric };
|
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TruncateLargeFieldsFunction } from "@arkyn/types";
|
|
2
|
+
/**
|
|
3
|
+
* Truncates large string fields in a JSON string to a specified maximum length.
|
|
4
|
+
*
|
|
5
|
+
* This function parses a JSON string, traverses its structure recursively, and truncates
|
|
6
|
+
* any string fields that exceed the specified maximum length. If a string field is truncated,
|
|
7
|
+
* it is replaced with a message indicating the original length of the field.
|
|
8
|
+
*
|
|
9
|
+
* @param jsonString - The JSON string to process.
|
|
10
|
+
* @param maxLength - The maximum allowed length for string fields. Defaults to 1000.
|
|
11
|
+
* @returns A JSON string with large string fields truncated.
|
|
12
|
+
*
|
|
13
|
+
* @throws {Error} Throws an error if the input is not a valid JSON string.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const json = JSON.stringify({
|
|
18
|
+
* name: "John",
|
|
19
|
+
* description: "A very long description that exceeds the maximum length...",
|
|
20
|
+
* nested: {
|
|
21
|
+
* details: "Another long string that needs truncation."
|
|
22
|
+
* }
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* const result = truncateLargeFields(json, 50);
|
|
26
|
+
* console.log(result);
|
|
27
|
+
* // Output: '{"name":"John","description":"To large information: field as 57 characters","nested":{"details":"To large information: field as 43 characters"}}'
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare const truncateLargeFields: TruncateLargeFieldsFunction;
|
|
2
31
|
export { truncateLargeFields };
|
|
3
32
|
//# sourceMappingURL=truncateLargeFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"truncateLargeFields.d.ts","sourceRoot":"","sources":["../../src/services/truncateLargeFields.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"truncateLargeFields.d.ts","sourceRoot":"","sources":["../../src/services/truncateLargeFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,QAAA,MAAM,mBAAmB,EAAE,2BAgC1B,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -1,5 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Truncates large string fields in a JSON string to a specified maximum length.
|
|
3
|
+
*
|
|
4
|
+
* This function parses a JSON string, traverses its structure recursively, and truncates
|
|
5
|
+
* any string fields that exceed the specified maximum length. If a string field is truncated,
|
|
6
|
+
* it is replaced with a message indicating the original length of the field.
|
|
7
|
+
*
|
|
8
|
+
* @param jsonString - The JSON string to process.
|
|
9
|
+
* @param maxLength - The maximum allowed length for string fields. Defaults to 1000.
|
|
10
|
+
* @returns A JSON string with large string fields truncated.
|
|
11
|
+
*
|
|
12
|
+
* @throws {Error} Throws an error if the input is not a valid JSON string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const json = JSON.stringify({
|
|
17
|
+
* name: "John",
|
|
18
|
+
* description: "A very long description that exceeds the maximum length...",
|
|
19
|
+
* nested: {
|
|
20
|
+
* details: "Another long string that needs truncation."
|
|
21
|
+
* }
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* const result = truncateLargeFields(json, 50);
|
|
25
|
+
* console.log(result);
|
|
26
|
+
* // Output: '{"name":"John","description":"To large information: field as 57 characters","nested":{"details":"To large information: field as 43 characters"}}'
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const truncateLargeFields = (jsonString, maxLength = 1000) => {
|
|
30
|
+
function truncateValue(value) {
|
|
3
31
|
if (typeof value === "string" && value.length > maxLength) {
|
|
4
32
|
return `To large information: field as ${value.length} characters`;
|
|
5
33
|
}
|
|
@@ -7,15 +35,15 @@ function truncateLargeFields(jsonString, maxLength = 1000) {
|
|
|
7
35
|
}
|
|
8
36
|
function recursiveTruncate(obj) {
|
|
9
37
|
if (Array.isArray(obj)) {
|
|
10
|
-
return obj.map(recursiveTruncate);
|
|
38
|
+
return obj.map((item) => recursiveTruncate(item)); // Corrigido para processar elementos do array
|
|
11
39
|
}
|
|
12
40
|
else if (obj !== null && typeof obj === "object") {
|
|
13
41
|
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
|
|
14
42
|
key,
|
|
15
|
-
|
|
43
|
+
recursiveTruncate(value), // Corrigido para aplicar recursão corretamente
|
|
16
44
|
]));
|
|
17
45
|
}
|
|
18
|
-
return obj;
|
|
46
|
+
return truncateValue(obj); // Corrigido para truncar valores diretamente
|
|
19
47
|
}
|
|
20
48
|
try {
|
|
21
49
|
const parsedJson = JSON.parse(jsonString);
|
|
@@ -25,5 +53,5 @@ function truncateLargeFields(jsonString, maxLength = 1000) {
|
|
|
25
53
|
catch (error) {
|
|
26
54
|
throw new Error("Invalid JSON string");
|
|
27
55
|
}
|
|
28
|
-
}
|
|
56
|
+
};
|
|
29
57
|
export { truncateLargeFields };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ValidateCepFunction } from "@arkyn/types";
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateCep.d.ts","sourceRoot":"","sources":["../../src/validations/validateCep.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGxD;;;;GAIG;AAEH;;;;;;;;;;;;;;GAcG;AAEH,QAAA,MAAM,WAAW,EAAE,mBAYlB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ValidateCnpjFunction } from "@arkyn/types";
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateCnpj.d.ts","sourceRoot":"","sources":["../../src/validations/validateCnpj.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AA0BzD;;;;;;;;;;;;;;;;;GAiBG;AAEH,QAAA,MAAM,YAAY,EAAE,oBAgBnB,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
|