@arkyn/shared 1.4.52 → 2.0.1-beta.0
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/package.json +4 -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__/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 +7 -15
- 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__/validateCpf.spec.ts +38 -0
- package/src/validations/__test__/validateDate.spec.ts +81 -0
- package/src/validations/__test__/validatePhone.spec.ts +39 -0
- package/src/validations/validateCpf.ts +64 -0
- package/src/validations/validateDate.ts +33 -11
- package/src/validations/validatePhone.ts +29 -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/formatJsonObject.d.ts +0 -3
- package/dist/formats/formatJsonObject.d.ts.map +0 -1
- package/dist/formats/formatJsonObject.js +0 -49
- package/dist/formats/formatJsonString.d.ts +0 -3
- package/dist/formats/formatJsonString.d.ts.map +0 -1
- package/dist/formats/formatJsonString.js +0 -12
- 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/formats/formatToCep.d.ts +0 -3
- package/dist/formats/formatToCep.d.ts.map +0 -1
- package/dist/formats/formatToCep.js +0 -9
- package/dist/formats/formatToCpfCnpj.d.ts +0 -3
- package/dist/formats/formatToCpfCnpj.d.ts.map +0 -1
- package/dist/formats/formatToCpfCnpj.js +0 -13
- package/dist/formats/formatToEllipsis.d.ts +0 -3
- package/dist/formats/formatToEllipsis.d.ts.map +0 -1
- package/dist/formats/formatToEllipsis.js +0 -4
- package/dist/formats/formatToHiddenDigits.d.ts +0 -4
- package/dist/formats/formatToHiddenDigits.d.ts.map +0 -1
- package/dist/formats/formatToHiddenDigits.js +0 -14
- package/dist/formats/formatToPhone.d.ts +0 -3
- package/dist/formats/formatToPhone.d.ts.map +0 -1
- package/dist/formats/formatToPhone.js +0 -9
- package/dist/generators/generateColorByString.d.ts +0 -3
- package/dist/generators/generateColorByString.d.ts.map +0 -1
- package/dist/generators/generateColorByString.js +0 -14
- package/dist/generators/generateId.d.ts +0 -6
- package/dist/generators/generateId.d.ts.map +0 -1
- package/dist/generators/generateId.js +0 -23
- package/dist/generators/generateSlug.d.ts +0 -3
- package/dist/generators/generateSlug.d.ts.map +0 -1
- package/dist/generators/generateSlug.js +0 -11
- package/dist/index.d.ts +0 -26
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -30
- 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/calculateCardInstallment.d.ts +0 -7
- package/dist/services/calculateCardInstallment.d.ts.map +0 -1
- package/dist/services/calculateCardInstallment.js +0 -14
- package/dist/services/maskSensitiveData.d.ts +0 -3
- package/dist/services/maskSensitiveData.d.ts.map +0 -1
- package/dist/services/maskSensitiveData.js +0 -38
- 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/services/truncateLargeFields.d.ts +0 -3
- package/dist/services/truncateLargeFields.d.ts.map +0 -1
- package/dist/services/truncateLargeFields.js +0 -29
- 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/dist/validations/validateDate.d.ts +0 -8
- package/dist/validations/validateDate.d.ts.map +0 -1
- package/dist/validations/validateDate.js +0 -47
- package/dist/validations/validatePhone.d.ts +0 -3
- package/dist/validations/validatePhone.d.ts.map +0 -1
- package/dist/validations/validatePhone.js +0 -19
- 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/validateCPF.ts +0 -38
- /package/src/{validations/regex.ts → regex/index.ts} +0 -0
|
@@ -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 phone - 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 = (phone) => {
|
|
4
31
|
for (const country of countries) {
|
|
5
32
|
const countryCode = country.code;
|
|
6
33
|
const prefix = country.prefix ? `-${country.prefix}` : "";
|
|
@@ -17,6 +44,6 @@ function validatePhone(phone: string): boolean {
|
|
|
17
44
|
}
|
|
18
45
|
|
|
19
46
|
return false;
|
|
20
|
-
}
|
|
47
|
+
};
|
|
21
48
|
|
|
22
49
|
export { validatePhone };
|
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":"formatJsonObject.d.ts","sourceRoot":"","sources":["../../src/formats/formatJsonObject.ts"],"names":[],"mappings":"AAAA,iBAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CA6C/D;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
function formatJsonObject(obj, indentLevel) {
|
|
2
|
-
const indent = " ".repeat(indentLevel);
|
|
3
|
-
let formattedString = "";
|
|
4
|
-
if (typeof obj === "object" && obj !== null) {
|
|
5
|
-
if (Array.isArray(obj)) {
|
|
6
|
-
formattedString += "[\n";
|
|
7
|
-
obj.forEach((item, index) => {
|
|
8
|
-
formattedString +=
|
|
9
|
-
indent + " " + formatJsonObject(item, indentLevel + 1);
|
|
10
|
-
if (index < obj.length - 1) {
|
|
11
|
-
formattedString += ",";
|
|
12
|
-
}
|
|
13
|
-
formattedString += "\n";
|
|
14
|
-
});
|
|
15
|
-
formattedString += indent + "]";
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
formattedString += "{\n";
|
|
19
|
-
const keys = Object.keys(obj);
|
|
20
|
-
keys.forEach((key, index) => {
|
|
21
|
-
formattedString +=
|
|
22
|
-
indent +
|
|
23
|
-
' "' +
|
|
24
|
-
key +
|
|
25
|
-
'": ' +
|
|
26
|
-
formatJsonObject(obj[key], indentLevel + 1);
|
|
27
|
-
if (index < keys.length - 1) {
|
|
28
|
-
formattedString += ",";
|
|
29
|
-
}
|
|
30
|
-
formattedString += "\n";
|
|
31
|
-
});
|
|
32
|
-
formattedString += indent + "}";
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else if (typeof obj === "string") {
|
|
36
|
-
try {
|
|
37
|
-
const parsedObj = JSON.parse(obj);
|
|
38
|
-
formattedString += formatJsonObject(parsedObj, indentLevel);
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
formattedString += '"' + obj + '"';
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
formattedString += obj;
|
|
46
|
-
}
|
|
47
|
-
return formattedString;
|
|
48
|
-
}
|
|
49
|
-
export { formatJsonObject };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatJsonString.d.ts","sourceRoot":"","sources":["../../src/formats/formatJsonString.ts"],"names":[],"mappings":"AAEA,iBAAS,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAQpD;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { formatJsonObject } from "./formatJsonObject";
|
|
2
|
-
function formatJsonString(jsonString) {
|
|
3
|
-
try {
|
|
4
|
-
const jsonObject = JSON.parse(jsonString);
|
|
5
|
-
return formatJsonObject(jsonObject, 0);
|
|
6
|
-
}
|
|
7
|
-
catch (error) {
|
|
8
|
-
console.error("Invalid JSON string:", error);
|
|
9
|
-
return "";
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export { formatJsonString };
|
|
@@ -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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatToCep.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCep.ts"],"names":[],"mappings":"AAAA,iBAAS,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO1C;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatToCpfCnpj.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCpfCnpj.ts"],"names":[],"mappings":"AAGA,iBAAS,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ9C;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { formatToCNPJ } from "./formatToCNPJ";
|
|
2
|
-
import { formatToCPF } from "./formatToCPF";
|
|
3
|
-
function formatToCpfCnpj(value) {
|
|
4
|
-
const cleaned = value.replace(/\D/g, "");
|
|
5
|
-
if (cleaned.length === 11) {
|
|
6
|
-
return formatToCPF(cleaned);
|
|
7
|
-
}
|
|
8
|
-
else if (cleaned.length === 14) {
|
|
9
|
-
return formatToCNPJ(cleaned);
|
|
10
|
-
}
|
|
11
|
-
return value;
|
|
12
|
-
}
|
|
13
|
-
export { formatToCpfCnpj };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatToEllipsis.d.ts","sourceRoot":"","sources":["../../src/formats/formatToEllipsis.ts"],"names":[],"mappings":"AAAA,iBAAS,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,MAAM,CAEzD;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatToHiddenDigits.d.ts","sourceRoot":"","sources":["../../src/formats/formatToHiddenDigits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAKhE,QAAA,MAAM,oBAAoB,GACxB,OAAO,MAAM,EACb,UAAS,2BAAgC,KACxC,MAUF,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { parseToCharacters } from "../parsers/parseToCharacters";
|
|
2
|
-
import { normalizeRange, within } from "../services/range";
|
|
3
|
-
const formatToHiddenDigits = (value, options = {}) => {
|
|
4
|
-
const characters = parseToCharacters(value);
|
|
5
|
-
const range = normalizeRange(options.range ?? 3, characters.digits);
|
|
6
|
-
return characters.children
|
|
7
|
-
.map((node) => {
|
|
8
|
-
if (node.kind === "digit" && within(range, node.digit))
|
|
9
|
-
return options.hider ?? "*";
|
|
10
|
-
return node.character;
|
|
11
|
-
})
|
|
12
|
-
.join("");
|
|
13
|
-
};
|
|
14
|
-
export { formatToHiddenDigits };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatToPhone.d.ts","sourceRoot":"","sources":["../../src/formats/formatToPhone.ts"],"names":[],"mappings":"AAAA,iBAAS,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO5C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateColorByString.d.ts","sourceRoot":"","sources":["../../src/generators/generateColorByString.ts"],"names":[],"mappings":"AAAA,iBAAS,qBAAqB,CAAC,MAAM,EAAE,MAAM,UAgB5C;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
function generateColorByString(string) {
|
|
2
|
-
var hash = 0;
|
|
3
|
-
for (var i = 0; i < string.length; i++) {
|
|
4
|
-
hash = string.charCodeAt(i) + ((hash << 5) - hash);
|
|
5
|
-
}
|
|
6
|
-
var red = (hash & 0xff0000) >> 16;
|
|
7
|
-
var green = (hash & 0x00ff00) >> 8;
|
|
8
|
-
var blue = hash & 0x0000ff;
|
|
9
|
-
var redHex = red.toString(16).padStart(2, "0");
|
|
10
|
-
var greenHex = green.toString(16).padStart(2, "0");
|
|
11
|
-
var blueHex = blue.toString(16).padStart(2, "0");
|
|
12
|
-
return "#" + redHex + greenHex + blueHex;
|
|
13
|
-
}
|
|
14
|
-
export { generateColorByString };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateId.d.ts","sourceRoot":"","sources":["../../src/generators/generateId.ts"],"names":[],"mappings":"AAsBA,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ;;;EAK1C;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { v4, v7 } from "uuid";
|
|
2
|
-
function hexToBin(hex) {
|
|
3
|
-
const buffer = new Uint8Array(hex.length / 2);
|
|
4
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
5
|
-
buffer[i / 2] = parseInt(hex.substring(i, i + 2), 16);
|
|
6
|
-
}
|
|
7
|
-
return buffer;
|
|
8
|
-
}
|
|
9
|
-
function uuidV4() {
|
|
10
|
-
const uuid = v4();
|
|
11
|
-
return { text: uuid, binary: hexToBin(uuid) };
|
|
12
|
-
}
|
|
13
|
-
function uuidV7() {
|
|
14
|
-
const uuid = v7();
|
|
15
|
-
return { text: uuid, binary: hexToBin(uuid) };
|
|
16
|
-
}
|
|
17
|
-
function generateId(type) {
|
|
18
|
-
return {
|
|
19
|
-
v4: uuidV4()[type],
|
|
20
|
-
v7: uuidV7()[type],
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export { generateId };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateSlug.d.ts","sourceRoot":"","sources":["../../src/generators/generateSlug.ts"],"names":[],"mappings":"AAAA,iBAAS,YAAY,CAAC,MAAM,EAAE,MAAM,UAanC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
function generateSlug(string) {
|
|
2
|
-
let slug = string.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
3
|
-
slug = slug
|
|
4
|
-
.replace(/[^\w\s-]/g, "")
|
|
5
|
-
.replace(/\s+/g, "-")
|
|
6
|
-
.toLowerCase();
|
|
7
|
-
slug = slug.replace(/-{2,}/g, "-");
|
|
8
|
-
slug = slug.replace(/^-+|-+$/g, "");
|
|
9
|
-
return slug;
|
|
10
|
-
}
|
|
11
|
-
export { generateSlug };
|
package/dist/index.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export { formatBrazilianDateHour } from "./formats/formatBrazilianDateHour";
|
|
2
|
-
export { formatBrazilianDateToDate } from "./formats/formatBrazilianDateToDate";
|
|
3
|
-
export { formatDateHour } from "./formats/formatDateHour";
|
|
4
|
-
export { formatJsonObject } from "./formats/formatJsonObject";
|
|
5
|
-
export { formatJsonString } from "./formats/formatJsonString";
|
|
6
|
-
export { formatToBRL } from "./formats/formatToBRL";
|
|
7
|
-
export { formatToCep } from "./formats/formatToCep";
|
|
8
|
-
export { formatToCNPJ } from "./formats/formatToCNPJ";
|
|
9
|
-
export { formatToCPF } from "./formats/formatToCPF";
|
|
10
|
-
export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
|
|
11
|
-
export { formatToEllipsis } from "./formats/formatToEllipsis";
|
|
12
|
-
export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
|
|
13
|
-
export { formatToPhone } from "./formats/formatToPhone";
|
|
14
|
-
export { generateColorByString } from "./generators/generateColorByString";
|
|
15
|
-
export { generateId } from "./generators/generateId";
|
|
16
|
-
export { generateSlug } from "./generators/generateSlug";
|
|
17
|
-
export { parseToCharacters } from "./parsers/parseToCharacters";
|
|
18
|
-
export { calculateCardInstallment } from "./services/calculateCardInstallment";
|
|
19
|
-
export { maskSensitiveData } from "./services/maskSensitiveData";
|
|
20
|
-
export { normalizeRange, within } from "./services/range";
|
|
21
|
-
export { truncateLargeFields } from "./services/truncateLargeFields";
|
|
22
|
-
export { regex } from "./validations/regex";
|
|
23
|
-
export { validateCPF } from "./validations/validateCPF";
|
|
24
|
-
export { validateDate } from "./validations/validateDate";
|
|
25
|
-
export { validatePhone } from "./validations/validatePhone";
|
|
26
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,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,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,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,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// formats
|
|
2
|
-
export { formatBrazilianDateHour } from "./formats/formatBrazilianDateHour";
|
|
3
|
-
export { formatBrazilianDateToDate } from "./formats/formatBrazilianDateToDate";
|
|
4
|
-
export { formatDateHour } from "./formats/formatDateHour";
|
|
5
|
-
export { formatJsonObject } from "./formats/formatJsonObject";
|
|
6
|
-
export { formatJsonString } from "./formats/formatJsonString";
|
|
7
|
-
export { formatToBRL } from "./formats/formatToBRL";
|
|
8
|
-
export { formatToCep } from "./formats/formatToCep";
|
|
9
|
-
export { formatToCNPJ } from "./formats/formatToCNPJ";
|
|
10
|
-
export { formatToCPF } from "./formats/formatToCPF";
|
|
11
|
-
export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
|
|
12
|
-
export { formatToEllipsis } from "./formats/formatToEllipsis";
|
|
13
|
-
export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
|
|
14
|
-
export { formatToPhone } from "./formats/formatToPhone";
|
|
15
|
-
// generators
|
|
16
|
-
export { generateColorByString } from "./generators/generateColorByString";
|
|
17
|
-
export { generateId } from "./generators/generateId";
|
|
18
|
-
export { generateSlug } from "./generators/generateSlug";
|
|
19
|
-
// parsers
|
|
20
|
-
export { parseToCharacters } from "./parsers/parseToCharacters";
|
|
21
|
-
// services
|
|
22
|
-
export { calculateCardInstallment } from "./services/calculateCardInstallment";
|
|
23
|
-
export { maskSensitiveData } from "./services/maskSensitiveData";
|
|
24
|
-
export { normalizeRange, within } from "./services/range";
|
|
25
|
-
export { truncateLargeFields } from "./services/truncateLargeFields";
|
|
26
|
-
// validations
|
|
27
|
-
export { regex } from "./validations/regex";
|
|
28
|
-
export { validateCPF } from "./validations/validateCPF";
|
|
29
|
-
export { validateDate } from "./validations/validateDate";
|
|
30
|
-
export { validatePhone } from "./validations/validatePhone";
|
|
@@ -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,7 +0,0 @@
|
|
|
1
|
-
import type { CalculateCardInstallmentProps } from "@arkyn/types";
|
|
2
|
-
declare function calculateCardInstallment(args: CalculateCardInstallmentProps): {
|
|
3
|
-
total_price: number;
|
|
4
|
-
installment_price: number;
|
|
5
|
-
};
|
|
6
|
-
export { calculateCardInstallment };
|
|
7
|
-
//# sourceMappingURL=calculateCardInstallment.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculateCardInstallment.d.ts","sourceRoot":"","sources":["../../src/services/calculateCardInstallment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAElE,iBAAS,wBAAwB,CAAC,IAAI,EAAE,6BAA6B;;;EAgBpE;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
function calculateCardInstallment(args) {
|
|
2
|
-
const { cash_price, number_installments, fees = 0.0349 } = args;
|
|
3
|
-
let installment_price = 0;
|
|
4
|
-
let total_price = 0;
|
|
5
|
-
let numerator = Math.pow(1 + fees, number_installments) * fees;
|
|
6
|
-
let denominator = Math.pow(1 + fees, number_installments) - 1;
|
|
7
|
-
installment_price = cash_price * (numerator / denominator);
|
|
8
|
-
total_price = number_installments * installment_price;
|
|
9
|
-
return {
|
|
10
|
-
total_price: +total_price.toFixed(2),
|
|
11
|
-
installment_price: +installment_price.toFixed(2),
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export { calculateCardInstallment };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"maskSensitiveData.d.ts","sourceRoot":"","sources":["../../src/services/maskSensitiveData.ts"],"names":[],"mappings":"AAAA,iBAAS,iBAAiB,CACxB,UAAU,EAAE,MAAM,EAClB,aAAa,WAAgD,GAC5D,MAAM,CAkCR;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
function maskSensitiveData(jsonString, sensitiveKeys = ["password", "confirmPassword", "creditCard"]) {
|
|
2
|
-
function maskValue(key, value) {
|
|
3
|
-
if (sensitiveKeys.includes(key))
|
|
4
|
-
return "****";
|
|
5
|
-
return value;
|
|
6
|
-
}
|
|
7
|
-
function recursiveMask(obj) {
|
|
8
|
-
if (Array.isArray(obj)) {
|
|
9
|
-
return obj.map((item) => recursiveMask(item));
|
|
10
|
-
}
|
|
11
|
-
else if (obj !== null && typeof obj === "object") {
|
|
12
|
-
return Object.keys(obj).reduce((acc, key) => {
|
|
13
|
-
let value = obj[key];
|
|
14
|
-
if (typeof value === "string") {
|
|
15
|
-
try {
|
|
16
|
-
const parsedValue = JSON.parse(value);
|
|
17
|
-
if (typeof parsedValue === "object") {
|
|
18
|
-
value = JSON.stringify(recursiveMask(parsedValue));
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
catch (e) { }
|
|
22
|
-
}
|
|
23
|
-
acc[key] = recursiveMask(maskValue(key, value));
|
|
24
|
-
return acc;
|
|
25
|
-
}, {});
|
|
26
|
-
}
|
|
27
|
-
return obj;
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
const jsonObject = JSON.parse(jsonString);
|
|
31
|
-
const maskedObject = recursiveMask(jsonObject);
|
|
32
|
-
return JSON.stringify(maskedObject);
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
return jsonString;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export { maskSensitiveData };
|
package/dist/services/range.d.ts
DELETED