@arkyn/shared 1.4.57 → 1.5.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/dist/formats/formatBrazilianDateHour.d.ts +3 -0
- package/dist/formats/formatBrazilianDateHour.d.ts.map +1 -0
- package/dist/formats/formatBrazilianDateHour.js +12 -0
- package/dist/formats/formatBrazilianDateToDate.d.ts +3 -0
- package/dist/formats/formatBrazilianDateToDate.d.ts.map +1 -0
- package/dist/formats/formatBrazilianDateToDate.js +9 -0
- package/dist/formats/formatDateHour.d.ts +3 -0
- package/dist/formats/formatDateHour.d.ts.map +1 -0
- package/dist/formats/formatDateHour.js +11 -0
- package/dist/formats/formatJsonObject.d.ts +1 -31
- package/dist/formats/formatJsonObject.d.ts.map +1 -1
- package/dist/formats/formatJsonObject.js +26 -67
- package/dist/formats/formatJsonString.d.ts +1 -37
- package/dist/formats/formatJsonString.d.ts.map +1 -1
- package/dist/formats/formatJsonString.js +4 -38
- package/dist/formats/formatToBRL.d.ts +3 -0
- package/dist/formats/formatToBRL.d.ts.map +1 -0
- package/dist/formats/formatToBRL.js +8 -0
- package/dist/formats/formatToCNPJ.d.ts +3 -0
- package/dist/formats/formatToCNPJ.d.ts.map +1 -0
- package/dist/formats/formatToCNPJ.js +9 -0
- package/dist/formats/formatToCPF.d.ts +3 -0
- package/dist/formats/formatToCPF.d.ts.map +1 -0
- package/dist/formats/formatToCPF.js +9 -0
- package/dist/formats/formatToCep.d.ts +1 -27
- package/dist/formats/formatToCep.d.ts.map +1 -1
- package/dist/formats/formatToCep.js +6 -31
- package/dist/formats/formatToCpfCnpj.d.ts +1 -22
- package/dist/formats/formatToCpfCnpj.d.ts.map +1 -1
- package/dist/formats/formatToCpfCnpj.js +7 -27
- package/dist/formats/formatToEllipsis.d.ts +1 -14
- package/dist/formats/formatToEllipsis.d.ts.map +1 -1
- package/dist/formats/formatToEllipsis.js +3 -20
- package/dist/formats/formatToHiddenDigits.d.ts +2 -30
- package/dist/formats/formatToHiddenDigits.d.ts.map +1 -1
- package/dist/formats/formatToHiddenDigits.js +3 -49
- package/dist/formats/formatToPhone.d.ts +1 -32
- package/dist/formats/formatToPhone.d.ts.map +1 -1
- package/dist/formats/formatToPhone.js +6 -128
- package/dist/generators/generateColorByString.d.ts +1 -13
- package/dist/generators/generateColorByString.d.ts.map +1 -1
- package/dist/generators/generateColorByString.js +4 -15
- package/dist/generators/generateId.d.ts +4 -26
- package/dist/generators/generateId.d.ts.map +1 -1
- package/dist/generators/generateId.js +5 -11
- package/dist/generators/generateSlug.d.ts +1 -15
- package/dist/generators/generateSlug.d.ts.map +1 -1
- package/dist/generators/generateSlug.js +2 -16
- package/dist/index.d.ts +10 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -7
- package/dist/parsers/parseToCharacters.d.ts +17 -0
- package/dist/parsers/parseToCharacters.d.ts.map +1 -0
- package/dist/parsers/parseToCharacters.js +13 -0
- package/dist/services/calculateCardInstallment.d.ts +5 -31
- package/dist/services/calculateCardInstallment.d.ts.map +1 -1
- package/dist/services/calculateCardInstallment.js +11 -52
- package/dist/services/maskSensitiveData.d.ts +1 -24
- package/dist/services/maskSensitiveData.d.ts.map +1 -1
- package/dist/services/maskSensitiveData.js +2 -24
- package/dist/services/range.d.ts +4 -0
- package/dist/services/range.d.ts.map +1 -0
- package/dist/services/range.js +9 -0
- package/dist/services/truncateLargeFields.d.ts +1 -30
- package/dist/services/truncateLargeFields.d.ts.map +1 -1
- package/dist/services/truncateLargeFields.js +6 -34
- package/dist/validations/regex.d.ts +15 -0
- package/dist/validations/regex.d.ts.map +1 -0
- package/dist/validations/regex.js +25 -0
- package/dist/validations/validateCPF.d.ts +3 -0
- package/dist/validations/validateCPF.d.ts.map +1 -0
- package/dist/validations/validateCPF.js +36 -0
- package/dist/validations/validateDate.d.ts +6 -27
- package/dist/validations/validateDate.d.ts.map +1 -1
- package/dist/validations/validateDate.js +6 -32
- package/dist/validations/validatePhone.d.ts +1 -27
- package/dist/validations/validatePhone.d.ts.map +1 -1
- package/dist/validations/validatePhone.js +2 -27
- package/package.json +2 -4
- package/src/formats/formatBrazilianDateHour.ts +17 -0
- package/src/formats/formatBrazilianDateToDate.ts +13 -0
- package/src/formats/formatDateHour.ts +15 -0
- package/src/formats/formatJsonObject.ts +26 -68
- package/src/formats/formatJsonString.ts +4 -40
- package/src/formats/formatToBRL.ts +10 -0
- package/src/formats/formatToCNPJ.ts +10 -0
- package/src/formats/formatToCPF.ts +10 -0
- package/src/formats/formatToCep.ts +7 -35
- package/src/formats/formatToCpfCnpj.ts +7 -31
- package/src/formats/formatToEllipsis.ts +3 -23
- package/src/formats/formatToHiddenDigits.ts +7 -75
- package/src/formats/formatToPhone.ts +6 -156
- package/src/generators/generateColorByString.ts +4 -18
- package/src/generators/generateId.ts +5 -36
- package/src/generators/generateSlug.ts +2 -17
- package/src/index.ts +15 -7
- package/src/parsers/parseToCharacters.ts +34 -0
- package/src/services/calculateCardInstallment.ts +12 -57
- package/src/services/maskSensitiveData.ts +4 -29
- package/src/services/range.ts +15 -0
- package/src/services/truncateLargeFields.ts +6 -40
- package/src/validations/regex.ts +41 -0
- package/src/validations/validateCPF.ts +38 -0
- package/src/validations/validateDate.ts +11 -33
- package/src/validations/validatePhone.ts +2 -29
- package/tsconfig.json +1 -1
- package/dist/formats/formatDate.d.ts +0 -43
- package/dist/formats/formatDate.d.ts.map +0 -1
- package/dist/formats/formatDate.js +0 -77
- package/dist/formats/formatToCnpj.d.ts +0 -30
- package/dist/formats/formatToCnpj.d.ts.map +0 -1
- package/dist/formats/formatToCnpj.js +0 -35
- package/dist/formats/formatToCpf.d.ts +0 -30
- package/dist/formats/formatToCpf.d.ts.map +0 -1
- package/dist/formats/formatToCpf.js +0 -35
- package/dist/formats/formatToCurrency.d.ts +0 -29
- package/dist/formats/formatToCurrency.d.ts.map +0 -1
- package/dist/formats/formatToCurrency.js +0 -41
- package/dist/regex/index.d.ts +0 -6
- package/dist/regex/index.d.ts.map +0 -1
- package/dist/regex/index.js +0 -4
- package/dist/services/removeCurrencySymbols.d.ts +0 -20
- package/dist/services/removeCurrencySymbols.d.ts.map +0 -1
- package/dist/services/removeCurrencySymbols.js +0 -23
- package/dist/services/removeNonNumeric.d.ts +0 -15
- package/dist/services/removeNonNumeric.d.ts.map +0 -1
- package/dist/services/removeNonNumeric.js +0 -16
- package/dist/validations/validateCpf.d.ts +0 -24
- package/dist/validations/validateCpf.d.ts.map +0 -1
- package/dist/validations/validateCpf.js +0 -56
- package/src/formats/formatDate.ts +0 -97
- package/src/formats/formatToCnpj.ts +0 -39
- package/src/formats/formatToCpf.ts +0 -39
- package/src/formats/formatToCurrency.ts +0 -53
- package/src/regex/index.ts +0 -8
- package/src/services/removeCurrencySymbols.ts +0 -25
- package/src/services/removeNonNumeric.ts +0 -18
- package/src/validations/validateCpf.ts +0 -64
- package/vitest.config.ts +0 -5
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
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 };
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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 };
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
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,33 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Formats a JSON object into a human-readable string with proper indentation.
|
|
4
|
-
*
|
|
5
|
-
* @param obj - The JSON object or value to format. It can be an object, array, string, or primitive value.
|
|
6
|
-
* @param indentLevel - The current level of indentation to apply. This is used recursively to format nested structures.
|
|
7
|
-
* @returns A formatted string representation of the JSON object.
|
|
8
|
-
*
|
|
9
|
-
* @remarks
|
|
10
|
-
* - If the input is an object, it will be formatted with keys and values properly indented.
|
|
11
|
-
* - If the input is an array, each element will be formatted and indented on a new line.
|
|
12
|
-
* - If the input is a string that can be parsed as JSON, it will attempt to parse and format it.
|
|
13
|
-
* - Primitive values (e.g., numbers, booleans, null) will be converted to their string representation.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* const obj = { name: "John", age: 30, hobbies: ["reading", "gaming"] };
|
|
18
|
-
* const formatted = formatJsonObject(obj, 0);
|
|
19
|
-
* console.log(formatted);
|
|
20
|
-
* // Output:
|
|
21
|
-
* // {
|
|
22
|
-
* // "name": "John",
|
|
23
|
-
* // "age": 30,
|
|
24
|
-
* // "hobbies": [
|
|
25
|
-
* // "reading",
|
|
26
|
-
* // "gaming"
|
|
27
|
-
* // ]
|
|
28
|
-
* // }
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
declare const formatJsonObject: FormatJsonObjectFunction;
|
|
1
|
+
declare function formatJsonObject(obj: any, indentLevel: number): string;
|
|
32
2
|
export { formatJsonObject };
|
|
33
3
|
//# sourceMappingURL=formatJsonObject.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatJsonObject.d.ts","sourceRoot":"","sources":["../../src/formats/formatJsonObject.ts"],"names":[],"mappings":"AAAA,
|
|
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,76 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
* Formats a JSON object into a human-readable string with proper indentation.
|
|
3
|
-
*
|
|
4
|
-
* @param obj - The JSON object or value to format. It can be an object, array, string, or primitive value.
|
|
5
|
-
* @param indentLevel - The current level of indentation to apply. This is used recursively to format nested structures.
|
|
6
|
-
* @returns A formatted string representation of the JSON object.
|
|
7
|
-
*
|
|
8
|
-
* @remarks
|
|
9
|
-
* - If the input is an object, it will be formatted with keys and values properly indented.
|
|
10
|
-
* - If the input is an array, each element will be formatted and indented on a new line.
|
|
11
|
-
* - If the input is a string that can be parsed as JSON, it will attempt to parse and format it.
|
|
12
|
-
* - Primitive values (e.g., numbers, booleans, null) will be converted to their string representation.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* const obj = { name: "John", age: 30, hobbies: ["reading", "gaming"] };
|
|
17
|
-
* const formatted = formatJsonObject(obj, 0);
|
|
18
|
-
* console.log(formatted);
|
|
19
|
-
* // Output:
|
|
20
|
-
* // {
|
|
21
|
-
* // "name": "John",
|
|
22
|
-
* // "age": 30,
|
|
23
|
-
* // "hobbies": [
|
|
24
|
-
* // "reading",
|
|
25
|
-
* // "gaming"
|
|
26
|
-
* // ]
|
|
27
|
-
* // }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
const formatJsonObject = (obj, indentLevel) => {
|
|
1
|
+
function formatJsonObject(obj, indentLevel) {
|
|
31
2
|
const indent = " ".repeat(indentLevel);
|
|
32
3
|
let formattedString = "";
|
|
33
4
|
if (typeof obj === "object" && obj !== null) {
|
|
34
5
|
if (Array.isArray(obj)) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
formattedString +=
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
formattedString += ",";
|
|
46
|
-
}
|
|
47
|
-
formattedString += "\n";
|
|
48
|
-
});
|
|
49
|
-
formattedString += indent + "]";
|
|
50
|
-
}
|
|
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 + "]";
|
|
51
16
|
}
|
|
52
17
|
else {
|
|
18
|
+
formattedString += "{\n";
|
|
53
19
|
const keys = Object.keys(obj);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (index < keys.length - 1) {
|
|
68
|
-
formattedString += ",";
|
|
69
|
-
}
|
|
70
|
-
formattedString += "\n";
|
|
71
|
-
});
|
|
72
|
-
formattedString += indent + "}";
|
|
73
|
-
}
|
|
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 + "}";
|
|
74
33
|
}
|
|
75
34
|
}
|
|
76
35
|
else if (typeof obj === "string") {
|
|
@@ -86,5 +45,5 @@ const formatJsonObject = (obj, indentLevel) => {
|
|
|
86
45
|
formattedString += obj;
|
|
87
46
|
}
|
|
88
47
|
return formattedString;
|
|
89
|
-
}
|
|
48
|
+
}
|
|
90
49
|
export { formatJsonObject };
|
|
@@ -1,39 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Formats a JSON string into a more readable format.
|
|
4
|
-
*
|
|
5
|
-
* This function attempts to parse the provided JSON string into a JavaScript object,
|
|
6
|
-
* and then formats it using the `formatJsonObject` function. If the input string
|
|
7
|
-
* is not a valid JSON, it logs an error to the console and returns an empty string.
|
|
8
|
-
*
|
|
9
|
-
* @param jsonString - The JSON string to be formatted.
|
|
10
|
-
* @returns A formatted JSON string, or an empty string if the input is invalid.
|
|
11
|
-
*
|
|
12
|
-
* @throws Will log an error to the console if the input is not a valid JSON string.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* const jsonString = '{"name":"John","age":30,"hobbies":["reading","gaming"]}';
|
|
17
|
-
* const formatted = formatJsonString(jsonString);
|
|
18
|
-
* console.log(formatted);
|
|
19
|
-
* // Output:
|
|
20
|
-
* // {
|
|
21
|
-
* // "name": "John",
|
|
22
|
-
* // "age": 30,
|
|
23
|
-
* // "hobbies": [
|
|
24
|
-
* // "reading",
|
|
25
|
-
* // "gaming"
|
|
26
|
-
* // ]
|
|
27
|
-
* // }
|
|
28
|
-
|
|
29
|
-
* const invalidJsonString = '{"name":"John", "age":30,';
|
|
30
|
-
* const formatted = formatJsonString(invalidJsonString);
|
|
31
|
-
* console.log(formatted);
|
|
32
|
-
* // Output:
|
|
33
|
-
* // (Logs "Invalid JSON string: ..." to the console)
|
|
34
|
-
* // ""
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
declare const formatJsonString: FormatJsonStringFunction;
|
|
1
|
+
declare function formatJsonString(jsonString: string): string;
|
|
38
2
|
export { formatJsonString };
|
|
39
3
|
//# sourceMappingURL=formatJsonString.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatJsonString.d.ts","sourceRoot":"","sources":["../../src/formats/formatJsonString.ts"],"names":[],"mappings":"
|
|
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,46 +1,12 @@
|
|
|
1
1
|
import { formatJsonObject } from "./formatJsonObject";
|
|
2
|
-
|
|
3
|
-
* Formats a JSON string into a more readable format.
|
|
4
|
-
*
|
|
5
|
-
* This function attempts to parse the provided JSON string into a JavaScript object,
|
|
6
|
-
* and then formats it using the `formatJsonObject` function. If the input string
|
|
7
|
-
* is not a valid JSON, it logs an error to the console and returns an empty string.
|
|
8
|
-
*
|
|
9
|
-
* @param jsonString - The JSON string to be formatted.
|
|
10
|
-
* @returns A formatted JSON string, or an empty string if the input is invalid.
|
|
11
|
-
*
|
|
12
|
-
* @throws Will log an error to the console if the input is not a valid JSON string.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* const jsonString = '{"name":"John","age":30,"hobbies":["reading","gaming"]}';
|
|
17
|
-
* const formatted = formatJsonString(jsonString);
|
|
18
|
-
* console.log(formatted);
|
|
19
|
-
* // Output:
|
|
20
|
-
* // {
|
|
21
|
-
* // "name": "John",
|
|
22
|
-
* // "age": 30,
|
|
23
|
-
* // "hobbies": [
|
|
24
|
-
* // "reading",
|
|
25
|
-
* // "gaming"
|
|
26
|
-
* // ]
|
|
27
|
-
* // }
|
|
28
|
-
|
|
29
|
-
* const invalidJsonString = '{"name":"John", "age":30,';
|
|
30
|
-
* const formatted = formatJsonString(invalidJsonString);
|
|
31
|
-
* console.log(formatted);
|
|
32
|
-
* // Output:
|
|
33
|
-
* // (Logs "Invalid JSON string: ..." to the console)
|
|
34
|
-
* // ""
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
const formatJsonString = (jsonString) => {
|
|
2
|
+
function formatJsonString(jsonString) {
|
|
38
3
|
try {
|
|
39
4
|
const jsonObject = JSON.parse(jsonString);
|
|
40
5
|
return formatJsonObject(jsonObject, 0);
|
|
41
6
|
}
|
|
42
7
|
catch (error) {
|
|
43
|
-
|
|
8
|
+
console.error("Invalid JSON string:", error);
|
|
9
|
+
return "";
|
|
44
10
|
}
|
|
45
|
-
}
|
|
11
|
+
}
|
|
46
12
|
export { formatJsonString };
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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 };
|
|
@@ -0,0 +1 @@
|
|
|
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,29 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Formats a given string into a Brazilian postal code (CEP) format.
|
|
4
|
-
*
|
|
5
|
-
* The function removes all non-numeric characters from the input string
|
|
6
|
-
* and attempts to format it as a CEP in the pattern `XXXXX-XXX`.
|
|
7
|
-
* If the input does not match the expected format, an error is thrown.
|
|
8
|
-
*
|
|
9
|
-
* @param value - The input string to be formatted as a CEP.
|
|
10
|
-
* @returns The formatted CEP string in the pattern `XXXXX-XXX`.
|
|
11
|
-
* @throws {Error} If the input does not match the expected CEP format.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import { formatToCep } from "./formatToCep";
|
|
16
|
-
*
|
|
17
|
-
* const formattedCep = formatToCep("12345678");
|
|
18
|
-
* console.log(formattedCep); // Output: "12345-678"
|
|
19
|
-
*
|
|
20
|
-
* try {
|
|
21
|
-
* formatToCep("1234");
|
|
22
|
-
* } catch (error) {
|
|
23
|
-
* console.error(error.message); // Output: "Invalid CEP format"
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
declare const formatToCep: FormatToCepFunction;
|
|
1
|
+
declare function formatToCep(value: string): string;
|
|
28
2
|
export { formatToCep };
|
|
29
3
|
//# sourceMappingURL=formatToCep.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatToCep.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCep.ts"],"names":[],"mappings":"AAAA,
|
|
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,34 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Formats a given string into a Brazilian postal code (CEP) format.
|
|
4
|
-
*
|
|
5
|
-
* The function removes all non-numeric characters from the input string
|
|
6
|
-
* and attempts to format it as a CEP in the pattern `XXXXX-XXX`.
|
|
7
|
-
* If the input does not match the expected format, an error is thrown.
|
|
8
|
-
*
|
|
9
|
-
* @param value - The input string to be formatted as a CEP.
|
|
10
|
-
* @returns The formatted CEP string in the pattern `XXXXX-XXX`.
|
|
11
|
-
* @throws {Error} If the input does not match the expected CEP format.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import { formatToCep } from "./formatToCep";
|
|
16
|
-
*
|
|
17
|
-
* const formattedCep = formatToCep("12345678");
|
|
18
|
-
* console.log(formattedCep); // Output: "12345-678"
|
|
19
|
-
*
|
|
20
|
-
* try {
|
|
21
|
-
* formatToCep("1234");
|
|
22
|
-
* } catch (error) {
|
|
23
|
-
* console.error(error.message); // Output: "Invalid CEP format"
|
|
24
|
-
* }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
const formatToCep = (value) => {
|
|
28
|
-
const cleaned = removeNonNumeric(value);
|
|
1
|
+
function formatToCep(value) {
|
|
2
|
+
const cleaned = value.replace(/\D/g, "");
|
|
29
3
|
const match = cleaned.match(/^(\d{5})(\d{3})$/);
|
|
30
|
-
if (match)
|
|
4
|
+
if (match) {
|
|
31
5
|
return `${match[1]}-${match[2]}`;
|
|
32
|
-
|
|
33
|
-
|
|
6
|
+
}
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
34
9
|
export { formatToCep };
|
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Formats a given string value into either a CPF or CNPJ format based on its length.
|
|
4
|
-
*
|
|
5
|
-
* - If the input contains 11 numeric characters, it is formatted as a CPF.
|
|
6
|
-
* - If the input contains 14 numeric characters, it is formatted as a CNPJ.
|
|
7
|
-
* - Throws an error if the input length is neither 11 nor 14 after removing non-numeric characters.
|
|
8
|
-
*
|
|
9
|
-
* @param value - The string value to be formatted. It may contain non-numeric characters, which will be removed.
|
|
10
|
-
* @returns The formatted CPF or CNPJ string.
|
|
11
|
-
* @throws {Error} If the input does not have a valid CPF or CNPJ length.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* formatToCpfCnpj("123.456.789-09"); // Returns "123.456.789-09" (CPF format)
|
|
16
|
-
* formatToCpfCnpj("12.345.678/0001-95"); // Returns "12.345.678/0001-95" (CNPJ format)
|
|
17
|
-
* formatToCpfCnpj("12345678909"); // Returns "123.456.789-09" (CPF format)
|
|
18
|
-
* formatToCpfCnpj("12345678000195"); // Returns "12.345.678/0001-95" (CNPJ format)
|
|
19
|
-
* formatToCpfCnpj("123"); // Throws an error: "Invalid CPF or CNPJ length"
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
declare const formatToCpfCnpj: FormatToCpfCnpjFunction;
|
|
1
|
+
declare function formatToCpfCnpj(value: string): string;
|
|
23
2
|
export { formatToCpfCnpj };
|
|
24
3
|
//# sourceMappingURL=formatToCpfCnpj.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatToCpfCnpj.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCpfCnpj.ts"],"names":[],"mappings":"
|
|
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,33 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
* Formats a given string value into either a CPF or CNPJ format based on its length.
|
|
5
|
-
*
|
|
6
|
-
* - If the input contains 11 numeric characters, it is formatted as a CPF.
|
|
7
|
-
* - If the input contains 14 numeric characters, it is formatted as a CNPJ.
|
|
8
|
-
* - Throws an error if the input length is neither 11 nor 14 after removing non-numeric characters.
|
|
9
|
-
*
|
|
10
|
-
* @param value - The string value to be formatted. It may contain non-numeric characters, which will be removed.
|
|
11
|
-
* @returns The formatted CPF or CNPJ string.
|
|
12
|
-
* @throws {Error} If the input does not have a valid CPF or CNPJ length.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* formatToCpfCnpj("123.456.789-09"); // Returns "123.456.789-09" (CPF format)
|
|
17
|
-
* formatToCpfCnpj("12.345.678/0001-95"); // Returns "12.345.678/0001-95" (CNPJ format)
|
|
18
|
-
* formatToCpfCnpj("12345678909"); // Returns "123.456.789-09" (CPF format)
|
|
19
|
-
* formatToCpfCnpj("12345678000195"); // Returns "12.345.678/0001-95" (CNPJ format)
|
|
20
|
-
* formatToCpfCnpj("123"); // Throws an error: "Invalid CPF or CNPJ length"
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
const formatToCpfCnpj = (value) => {
|
|
1
|
+
import { formatToCNPJ } from "./formatToCNPJ";
|
|
2
|
+
import { formatToCPF } from "./formatToCPF";
|
|
3
|
+
function formatToCpfCnpj(value) {
|
|
24
4
|
const cleaned = value.replace(/\D/g, "");
|
|
25
5
|
if (cleaned.length === 11) {
|
|
26
|
-
return
|
|
6
|
+
return formatToCPF(cleaned);
|
|
27
7
|
}
|
|
28
8
|
else if (cleaned.length === 14) {
|
|
29
|
-
return
|
|
9
|
+
return formatToCNPJ(cleaned);
|
|
30
10
|
}
|
|
31
|
-
|
|
32
|
-
}
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
33
13
|
export { formatToCpfCnpj };
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Truncates a given text to a specified maximum length and appends an ellipsis ("...")
|
|
4
|
-
* if the text exceeds the maximum length.
|
|
5
|
-
*
|
|
6
|
-
* @param text - The input string to be truncated.
|
|
7
|
-
* @param maxLength - The maximum allowed length of the string before truncation.
|
|
8
|
-
* @returns The truncated string with an ellipsis if the input exceeds the maximum length,
|
|
9
|
-
* or the original string if it does not.
|
|
10
|
-
* @example
|
|
11
|
-
* const result = formatToEllipsis("Hello, world!", 5);
|
|
12
|
-
* console.log(result); // Output: "Hello..."
|
|
13
|
-
*/
|
|
14
|
-
declare const formatToEllipsis: FormatToEllipsisFunction;
|
|
1
|
+
declare function formatToEllipsis(text: string, size?: number): string;
|
|
15
2
|
export { formatToEllipsis };
|
|
16
3
|
//# sourceMappingURL=formatToEllipsis.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatToEllipsis.d.ts","sourceRoot":"","sources":["../../src/formats/formatToEllipsis.ts"],"names":[],"mappings":"AAAA,
|
|
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,21 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* @param text - The input string to be truncated.
|
|
6
|
-
* @param maxLength - The maximum allowed length of the string before truncation.
|
|
7
|
-
* @returns The truncated string with an ellipsis if the input exceeds the maximum length,
|
|
8
|
-
* or the original string if it does not.
|
|
9
|
-
* @example
|
|
10
|
-
* const result = formatToEllipsis("Hello, world!", 5);
|
|
11
|
-
* console.log(result); // Output: "Hello..."
|
|
12
|
-
*/
|
|
13
|
-
const formatToEllipsis = (text, maxLength) => {
|
|
14
|
-
if (text.length > maxLength) {
|
|
15
|
-
let trimmedText = text.substring(0, maxLength).trimEnd();
|
|
16
|
-
trimmedText = trimmedText.replace(/[.,!?;:]$/, "");
|
|
17
|
-
return `${trimmedText}...`;
|
|
18
|
-
}
|
|
19
|
-
return text;
|
|
20
|
-
};
|
|
1
|
+
function formatToEllipsis(text, size = 40) {
|
|
2
|
+
return text.length > size ? `${text.substring(0, size)}...` : text;
|
|
3
|
+
}
|
|
21
4
|
export { formatToEllipsis };
|
|
@@ -1,32 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
* Formats a string by hiding specific digits within a given range.
|
|
4
|
-
*
|
|
5
|
-
* This function takes a string input and replaces digits within a specified range
|
|
6
|
-
* with a hiding character (e.g., "*"). Non-digit characters remain unchanged.
|
|
7
|
-
*
|
|
8
|
-
* @param value - The input string to be formatted.
|
|
9
|
-
* @param options - Configuration options for formatting.
|
|
10
|
-
* @param options.range - The range of digits to hide. It can be:
|
|
11
|
-
* - A single number (e.g., `3`), which hides the first `n` digits if positive,
|
|
12
|
-
* or the last `n` digits if negative.
|
|
13
|
-
* - A tuple `[start, end]` specifying the range of digits to hide (inclusive).
|
|
14
|
-
* - Defaults to `3`, hiding the first three digits.
|
|
15
|
-
* @param options.hider - The character used to hide digits. Defaults to `"*"`.
|
|
16
|
-
*
|
|
17
|
-
* @returns The formatted string with specified digits hidden.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { formatToHiddenDigits } from "./formatToHiddenDigits";
|
|
22
|
-
*
|
|
23
|
-
* formatToHiddenDigits("123-456-7890", { range: 3 });
|
|
24
|
-
* // Output: "***-456-7890"
|
|
25
|
-
*
|
|
26
|
-
* formatToHiddenDigits("123-456-7890", { range: [4, 6], hider: "#" });
|
|
27
|
-
* // Output: "123-###-7890"
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
declare const formatToHiddenDigits: FormatToHiddenDigitsFunction;
|
|
1
|
+
import type { FormatToHiddenDigitsOptions } from "@arkyn/types";
|
|
2
|
+
declare const formatToHiddenDigits: (value: string, options?: FormatToHiddenDigitsOptions) => string;
|
|
31
3
|
export { formatToHiddenDigits };
|
|
32
4
|
//# sourceMappingURL=formatToHiddenDigits.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatToHiddenDigits.d.ts","sourceRoot":"","sources":["../../src/formats/formatToHiddenDigits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
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"}
|