@arkyn/shared 3.0.1-beta.13 → 3.0.1-beta.130
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/README.md +452 -67
- package/dist/bundle.js +3749 -0
- package/dist/bundle.umd.cjs +10 -0
- package/dist/formats/formatDate.d.ts +44 -16
- package/dist/formats/formatDate.d.ts.map +1 -1
- package/dist/formats/formatDate.js +61 -26
- package/dist/formats/formatJsonObject.d.ts +6 -7
- package/dist/formats/formatJsonObject.d.ts.map +1 -1
- package/dist/formats/formatJsonObject.js +17 -17
- package/dist/formats/formatToCep.d.ts +5 -12
- package/dist/formats/formatToCep.d.ts.map +1 -1
- package/dist/formats/formatToCep.js +11 -16
- package/dist/formats/formatToCnpj.d.ts +3 -13
- package/dist/formats/formatToCnpj.d.ts.map +1 -1
- package/dist/formats/formatToCnpj.js +9 -17
- package/dist/formats/formatToCpf.d.ts +5 -13
- package/dist/formats/formatToCpf.d.ts.map +1 -1
- package/dist/formats/formatToCpf.js +11 -17
- package/dist/formats/formatToCurrency.d.ts +18 -14
- package/dist/formats/formatToCurrency.d.ts.map +1 -1
- package/dist/formats/formatToCurrency.js +21 -14
- package/dist/formats/formatToEllipsis.d.ts +8 -5
- package/dist/formats/formatToEllipsis.d.ts.map +1 -1
- package/dist/formats/formatToEllipsis.js +21 -7
- package/dist/formats/formatToHiddenDigits.d.ts +16 -16
- package/dist/formats/formatToHiddenDigits.d.ts.map +1 -1
- package/dist/formats/formatToHiddenDigits.js +19 -19
- package/dist/formats/formatToPhone.d.ts +11 -22
- package/dist/formats/formatToPhone.d.ts.map +1 -1
- package/dist/formats/formatToPhone.js +31 -118
- package/dist/generators/generateColorByString.d.ts +7 -4
- package/dist/generators/generateColorByString.d.ts.map +1 -1
- package/dist/generators/generateColorByString.js +10 -6
- package/dist/generators/generateId.d.ts +3 -3
- package/dist/generators/generateSlug.d.ts +10 -3
- package/dist/generators/generateSlug.d.ts.map +1 -1
- package/dist/generators/generateSlug.js +11 -4
- package/dist/index.d.ts +11 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -17
- package/dist/{services/truncateLargeFields.d.ts → parsers/parseLargeFields.d.ts} +9 -11
- package/dist/parsers/parseLargeFields.d.ts.map +1 -0
- package/dist/{services/truncateLargeFields.js → parsers/parseLargeFields.js} +12 -13
- package/dist/parsers/parseSensitiveData.d.ts +23 -0
- package/dist/parsers/parseSensitiveData.d.ts.map +1 -0
- package/dist/{services/maskSensitiveData.js → parsers/parseSensitiveData.js} +10 -12
- package/dist/parsers/parseToDate.d.ts +41 -0
- package/dist/parsers/parseToDate.d.ts.map +1 -0
- package/dist/parsers/parseToDate.js +67 -0
- package/dist/services/validateDateService.d.ts +85 -0
- package/dist/services/validateDateService.d.ts.map +1 -0
- package/dist/services/validateDateService.js +132 -0
- package/dist/{services → utilities}/calculateCardInstallment.d.ts +16 -18
- package/dist/utilities/calculateCardInstallment.d.ts.map +1 -0
- package/dist/{services → utilities}/calculateCardInstallment.js +12 -15
- package/dist/utilities/ensureQuotes.d.ts +21 -0
- package/dist/utilities/ensureQuotes.d.ts.map +1 -0
- package/dist/{services → utilities}/ensureQuotes.js +12 -4
- package/dist/utilities/findCountryMask.d.ts +45 -0
- package/dist/utilities/findCountryMask.d.ts.map +1 -0
- package/dist/utilities/findCountryMask.js +73 -0
- package/dist/utilities/isHtml.d.ts +22 -0
- package/dist/utilities/isHtml.d.ts.map +1 -0
- package/dist/utilities/isHtml.js +24 -0
- package/dist/{services → utilities}/removeCurrencySymbols.d.ts +6 -4
- package/dist/utilities/removeCurrencySymbols.d.ts.map +1 -0
- package/dist/{services → utilities}/removeCurrencySymbols.js +8 -7
- package/dist/utilities/removeNonNumeric.d.ts +16 -0
- package/dist/utilities/removeNonNumeric.d.ts.map +1 -0
- package/dist/utilities/removeNonNumeric.js +17 -0
- package/dist/utilities/stripHtmlTags.d.ts +19 -0
- package/dist/utilities/stripHtmlTags.d.ts.map +1 -0
- package/dist/utilities/stripHtmlTags.js +24 -0
- package/package.json +25 -6
- package/dist/formats/formatToCpfCnpj.d.ts +0 -24
- package/dist/formats/formatToCpfCnpj.d.ts.map +0 -1
- package/dist/formats/formatToCpfCnpj.js +0 -33
- package/dist/formats/formatToDate.d.ts +0 -32
- package/dist/formats/formatToDate.d.ts.map +0 -1
- package/dist/formats/formatToDate.js +0 -50
- package/dist/services/calculateCardInstallment.d.ts.map +0 -1
- package/dist/services/ensureQuotes.d.ts +0 -14
- package/dist/services/ensureQuotes.d.ts.map +0 -1
- package/dist/services/maskSensitiveData.d.ts +0 -26
- package/dist/services/maskSensitiveData.d.ts.map +0 -1
- package/dist/services/removeCurrencySymbols.d.ts.map +0 -1
- package/dist/services/removeNonNumeric.d.ts +0 -16
- package/dist/services/removeNonNumeric.d.ts.map +0 -1
- package/dist/services/removeNonNumeric.js +0 -16
- package/dist/services/stripHtmlTags.d.ts +0 -16
- package/dist/services/stripHtmlTags.d.ts.map +0 -1
- package/dist/services/stripHtmlTags.js +0 -16
- package/dist/services/truncateLargeFields.d.ts.map +0 -1
- package/dist/validations/validateCep.d.ts +0 -24
- package/dist/validations/validateCep.d.ts.map +0 -1
- package/dist/validations/validateCep.js +0 -33
- package/dist/validations/validateCnpj.d.ts +0 -22
- package/dist/validations/validateCnpj.d.ts.map +0 -1
- package/dist/validations/validateCnpj.js +0 -52
- package/dist/validations/validateCpf.d.ts +0 -24
- package/dist/validations/validateCpf.d.ts.map +0 -1
- package/dist/validations/validateCpf.js +0 -54
- package/dist/validations/validateDate.d.ts +0 -34
- package/dist/validations/validateDate.d.ts.map +0 -1
- package/dist/validations/validateDate.js +0 -73
- package/dist/validations/validatePassword.d.ts +0 -21
- package/dist/validations/validatePassword.d.ts.map +0 -1
- package/dist/validations/validatePassword.js +0 -34
- package/dist/validations/validatePhone.d.ts +0 -29
- package/dist/validations/validatePhone.d.ts.map +0 -1
- package/dist/validations/validatePhone.js +0 -44
- package/dist/validations/validateRg.d.ts +0 -22
- package/dist/validations/validateRg.d.ts.map +0 -1
- package/dist/validations/validateRg.js +0 -31
- package/src/formats/formatDate.ts +0 -92
- package/src/formats/formatJsonObject.ts +0 -90
- package/src/formats/formatJsonString.ts +0 -50
- package/src/formats/formatToCapitalizeFirstWordLetter.ts +0 -46
- package/src/formats/formatToCep.ts +0 -39
- package/src/formats/formatToCnpj.ts +0 -40
- package/src/formats/formatToCpf.ts +0 -40
- package/src/formats/formatToCpfCnpj.ts +0 -38
- package/src/formats/formatToCurrency.ts +0 -63
- package/src/formats/formatToDate.ts +0 -70
- package/src/formats/formatToEllipsis.ts +0 -25
- package/src/formats/formatToHiddenDigits.ts +0 -92
- package/src/formats/formatToPhone.ts +0 -170
- package/src/generators/generateColorByString.ts +0 -33
- package/src/generators/generateId.ts +0 -61
- package/src/generators/generateSlug.ts +0 -31
- package/src/index.ts +0 -37
- package/src/services/calculateCardInstallment.ts +0 -73
- package/src/services/ensureQuotes.ts +0 -25
- package/src/services/maskSensitiveData.ts +0 -68
- package/src/services/removeCurrencySymbols.ts +0 -29
- package/src/services/removeNonNumeric.ts +0 -20
- package/src/services/stripHtmlTags.ts +0 -20
- package/src/services/truncateLargeFields.ts +0 -69
- package/src/validations/validateCep.ts +0 -41
- package/src/validations/validateCnpj.ts +0 -65
- package/src/validations/validateCpf.ts +0 -62
- package/src/validations/validateDate.ts +0 -86
- package/src/validations/validatePassword.ts +0 -41
- package/src/validations/validatePhone.ts +0 -50
- package/src/validations/validateRg.ts +0 -37
- package/tsconfig.json +0 -20
- package/vitest.config.ts +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatDate.d.ts","sourceRoot":"","sources":["../../src/formats/formatDate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatDate.d.ts","sourceRoot":"","sources":["../../src/formats/formatDate.ts"],"names":[],"mappings":"AAqBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,iBAAS,UAAU,CACjB,CAAC,IAAI,EAAE,IAAiB,CAAC,EAAE,MAAM,EAAE,EACnC,WAAW,EAAE,eAAe,GAAG,SAAS,GAAG,WAAW,EACtD,YAAY,EAAE,MAAM,EACpB,QAAQ,GAAE,MAAU,GACnB,MAAM,CAkCR;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -1,45 +1,79 @@
|
|
|
1
|
+
import { ValidateDateService } from "../services/validateDateService";
|
|
1
2
|
function formatDateString(date, format) {
|
|
2
3
|
const pad = (num) => num.toString().padStart(2, "0");
|
|
3
4
|
const replacements = {
|
|
4
|
-
YYYY: date.
|
|
5
|
-
YY: date.
|
|
6
|
-
MM: pad(date.
|
|
7
|
-
DD: pad(date.
|
|
8
|
-
hh: pad(date.
|
|
9
|
-
mm: pad(date.
|
|
10
|
-
ss: pad(date.
|
|
5
|
+
YYYY: date.getUTCFullYear().toString(),
|
|
6
|
+
YY: date.getUTCFullYear().toString().slice(-2),
|
|
7
|
+
MM: pad(date.getUTCMonth() + 1),
|
|
8
|
+
DD: pad(date.getUTCDate()),
|
|
9
|
+
hh: pad(date.getUTCHours()),
|
|
10
|
+
mm: pad(date.getUTCMinutes()),
|
|
11
|
+
ss: pad(date.getUTCSeconds()),
|
|
11
12
|
};
|
|
12
13
|
return format.replace(/YYYY|YY|MM|DD|hh|mm|ss/g, (match) => replacements[match]);
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Formats a date and time string based on the provided input and output formats.
|
|
16
17
|
*
|
|
17
|
-
* @
|
|
18
|
+
* @remarks
|
|
19
|
+
* **Note:** This function works with UTC+0 by default. The returned formatted string is not automatically converted to the machine's local timezone.
|
|
20
|
+
* To adjust the timezone, you must manually specify the `timezone` parameter (e.g., -3 for UTC-3).
|
|
21
|
+
*
|
|
22
|
+
* @param {string[]} dateTime - An array containing the date and optional time.
|
|
18
23
|
* - The first element is the date string.
|
|
19
24
|
* - The second element is the time string (default is "00:00:00").
|
|
20
25
|
* @param {"brazilianDate" | "isoDate" | "timestamp"} inputFormat - The format of the input date.
|
|
21
|
-
* - "brazilianDate": Expects the date in "DD/MM/YYYY" format.
|
|
22
|
-
* - "isoDate": Expects the date in "
|
|
23
|
-
* - "timestamp": Expects the date in "YYYY
|
|
26
|
+
* - "brazilianDate": Expects the date in "DD/MM/YYYY" or "D/M/YYYY" format.
|
|
27
|
+
* - "isoDate": Expects the date in "MM-DD-YYYY" or "M-D-YYYY" format.
|
|
28
|
+
* - "timestamp": Expects the date in "YYYY-MM-DD" or "YYYY-M-D" format.
|
|
24
29
|
* @param {string} outputFormat - The desired output format for the date.
|
|
25
30
|
* - Use placeholders like "YYYY", "MM", "DD", "hh", "mm", "ss" to define the format.
|
|
26
31
|
* @param {number} [timezone=0] - The timezone offset in hours to apply to the date.
|
|
27
32
|
* - Defaults to 0 (UTC).
|
|
33
|
+
*
|
|
28
34
|
* @returns {string} The formatted date string based on the output format.
|
|
29
|
-
* @throws {Error} If the input format is invalid.
|
|
30
|
-
* @throws {Error} If the date is invalid.
|
|
31
35
|
*
|
|
36
|
+
* @throws {Error} If the date parts are invalid (e.g., month not between 1-12).
|
|
37
|
+
* @throws {Error} If the date created is invalid.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* Format a Brazilian date to ISO format
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const formattedDate = formatDate(
|
|
43
|
+
* ["25/12/2023", "15:30:00"],
|
|
44
|
+
* "brazilianDate",
|
|
45
|
+
* "YYYY-MM-DD hh:mm",
|
|
46
|
+
* );
|
|
47
|
+
*
|
|
48
|
+
* console.log(formattedDate); // Output: "2023-12-25 15:30"
|
|
49
|
+
* ```
|
|
32
50
|
* @example
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
51
|
+
* Format an ISO date to a custom format with timezone adjustment
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const formattedDate = formatDate(
|
|
54
|
+
* ["2023-12-25", "15:30:00"],
|
|
55
|
+
* "isoDate",
|
|
56
|
+
* "DD/MM/YYYY hh:mm",
|
|
57
|
+
* -3,
|
|
58
|
+
* );
|
|
36
59
|
*
|
|
60
|
+
* console.log(formattedDate); // Output: "25/12/2023 12:30"
|
|
61
|
+
* ```
|
|
37
62
|
* @example
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
63
|
+
* Format a timestamp date to a custom format
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const formattedDate = formatDate(
|
|
66
|
+
* ["2023-12-25", "15:30:00"],
|
|
67
|
+
* "timestamp",
|
|
68
|
+
* "MM-DD-YYYY hh:mm:ss",
|
|
69
|
+
* );
|
|
70
|
+
*
|
|
71
|
+
* console.log(formattedDate); // Output: "12-25-2023 15:30:00"
|
|
72
|
+
* ```
|
|
41
73
|
*/
|
|
42
|
-
|
|
74
|
+
function formatDate([date, time = "00:00:00"], inputFormat, outputFormat, timezone = 0) {
|
|
75
|
+
const validateDateService = new ValidateDateService();
|
|
76
|
+
validateDateService.validateInputFormat(inputFormat);
|
|
43
77
|
const dateParts = date.split(/[-/]/).map(Number);
|
|
44
78
|
const timeParts = time.split(".")[0].split(":").map(Number);
|
|
45
79
|
let day, month, year;
|
|
@@ -47,20 +81,21 @@ const formatDate = ([date, time = "00:00:00"], inputFormat, outputFormat, timezo
|
|
|
47
81
|
switch (inputFormat) {
|
|
48
82
|
case "brazilianDate":
|
|
49
83
|
[day, month, year] = dateParts;
|
|
84
|
+
validateDateService.validateDateParts(year, month, day);
|
|
50
85
|
break;
|
|
51
86
|
case "isoDate":
|
|
52
|
-
[
|
|
87
|
+
[month, day, year] = dateParts;
|
|
88
|
+
validateDateService.validateDateParts(year, month, day);
|
|
53
89
|
break;
|
|
54
90
|
case "timestamp":
|
|
55
|
-
[year, month, day] = dateParts
|
|
91
|
+
[year, month, day] = dateParts;
|
|
92
|
+
validateDateService.validateDateParts(year, month, day);
|
|
56
93
|
break;
|
|
57
|
-
default:
|
|
58
|
-
throw new Error("Invalid input format");
|
|
59
94
|
}
|
|
60
|
-
const formattedDate = new Date(year, month - 1, day, hours, minutes, seconds);
|
|
95
|
+
const formattedDate = new Date(Date.UTC(year, month - 1, day, hours, minutes, seconds));
|
|
61
96
|
if (isNaN(formattedDate.getTime()))
|
|
62
97
|
throw new Error("Invalid date");
|
|
63
98
|
formattedDate.setUTCHours(formattedDate.getUTCHours() + timezone);
|
|
64
99
|
return formatDateString(formattedDate, outputFormat);
|
|
65
|
-
}
|
|
100
|
+
}
|
|
66
101
|
export { formatDate };
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
type FormatJsonObjectFunction = (jsonString: any, identLevel: number) => string;
|
|
2
1
|
/**
|
|
3
2
|
* Formats a JSON object into a human-readable string with proper indentation.
|
|
4
3
|
*
|
|
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
4
|
* - If the input is an object, it will be formatted with keys and values properly indented.
|
|
11
5
|
* - If the input is an array, each element will be formatted and indented on a new line.
|
|
12
6
|
* - If the input is a string that can be parsed as JSON, it will attempt to parse and format it.
|
|
13
7
|
* - Primitive values (e.g., numbers, booleans, null) will be converted to their string representation.
|
|
14
8
|
*
|
|
9
|
+
* @param {any} json - The JSON object or value to format. It can be an object, array, string, or primitive value.
|
|
10
|
+
* @param {number} indentLevel - The current level of indentation to apply. This is used recursively to format nested structures.
|
|
11
|
+
*
|
|
12
|
+
* @returns {string} A formatted string representation of the JSON object.
|
|
13
|
+
*
|
|
15
14
|
* @example
|
|
16
15
|
* ```typescript
|
|
17
16
|
* const obj = { name: "John", age: 30, hobbies: ["reading", "gaming"] };
|
|
@@ -28,6 +27,6 @@ type FormatJsonObjectFunction = (jsonString: any, identLevel: number) => string;
|
|
|
28
27
|
* // }
|
|
29
28
|
* ```
|
|
30
29
|
*/
|
|
31
|
-
declare const formatJsonObject:
|
|
30
|
+
declare const formatJsonObject: (json: any, indentLevel: number) => string;
|
|
32
31
|
export { formatJsonObject };
|
|
33
32
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,QAAA,MAAM,gBAAgB,GAAI,MAAM,GAAG,EAAE,aAAa,MAAM,KAAG,MAuD1D,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Formats a JSON object into a human-readable string with proper indentation.
|
|
3
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
4
|
* - If the input is an object, it will be formatted with keys and values properly indented.
|
|
10
5
|
* - If the input is an array, each element will be formatted and indented on a new line.
|
|
11
6
|
* - If the input is a string that can be parsed as JSON, it will attempt to parse and format it.
|
|
12
7
|
* - Primitive values (e.g., numbers, booleans, null) will be converted to their string representation.
|
|
13
8
|
*
|
|
9
|
+
* @param {any} json - The JSON object or value to format. It can be an object, array, string, or primitive value.
|
|
10
|
+
* @param {number} indentLevel - The current level of indentation to apply. This is used recursively to format nested structures.
|
|
11
|
+
*
|
|
12
|
+
* @returns {string} A formatted string representation of the JSON object.
|
|
13
|
+
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
16
|
* const obj = { name: "John", age: 30, hobbies: ["reading", "gaming"] };
|
|
@@ -27,21 +27,21 @@
|
|
|
27
27
|
* // }
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
const formatJsonObject = (
|
|
30
|
+
const formatJsonObject = (json, indentLevel) => {
|
|
31
31
|
const indent = " ".repeat(indentLevel);
|
|
32
32
|
let formattedString = "";
|
|
33
|
-
if (typeof
|
|
34
|
-
if (Array.isArray(
|
|
35
|
-
if (
|
|
33
|
+
if (typeof json === "object" && json !== null) {
|
|
34
|
+
if (Array.isArray(json)) {
|
|
35
|
+
if (json.length === 0) {
|
|
36
36
|
// Caso especial para arrays vazios
|
|
37
37
|
formattedString += "[]";
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
40
|
formattedString += "[\n";
|
|
41
|
-
|
|
41
|
+
json.forEach((item, index) => {
|
|
42
42
|
formattedString +=
|
|
43
43
|
indent + " " + formatJsonObject(item, indentLevel + 1);
|
|
44
|
-
if (index <
|
|
44
|
+
if (index < json.length - 1) {
|
|
45
45
|
formattedString += ",";
|
|
46
46
|
}
|
|
47
47
|
formattedString += "\n";
|
|
@@ -50,7 +50,7 @@ const formatJsonObject = (obj, indentLevel) => {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
const keys = Object.keys(
|
|
53
|
+
const keys = Object.keys(json);
|
|
54
54
|
if (keys.length === 0) {
|
|
55
55
|
// Caso especial para objetos vazios
|
|
56
56
|
formattedString += "{}";
|
|
@@ -63,7 +63,7 @@ const formatJsonObject = (obj, indentLevel) => {
|
|
|
63
63
|
' "' +
|
|
64
64
|
key +
|
|
65
65
|
'": ' +
|
|
66
|
-
formatJsonObject(
|
|
66
|
+
formatJsonObject(json[key], indentLevel + 1);
|
|
67
67
|
if (index < keys.length - 1) {
|
|
68
68
|
formattedString += ",";
|
|
69
69
|
}
|
|
@@ -73,17 +73,17 @@ const formatJsonObject = (obj, indentLevel) => {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
else if (typeof
|
|
76
|
+
else if (typeof json === "string") {
|
|
77
77
|
try {
|
|
78
|
-
const parsedObj = JSON.parse(
|
|
78
|
+
const parsedObj = JSON.parse(json);
|
|
79
79
|
formattedString += formatJsonObject(parsedObj, indentLevel);
|
|
80
80
|
}
|
|
81
81
|
catch {
|
|
82
|
-
formattedString += '"' +
|
|
82
|
+
formattedString += '"' + json + '"';
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
|
-
formattedString +=
|
|
86
|
+
formattedString += json;
|
|
87
87
|
}
|
|
88
88
|
return formattedString;
|
|
89
89
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
type FormatToCepFunction = (value: string) => string;
|
|
2
1
|
/**
|
|
3
2
|
* Formats a given string into a Brazilian postal code (CEP) format.
|
|
4
3
|
*
|
|
@@ -6,24 +5,18 @@ type FormatToCepFunction = (value: string) => string;
|
|
|
6
5
|
* and attempts to format it as a CEP in the pattern `XXXXX-XXX`.
|
|
7
6
|
* If the input does not match the expected format, an error is thrown.
|
|
8
7
|
*
|
|
9
|
-
* @param value - The input string to be formatted as a CEP.
|
|
10
|
-
*
|
|
8
|
+
* @param {string} value - The input string to be formatted as a CEP, the string must contain 8 numeric digits; special characters will be ignored.
|
|
9
|
+
*
|
|
10
|
+
* @returns {string} The formatted CEP string in the pattern `XXXXX-XXX`.
|
|
11
|
+
*
|
|
11
12
|
* @throws {Error} If the input does not match the expected CEP format.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* ```typescript
|
|
15
|
-
* import { formatToCep } from "./formatToCep";
|
|
16
|
-
*
|
|
17
16
|
* const formattedCep = formatToCep("12345678");
|
|
18
17
|
* 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
18
|
* ```
|
|
26
19
|
*/
|
|
27
|
-
declare
|
|
20
|
+
declare function formatToCep(value: string): string;
|
|
28
21
|
export { formatToCep };
|
|
29
22
|
//# sourceMappingURL=formatToCep.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatToCep.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCep.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"formatToCep.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCep.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,iBAAS,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ1C;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { removeNonNumeric } from "../
|
|
1
|
+
import { removeNonNumeric } from "../utilities/removeNonNumeric";
|
|
2
2
|
/**
|
|
3
3
|
* Formats a given string into a Brazilian postal code (CEP) format.
|
|
4
4
|
*
|
|
@@ -6,29 +6,24 @@ import { removeNonNumeric } from "../services/removeNonNumeric";
|
|
|
6
6
|
* and attempts to format it as a CEP in the pattern `XXXXX-XXX`.
|
|
7
7
|
* If the input does not match the expected format, an error is thrown.
|
|
8
8
|
*
|
|
9
|
-
* @param value - The input string to be formatted as a CEP.
|
|
10
|
-
*
|
|
9
|
+
* @param {string} value - The input string to be formatted as a CEP, the string must contain 8 numeric digits; special characters will be ignored.
|
|
10
|
+
*
|
|
11
|
+
* @returns {string} The formatted CEP string in the pattern `XXXXX-XXX`.
|
|
12
|
+
*
|
|
11
13
|
* @throws {Error} If the input does not match the expected CEP format.
|
|
12
14
|
*
|
|
13
15
|
* @example
|
|
14
16
|
* ```typescript
|
|
15
|
-
* import { formatToCep } from "./formatToCep";
|
|
16
|
-
*
|
|
17
17
|
* const formattedCep = formatToCep("12345678");
|
|
18
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
19
|
* ```
|
|
26
20
|
*/
|
|
27
|
-
|
|
21
|
+
function formatToCep(value) {
|
|
28
22
|
const cleaned = removeNonNumeric(value);
|
|
29
23
|
const match = cleaned.match(/^(\d{5})(\d{3})$/);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
24
|
+
const errorMessage = `CEP must be contain 8 numeric digits: ${value}`;
|
|
25
|
+
if (!match)
|
|
26
|
+
throw new Error(errorMessage);
|
|
27
|
+
return `${match[1]}-${match[2]}`;
|
|
28
|
+
}
|
|
34
29
|
export { formatToCep };
|
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
type FormatToCnpjFunction = (value: string) => string;
|
|
2
1
|
/**
|
|
3
2
|
* Formats a given string or number into a CNPJ (Cadastro Nacional da Pessoa Jurídica) format.
|
|
4
3
|
*
|
|
5
4
|
* The CNPJ format is: `XX.XXX.XXX/XXXX-XX`, where `X` represents a digit.
|
|
6
5
|
*
|
|
7
|
-
* @param value - The input
|
|
8
|
-
* Non-numeric characters will be removed before formatting.
|
|
6
|
+
* @param {string} value - The input string to be formatted as a CNPJ, the string must contain 14 numeric digits; special characters will be ignored.
|
|
9
7
|
*
|
|
10
|
-
* @returns
|
|
8
|
+
* @returns {string} The formatted CNPJ string in the pattern `XX.XXX.XXX/XXXX-XX`.
|
|
11
9
|
*
|
|
12
10
|
* @throws {Error} Throws an error if the input does not contain exactly 14 numeric digits.
|
|
13
11
|
*
|
|
14
12
|
* @example
|
|
15
13
|
* ```typescript
|
|
16
|
-
* import { formatToCnpj } from "./formatToCNPJ";
|
|
17
|
-
*
|
|
18
14
|
* const formattedCnpj = formatToCnpj("12345678000195");
|
|
19
15
|
* console.log(formattedCnpj); // Output: "12.345.678/0001-95"
|
|
20
|
-
*
|
|
21
|
-
* try {
|
|
22
|
-
* formatToCnpj("12345");
|
|
23
|
-
* } catch (error) {
|
|
24
|
-
* console.error(error.message); // Output: "Invalid CNPJ length"
|
|
25
|
-
* }
|
|
26
16
|
* ```
|
|
27
17
|
*/
|
|
28
|
-
declare
|
|
18
|
+
declare function formatToCnpj(value: string): string;
|
|
29
19
|
export { formatToCnpj };
|
|
30
20
|
//# sourceMappingURL=formatToCnpj.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatToCnpj.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCnpj.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"formatToCnpj.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCnpj.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AAEH,iBAAS,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ3C;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,35 +1,27 @@
|
|
|
1
|
-
import { removeNonNumeric } from "../
|
|
1
|
+
import { removeNonNumeric } from "../utilities/removeNonNumeric";
|
|
2
2
|
/**
|
|
3
3
|
* Formats a given string or number into a CNPJ (Cadastro Nacional da Pessoa Jurídica) format.
|
|
4
4
|
*
|
|
5
5
|
* The CNPJ format is: `XX.XXX.XXX/XXXX-XX`, where `X` represents a digit.
|
|
6
6
|
*
|
|
7
|
-
* @param value - The input
|
|
8
|
-
* Non-numeric characters will be removed before formatting.
|
|
7
|
+
* @param {string} value - The input string to be formatted as a CNPJ, the string must contain 14 numeric digits; special characters will be ignored.
|
|
9
8
|
*
|
|
10
|
-
* @returns
|
|
9
|
+
* @returns {string} The formatted CNPJ string in the pattern `XX.XXX.XXX/XXXX-XX`.
|
|
11
10
|
*
|
|
12
11
|
* @throws {Error} Throws an error if the input does not contain exactly 14 numeric digits.
|
|
13
12
|
*
|
|
14
13
|
* @example
|
|
15
14
|
* ```typescript
|
|
16
|
-
* import { formatToCnpj } from "./formatToCNPJ";
|
|
17
|
-
*
|
|
18
15
|
* const formattedCnpj = formatToCnpj("12345678000195");
|
|
19
16
|
* console.log(formattedCnpj); // Output: "12.345.678/0001-95"
|
|
20
|
-
*
|
|
21
|
-
* try {
|
|
22
|
-
* formatToCnpj("12345");
|
|
23
|
-
* } catch (error) {
|
|
24
|
-
* console.error(error.message); // Output: "Invalid CNPJ length"
|
|
25
|
-
* }
|
|
26
17
|
* ```
|
|
27
18
|
*/
|
|
28
|
-
|
|
19
|
+
function formatToCnpj(value) {
|
|
29
20
|
const cleaned = removeNonNumeric(value);
|
|
30
21
|
const match = cleaned.match(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
22
|
+
const errorMessage = `CNPJ must be contain 14 numeric digits: ${value}`;
|
|
23
|
+
if (!match)
|
|
24
|
+
throw new Error(errorMessage);
|
|
25
|
+
return `${match[1]}.${match[2]}.${match[3]}/${match[4]}-${match[5]}`;
|
|
26
|
+
}
|
|
35
27
|
export { formatToCnpj };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
type FormatToCpfFunction = (value: string) => string;
|
|
2
1
|
/**
|
|
3
2
|
* Formats a given string into a CPF (Cadastro de Pessoas Físicas) format.
|
|
4
3
|
*
|
|
@@ -6,25 +5,18 @@ type FormatToCpfFunction = (value: string) => string;
|
|
|
6
5
|
* This function ensures the input is cleaned of non-numeric characters and
|
|
7
6
|
* then formats it into the standard CPF format: `XXX.XXX.XXX-XX`.
|
|
8
7
|
*
|
|
9
|
-
* @param value -
|
|
10
|
-
*
|
|
8
|
+
* @param {string} value - The input string to be formatted as a CPF, the string must contain 11 numeric digits; special characters will be ignored.
|
|
9
|
+
*
|
|
10
|
+
* @returns {string} The formatted CPF string.
|
|
11
|
+
*
|
|
11
12
|
* @throws {Error} If the input string does not match the expected CPF format.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* ```typescript
|
|
15
|
-
* import { formatToCpf } from "./formatToCPF";
|
|
16
|
-
*
|
|
17
16
|
* const formattedCpf = formatToCpf("12345678909");
|
|
18
17
|
* console.log(formattedCpf); // Output: "123.456.789-09"
|
|
19
|
-
|
|
20
|
-
* try {
|
|
21
|
-
* const formattedCpf = formatToCpf("12345");
|
|
22
|
-
* } catch (error) {
|
|
23
|
-
* console.error(error.message); // Output: "Invalid CPF format"
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
18
|
* ```
|
|
27
19
|
*/
|
|
28
|
-
declare
|
|
20
|
+
declare function formatToCpf(value: string): string;
|
|
29
21
|
export { formatToCpf };
|
|
30
22
|
//# sourceMappingURL=formatToCpf.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatToCpf.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCpf.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"formatToCpf.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCpf.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,iBAAS,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ1C;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { removeNonNumeric } from "../
|
|
1
|
+
import { removeNonNumeric } from "../utilities/removeNonNumeric";
|
|
2
2
|
/**
|
|
3
3
|
* Formats a given string into a CPF (Cadastro de Pessoas Físicas) format.
|
|
4
4
|
*
|
|
@@ -6,30 +6,24 @@ import { removeNonNumeric } from "../services/removeNonNumeric";
|
|
|
6
6
|
* This function ensures the input is cleaned of non-numeric characters and
|
|
7
7
|
* then formats it into the standard CPF format: `XXX.XXX.XXX-XX`.
|
|
8
8
|
*
|
|
9
|
-
* @param value -
|
|
10
|
-
*
|
|
9
|
+
* @param {string} value - The input string to be formatted as a CPF, the string must contain 11 numeric digits; special characters will be ignored.
|
|
10
|
+
*
|
|
11
|
+
* @returns {string} The formatted CPF string.
|
|
12
|
+
*
|
|
11
13
|
* @throws {Error} If the input string does not match the expected CPF format.
|
|
12
14
|
*
|
|
13
15
|
* @example
|
|
14
16
|
* ```typescript
|
|
15
|
-
* import { formatToCpf } from "./formatToCPF";
|
|
16
|
-
*
|
|
17
17
|
* const formattedCpf = formatToCpf("12345678909");
|
|
18
18
|
* console.log(formattedCpf); // Output: "123.456.789-09"
|
|
19
|
-
|
|
20
|
-
* try {
|
|
21
|
-
* const formattedCpf = formatToCpf("12345");
|
|
22
|
-
* } catch (error) {
|
|
23
|
-
* console.error(error.message); // Output: "Invalid CPF format"
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
19
|
* ```
|
|
27
20
|
*/
|
|
28
|
-
|
|
21
|
+
function formatToCpf(value) {
|
|
29
22
|
const cleaned = removeNonNumeric(value);
|
|
30
23
|
const match = cleaned.match(/^(\d{3})(\d{3})(\d{3})(\d{2})$/);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
24
|
+
const errorMessage = `CPF must be contain 11 numeric digits: ${value}`;
|
|
25
|
+
if (!match)
|
|
26
|
+
throw new Error(errorMessage);
|
|
27
|
+
return `${match[1]}.${match[2]}.${match[3]}-${match[4]}`;
|
|
28
|
+
}
|
|
35
29
|
export { formatToCpf };
|
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
import { countryCurrencies } from "@arkyn/templates";
|
|
2
2
|
type Currencies = keyof typeof countryCurrencies;
|
|
3
|
-
type Config = {
|
|
4
|
-
showPrefix?: boolean;
|
|
5
|
-
};
|
|
6
|
-
type FormatToCurrency = (value: number, currency: Currencies, config?: Config) => string;
|
|
7
3
|
/**
|
|
8
4
|
* Formats a numeric value into a currency string based on the specified currency and configuration.
|
|
9
5
|
*
|
|
10
|
-
* @param value - The numeric value to be formatted.
|
|
11
|
-
* @param currency - The currency code used to determine the formatting style.
|
|
12
|
-
* @param config - Optional configuration object.
|
|
13
|
-
* @param config.showPrefix - Determines whether the currency symbol/prefix should be included in the formatted string. Defaults to `true`.
|
|
6
|
+
* @param {number} value - The numeric value to be formatted.
|
|
7
|
+
* @param {Currencies} currency - The currency code used to determine the formatting style.
|
|
8
|
+
* @param {object} [config] - Optional configuration object.
|
|
9
|
+
* @param {boolean} [config.showPrefix=true] - Determines whether the currency symbol/prefix should be included in the formatted string. Defaults to `true`.
|
|
14
10
|
*
|
|
15
|
-
* @returns A formatted currency string. If `config.showPrefix` is `false`, the currency symbol is removed.
|
|
11
|
+
* @returns {string} A formatted currency string. If `config.showPrefix` is `false`, the currency symbol is removed.
|
|
16
12
|
*
|
|
17
|
-
* @example
|
|
13
|
+
* @example Format a value in USD with prefix
|
|
18
14
|
* ```typescript
|
|
19
15
|
* const formatted = formatToCurrency(1234.56, "USD", { showPrefix: true });
|
|
20
16
|
* console.log(formatted); // "$1,234.56"
|
|
21
|
-
*
|
|
17
|
+
* ```
|
|
18
|
+
* @example Format a value in USD without prefix
|
|
19
|
+
* ```typescript
|
|
22
20
|
* const withoutPrefix = formatToCurrency(1234.56, "USD", { showPrefix: false });
|
|
23
21
|
* console.log(withoutPrefix); // "1,234.56"
|
|
24
|
-
*
|
|
22
|
+
* ```
|
|
23
|
+
* @example Format a value in BRL with prefix
|
|
24
|
+
* ```typescript
|
|
25
25
|
* const formattedBRL = formatToCurrency(1234.56, "BRL", { showPrefix: true });
|
|
26
26
|
* console.log(formattedBRL); // "R$ 1.234,56"
|
|
27
|
-
*
|
|
27
|
+
* ```
|
|
28
|
+
* @example Format a value in BRL without prefix
|
|
29
|
+
* ```typescript
|
|
28
30
|
* const withoutPrefixBRL = formatToCurrency(1234.56, "BRL", { showPrefix: false });
|
|
29
31
|
* console.log(withoutPrefixBRL); // "1.234,56"
|
|
30
32
|
* ```
|
|
31
33
|
*/
|
|
32
|
-
declare
|
|
34
|
+
declare function formatToCurrency(value: number, currency: Currencies, config?: {
|
|
35
|
+
showPrefix?: boolean;
|
|
36
|
+
}): string;
|
|
33
37
|
export { formatToCurrency };
|
|
34
38
|
//# sourceMappingURL=formatToCurrency.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatToCurrency.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,KAAK,UAAU,GAAG,MAAM,OAAO,iBAAiB,CAAC;AAEjD
|
|
1
|
+
{"version":3,"file":"formatToCurrency.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,KAAK,UAAU,GAAG,MAAM,OAAO,iBAAiB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,iBAAS,gBAAgB,CACvB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,UAAU,EACpB,MAAM,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,GAChC,MAAM,CAiBR;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,41 +1,48 @@
|
|
|
1
1
|
import { countryCurrencies } from "@arkyn/templates";
|
|
2
|
-
import { removeCurrencySymbols } from "../
|
|
2
|
+
import { removeCurrencySymbols } from "../utilities/removeCurrencySymbols";
|
|
3
3
|
/**
|
|
4
4
|
* Formats a numeric value into a currency string based on the specified currency and configuration.
|
|
5
5
|
*
|
|
6
|
-
* @param value - The numeric value to be formatted.
|
|
7
|
-
* @param currency - The currency code used to determine the formatting style.
|
|
8
|
-
* @param config - Optional configuration object.
|
|
9
|
-
* @param config.showPrefix - Determines whether the currency symbol/prefix should be included in the formatted string. Defaults to `true`.
|
|
6
|
+
* @param {number} value - The numeric value to be formatted.
|
|
7
|
+
* @param {Currencies} currency - The currency code used to determine the formatting style.
|
|
8
|
+
* @param {object} [config] - Optional configuration object.
|
|
9
|
+
* @param {boolean} [config.showPrefix=true] - Determines whether the currency symbol/prefix should be included in the formatted string. Defaults to `true`.
|
|
10
10
|
*
|
|
11
|
-
* @returns A formatted currency string. If `config.showPrefix` is `false`, the currency symbol is removed.
|
|
11
|
+
* @returns {string} A formatted currency string. If `config.showPrefix` is `false`, the currency symbol is removed.
|
|
12
12
|
*
|
|
13
|
-
* @example
|
|
13
|
+
* @example Format a value in USD with prefix
|
|
14
14
|
* ```typescript
|
|
15
15
|
* const formatted = formatToCurrency(1234.56, "USD", { showPrefix: true });
|
|
16
16
|
* console.log(formatted); // "$1,234.56"
|
|
17
|
-
*
|
|
17
|
+
* ```
|
|
18
|
+
* @example Format a value in USD without prefix
|
|
19
|
+
* ```typescript
|
|
18
20
|
* const withoutPrefix = formatToCurrency(1234.56, "USD", { showPrefix: false });
|
|
19
21
|
* console.log(withoutPrefix); // "1,234.56"
|
|
20
|
-
*
|
|
22
|
+
* ```
|
|
23
|
+
* @example Format a value in BRL with prefix
|
|
24
|
+
* ```typescript
|
|
21
25
|
* const formattedBRL = formatToCurrency(1234.56, "BRL", { showPrefix: true });
|
|
22
26
|
* console.log(formattedBRL); // "R$ 1.234,56"
|
|
23
|
-
*
|
|
27
|
+
* ```
|
|
28
|
+
* @example Format a value in BRL without prefix
|
|
29
|
+
* ```typescript
|
|
24
30
|
* const withoutPrefixBRL = formatToCurrency(1234.56, "BRL", { showPrefix: false });
|
|
25
31
|
* console.log(withoutPrefixBRL); // "1.234,56"
|
|
26
32
|
* ```
|
|
27
33
|
*/
|
|
28
|
-
|
|
29
|
-
if (!countryCurrencies[currency]) {
|
|
34
|
+
function formatToCurrency(value, currency, config) {
|
|
35
|
+
if (!countryCurrencies?.[currency]) {
|
|
30
36
|
throw new Error("Unsupported currency code");
|
|
31
37
|
}
|
|
38
|
+
const showPrefix = config?.showPrefix ?? true;
|
|
32
39
|
const { countryCurrency, countryLanguage } = countryCurrencies[currency];
|
|
33
40
|
const format = new Intl.NumberFormat(countryLanguage, {
|
|
34
41
|
style: "currency",
|
|
35
42
|
currency: countryCurrency,
|
|
36
43
|
}).format(value);
|
|
37
|
-
return
|
|
44
|
+
return showPrefix
|
|
38
45
|
? format.replace(/\s/g, " ")
|
|
39
46
|
: removeCurrencySymbols(format).replace(/\s/g, " ");
|
|
40
|
-
}
|
|
47
|
+
}
|
|
41
48
|
export { formatToCurrency };
|