@arkyn/shared 3.0.1-beta.143 → 3.0.1-beta.144
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/bundle.js +6 -36
- package/dist/formats/formatDate.d.ts +16 -52
- package/dist/formats/formatDate.d.ts.map +1 -1
- package/dist/formats/formatDate.js +15 -51
- package/dist/formats/formatJsonObject.d.ts +3 -4
- package/dist/formats/formatJsonObject.d.ts.map +1 -1
- package/dist/formats/formatJsonObject.js +3 -4
- package/dist/formats/formatJsonString.d.ts +5 -21
- package/dist/formats/formatJsonString.d.ts.map +1 -1
- package/dist/formats/formatJsonString.js +5 -21
- package/dist/formats/formatToCapitalizeFirstWordLetter.d.ts +5 -24
- package/dist/formats/formatToCapitalizeFirstWordLetter.d.ts.map +1 -1
- package/dist/formats/formatToCapitalizeFirstWordLetter.js +5 -24
- package/dist/formats/formatToCep.d.ts +2 -3
- package/dist/formats/formatToCep.d.ts.map +1 -1
- package/dist/formats/formatToCep.js +2 -3
- package/dist/formats/formatToCnpj.d.ts +2 -3
- package/dist/formats/formatToCnpj.d.ts.map +1 -1
- package/dist/formats/formatToCnpj.js +2 -3
- package/dist/formats/formatToCpf.d.ts +2 -3
- package/dist/formats/formatToCpf.d.ts.map +1 -1
- package/dist/formats/formatToCpf.js +2 -3
- package/dist/formats/formatToCurrency.d.ts +8 -25
- package/dist/formats/formatToCurrency.d.ts.map +1 -1
- package/dist/formats/formatToCurrency.js +8 -25
- package/dist/formats/formatToEllipsis.d.ts +3 -6
- package/dist/formats/formatToEllipsis.d.ts.map +1 -1
- package/dist/formats/formatToEllipsis.js +3 -6
- package/dist/formats/formatToHiddenDigits.d.ts +11 -22
- package/dist/formats/formatToHiddenDigits.d.ts.map +1 -1
- package/dist/formats/formatToHiddenDigits.js +11 -22
- package/dist/formats/formatToPhone.d.ts +2 -3
- package/dist/formats/formatToPhone.d.ts.map +1 -1
- package/dist/formats/formatToPhone.js +2 -3
- package/dist/generators/generateColorByString.d.ts +2 -3
- package/dist/generators/generateColorByString.d.ts.map +1 -1
- package/dist/generators/generateColorByString.js +2 -3
- package/dist/generators/generateId.d.ts +8 -19
- package/dist/generators/generateId.d.ts.map +1 -1
- package/dist/generators/generateSlug.d.ts +2 -3
- package/dist/generators/generateSlug.d.ts.map +1 -1
- package/dist/generators/generateSlug.js +2 -3
- package/dist/parsers/parseLargeFields.d.ts +3 -4
- package/dist/parsers/parseLargeFields.d.ts.map +1 -1
- package/dist/parsers/parseLargeFields.js +3 -4
- package/dist/parsers/parseSensitiveData.d.ts +3 -4
- package/dist/parsers/parseSensitiveData.d.ts.map +1 -1
- package/dist/parsers/parseSensitiveData.js +3 -4
- package/dist/parsers/parseToDate.d.ts +16 -32
- package/dist/parsers/parseToDate.d.ts.map +1 -1
- package/dist/parsers/parseToDate.js +16 -32
- package/dist/services/validateDateService.d.ts +13 -64
- package/dist/services/validateDateService.d.ts.map +1 -1
- package/dist/services/validateDateService.js +13 -64
- package/dist/utilities/calculateCardInstallment.d.ts +8 -21
- package/dist/utilities/calculateCardInstallment.d.ts.map +1 -1
- package/dist/utilities/calculateCardInstallment.js +8 -21
- package/dist/utilities/ensureQuotes.d.ts +2 -3
- package/dist/utilities/ensureQuotes.d.ts.map +1 -1
- package/dist/utilities/ensureQuotes.js +2 -3
- package/dist/utilities/findCountryMask.d.ts +10 -34
- package/dist/utilities/findCountryMask.d.ts.map +1 -1
- package/dist/utilities/findCountryMask.js +10 -34
- package/dist/utilities/isHtml.d.ts +2 -3
- package/dist/utilities/isHtml.d.ts.map +1 -1
- package/dist/utilities/isHtml.js +2 -3
- package/dist/utilities/removeCurrencySymbols.d.ts +2 -3
- package/dist/utilities/removeCurrencySymbols.d.ts.map +1 -1
- package/dist/utilities/removeCurrencySymbols.js +2 -3
- package/dist/utilities/removeNonNumeric.d.ts +2 -3
- package/dist/utilities/removeNonNumeric.d.ts.map +1 -1
- package/dist/utilities/removeNonNumeric.js +2 -3
- package/dist/utilities/stripHtmlTags.d.ts +2 -3
- package/dist/utilities/stripHtmlTags.d.ts.map +1 -1
- package/dist/utilities/stripHtmlTags.js +2 -3
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -27,24 +27,11 @@ class v1 {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Throws if year, month, or day are out of valid range or inconsistent with the calendar.
|
|
31
31
|
*
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
35
|
-
*
|
|
36
|
-
* @throws {Error} "Year should be four digits" - If the year doesn't have exactly 4 digits.
|
|
37
|
-
* @throws {Error} "Month should be between 1 and 12" - If the month is out of valid range.
|
|
38
|
-
* @throws {Error} "Day should be between 1 and 31" - If the day is out of valid range.
|
|
39
|
-
* @throws {Error} Month-specific error - If the day is invalid for the specific month.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* const service = new ValidateDateService();
|
|
44
|
-
* service.validateDateParts(2024, 2, 29); // Valid leap year date
|
|
45
|
-
* service.validateDateParts(2023, 2, 29); // Throws error - not a leap year
|
|
46
|
-
* service.validateDateParts(2024, 4, 31); // Throws error - April has only 30 days
|
|
47
|
-
* ```
|
|
32
|
+
* @param year - 4-digit year (1000–9999).
|
|
33
|
+
* @param month - Month number (1–12).
|
|
34
|
+
* @param day - Day number (1–31, validated against the specific month).
|
|
48
35
|
*/
|
|
49
36
|
validateDateParts(t, e, n) {
|
|
50
37
|
const r = {
|
|
@@ -58,26 +45,9 @@ class v1 {
|
|
|
58
45
|
this.validateDayInMonth(n, e, t);
|
|
59
46
|
}
|
|
60
47
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* @param {string} format - The format string to validate.
|
|
64
|
-
*
|
|
65
|
-
* @throws {Error} "Invalid input format: {format}" - If the format is not one of the valid formats.
|
|
66
|
-
*
|
|
67
|
-
* @remarks
|
|
68
|
-
* Valid formats are:
|
|
69
|
-
* - "brazilianDate": DD/MM/YYYY format
|
|
70
|
-
* - "isoDate": MM-DD-YYYY format
|
|
71
|
-
* - "timestamp": YYYY-MM-DD format
|
|
48
|
+
* Throws if `format` is not one of `"brazilianDate"`, `"isoDate"`, or `"timestamp"`.
|
|
72
49
|
*
|
|
73
|
-
* @
|
|
74
|
-
* ```typescript
|
|
75
|
-
* const service = new ValidateDateService();
|
|
76
|
-
* service.validateInputFormat("brazilianDate"); // Valid
|
|
77
|
-
* service.validateInputFormat("isoDate"); // Valid
|
|
78
|
-
* service.validateInputFormat("timestamp"); // Valid
|
|
79
|
-
* service.validateInputFormat("customFormat"); // Throws error
|
|
80
|
-
* ```
|
|
50
|
+
* @param format - The format string to check.
|
|
81
51
|
*/
|
|
82
52
|
validateInputFormat(t) {
|
|
83
53
|
if (!["brazilianDate", "isoDate", "timestamp"].includes(t))
|
|
@@ -1,60 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Formats a date and time string
|
|
2
|
+
* Formats a date (and optional time) string into a custom output format.
|
|
3
|
+
* All calculations are in UTC+0; use the `timezone` parameter to shift the result.
|
|
4
|
+
*
|
|
5
|
+
* @param date - Date string in the format determined by `inputFormat`.
|
|
6
|
+
* @param time - Optional time string `"HH:mm:ss"` (defaults to `"00:00:00"`).
|
|
7
|
+
* @param inputFormat - Parsing format:
|
|
8
|
+
* - `"brazilianDate"`: DD/MM/YYYY
|
|
9
|
+
* - `"isoDate"`: MM-DD-YYYY
|
|
10
|
+
* - `"timestamp"`: YYYY-MM-DD
|
|
11
|
+
* @param outputFormat - Output template using `YYYY`, `MM`, `DD`, `hh`, `mm`, `ss` placeholders.
|
|
12
|
+
* @param timezone - UTC offset in hours (e.g. `-3` for UTC-3). Defaults to `0`.
|
|
13
|
+
* @returns The formatted date string.
|
|
3
14
|
*
|
|
4
|
-
* @remarks
|
|
5
|
-
* **Note:** This function works with UTC+0 by default. The returned formatted string is not automatically converted to the machine's local timezone.
|
|
6
|
-
* To adjust the timezone, you must manually specify the `timezone` parameter (e.g., -3 for UTC-3).
|
|
7
|
-
*
|
|
8
|
-
* @param {string[]} dateTime - An array containing the date and optional time.
|
|
9
|
-
* - The first element is the date string.
|
|
10
|
-
* - The second element is the time string (default is "00:00:00").
|
|
11
|
-
* @param {"brazilianDate" | "isoDate" | "timestamp"} inputFormat - The format of the input date.
|
|
12
|
-
* - "brazilianDate": Expects the date in "DD/MM/YYYY" or "D/M/YYYY" format.
|
|
13
|
-
* - "isoDate": Expects the date in "MM-DD-YYYY" or "M-D-YYYY" format.
|
|
14
|
-
* - "timestamp": Expects the date in "YYYY-MM-DD" or "YYYY-M-D" format.
|
|
15
|
-
* @param {string} outputFormat - The desired output format for the date.
|
|
16
|
-
* - Use placeholders like "YYYY", "MM", "DD", "hh", "mm", "ss" to define the format.
|
|
17
|
-
* @param {number} [timezone=0] - The timezone offset in hours to apply to the date.
|
|
18
|
-
* - Defaults to 0 (UTC).
|
|
19
|
-
*
|
|
20
|
-
* @returns {string} The formatted date string based on the output format.
|
|
21
|
-
*
|
|
22
|
-
* @throws {Error} If the date parts are invalid (e.g., month not between 1-12).
|
|
23
|
-
* @throws {Error} If the date created is invalid.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* Format a Brazilian date to ISO format
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const formattedDate = formatDate(
|
|
29
|
-
* ["25/12/2023", "15:30:00"],
|
|
30
|
-
* "brazilianDate",
|
|
31
|
-
* "YYYY-MM-DD hh:mm",
|
|
32
|
-
* );
|
|
33
|
-
*
|
|
34
|
-
* console.log(formattedDate); // Output: "2023-12-25 15:30"
|
|
35
|
-
* ```
|
|
36
|
-
* @example
|
|
37
|
-
* Format an ISO date to a custom format with timezone adjustment
|
|
38
|
-
* ```typescript
|
|
39
|
-
* const formattedDate = formatDate(
|
|
40
|
-
* ["2023-12-25", "15:30:00"],
|
|
41
|
-
* "isoDate",
|
|
42
|
-
* "DD/MM/YYYY hh:mm",
|
|
43
|
-
* -3,
|
|
44
|
-
* );
|
|
45
|
-
*
|
|
46
|
-
* console.log(formattedDate); // Output: "25/12/2023 12:30"
|
|
47
|
-
* ```
|
|
48
15
|
* @example
|
|
49
|
-
* Format a timestamp date to a custom format
|
|
50
16
|
* ```typescript
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* "timestamp",
|
|
54
|
-
* "MM-DD-YYYY hh:mm:ss",
|
|
55
|
-
* );
|
|
17
|
+
* formatDate(["25/12/2023", "15:30:00"], "brazilianDate", "YYYY-MM-DD hh:mm");
|
|
18
|
+
* // "2023-12-25 15:30"
|
|
56
19
|
*
|
|
57
|
-
*
|
|
20
|
+
* formatDate(["2023-12-25", "15:30:00"], "timestamp", "DD/MM/YYYY hh:mm", -3);
|
|
21
|
+
* // "2023-12-25 12:30"
|
|
58
22
|
* ```
|
|
59
23
|
*/
|
|
60
24
|
declare function formatDate([date, time]: string[], inputFormat: "brazilianDate" | "isoDate" | "timestamp", outputFormat: string, timezone?: number): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatDate.d.ts","sourceRoot":"","sources":["../../src/formats/formatDate.ts"],"names":[],"mappings":"AAqBA
|
|
1
|
+
{"version":3,"file":"formatDate.d.ts","sourceRoot":"","sources":["../../src/formats/formatDate.ts"],"names":[],"mappings":"AAqBA;;;;;;;;;;;;;;;;;;;;;;GAsBG;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"}
|
|
@@ -13,62 +13,26 @@ function formatDateString(date, format) {
|
|
|
13
13
|
return format.replace(/YYYY|YY|MM|DD|hh|mm|ss/g, (match) => replacements[match]);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Formats a date and time string
|
|
16
|
+
* Formats a date (and optional time) string into a custom output format.
|
|
17
|
+
* All calculations are in UTC+0; use the `timezone` parameter to shift the result.
|
|
17
18
|
*
|
|
18
|
-
* @
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* @param date - Date string in the format determined by `inputFormat`.
|
|
20
|
+
* @param time - Optional time string `"HH:mm:ss"` (defaults to `"00:00:00"`).
|
|
21
|
+
* @param inputFormat - Parsing format:
|
|
22
|
+
* - `"brazilianDate"`: DD/MM/YYYY
|
|
23
|
+
* - `"isoDate"`: MM-DD-YYYY
|
|
24
|
+
* - `"timestamp"`: YYYY-MM-DD
|
|
25
|
+
* @param outputFormat - Output template using `YYYY`, `MM`, `DD`, `hh`, `mm`, `ss` placeholders.
|
|
26
|
+
* @param timezone - UTC offset in hours (e.g. `-3` for UTC-3). Defaults to `0`.
|
|
27
|
+
* @returns The formatted date string.
|
|
21
28
|
*
|
|
22
|
-
* @param {string[]} dateTime - An array containing the date and optional time.
|
|
23
|
-
* - The first element is the date string.
|
|
24
|
-
* - The second element is the time string (default is "00:00:00").
|
|
25
|
-
* @param {"brazilianDate" | "isoDate" | "timestamp"} inputFormat - The format of the input date.
|
|
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.
|
|
29
|
-
* @param {string} outputFormat - The desired output format for the date.
|
|
30
|
-
* - Use placeholders like "YYYY", "MM", "DD", "hh", "mm", "ss" to define the format.
|
|
31
|
-
* @param {number} [timezone=0] - The timezone offset in hours to apply to the date.
|
|
32
|
-
* - Defaults to 0 (UTC).
|
|
33
|
-
*
|
|
34
|
-
* @returns {string} The formatted date string based on the output format.
|
|
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
|
-
* ```
|
|
50
|
-
* @example
|
|
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
|
-
* );
|
|
59
|
-
*
|
|
60
|
-
* console.log(formattedDate); // Output: "25/12/2023 12:30"
|
|
61
|
-
* ```
|
|
62
29
|
* @example
|
|
63
|
-
* Format a timestamp date to a custom format
|
|
64
30
|
* ```typescript
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* "timestamp",
|
|
68
|
-
* "MM-DD-YYYY hh:mm:ss",
|
|
69
|
-
* );
|
|
31
|
+
* formatDate(["25/12/2023", "15:30:00"], "brazilianDate", "YYYY-MM-DD hh:mm");
|
|
32
|
+
* // "2023-12-25 15:30"
|
|
70
33
|
*
|
|
71
|
-
*
|
|
34
|
+
* formatDate(["2023-12-25", "15:30:00"], "timestamp", "DD/MM/YYYY hh:mm", -3);
|
|
35
|
+
* // "2023-12-25 12:30"
|
|
72
36
|
* ```
|
|
73
37
|
*/
|
|
74
38
|
function formatDate([date, time = "00:00:00"], inputFormat, outputFormat, timezone = 0) {
|
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
* - If the input is a string that can be parsed as JSON, it will attempt to parse and format it.
|
|
7
7
|
* - Primitive values (e.g., numbers, booleans, null) will be converted to their string representation.
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
*
|
|
12
|
-
* @returns {string} A formatted string representation of the JSON object.
|
|
9
|
+
* @param json - The value to format: object, array, string, or primitive.
|
|
10
|
+
* @param indentLevel - Current indentation depth (used recursively; pass `0` at the top level).
|
|
11
|
+
* @returns A pretty-printed string representation of the value.
|
|
13
12
|
*
|
|
14
13
|
* @example
|
|
15
14
|
* ```typescript
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,QAAA,MAAM,gBAAgB,GAAI,MAAM,GAAG,EAAE,aAAa,MAAM,KAAG,MAuD1D,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
* - If the input is a string that can be parsed as JSON, it will attempt to parse and format it.
|
|
7
7
|
* - Primitive values (e.g., numbers, booleans, null) will be converted to their string representation.
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
*
|
|
12
|
-
* @returns {string} A formatted string representation of the JSON object.
|
|
9
|
+
* @param json - The value to format: object, array, string, or primitive.
|
|
10
|
+
* @param indentLevel - Current indentation depth (used recursively; pass `0` at the top level).
|
|
11
|
+
* @returns A pretty-printed string representation of the value.
|
|
13
12
|
*
|
|
14
13
|
* @example
|
|
15
14
|
* ```typescript
|
|
@@ -1,37 +1,21 @@
|
|
|
1
1
|
type FormatJsonStringFunction = (jsonString: string) => string;
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Parses a JSON string and returns a human-readable pretty-printed representation.
|
|
4
|
+
* Throws if the input is not valid JSON.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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.
|
|
6
|
+
* @param jsonString - A valid JSON string to format.
|
|
7
|
+
* @returns A pretty-printed string representation.
|
|
13
8
|
*
|
|
14
9
|
* @example
|
|
15
10
|
* ```typescript
|
|
16
|
-
*
|
|
17
|
-
* const formatted = formatJsonString(jsonString);
|
|
18
|
-
* console.log(formatted);
|
|
19
|
-
* // Output:
|
|
11
|
+
* formatJsonString('{"name":"John","hobbies":["reading","gaming"]}');
|
|
20
12
|
* // {
|
|
21
13
|
* // "name": "John",
|
|
22
|
-
* // "age": 30,
|
|
23
14
|
* // "hobbies": [
|
|
24
15
|
* // "reading",
|
|
25
16
|
* // "gaming"
|
|
26
17
|
* // ]
|
|
27
18
|
* // }
|
|
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
19
|
* ```
|
|
36
20
|
*/
|
|
37
21
|
declare const formatJsonString: FormatJsonStringFunction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatJsonString.d.ts","sourceRoot":"","sources":["../../src/formats/formatJsonString.ts"],"names":[],"mappings":"AAEA,KAAK,wBAAwB,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,CAAC;AAE/D
|
|
1
|
+
{"version":3,"file":"formatJsonString.d.ts","sourceRoot":"","sources":["../../src/formats/formatJsonString.ts"],"names":[],"mappings":"AAEA,KAAK,wBAAwB,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,CAAC;AAE/D;;;;;;;;;;;;;;;;;;GAkBG;AAEH,QAAA,MAAM,gBAAgB,EAAE,wBAOvB,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,37 +1,21 @@
|
|
|
1
1
|
import { formatJsonObject } from "./formatJsonObject";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Parses a JSON string and returns a human-readable pretty-printed representation.
|
|
4
|
+
* Throws if the input is not valid JSON.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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.
|
|
6
|
+
* @param jsonString - A valid JSON string to format.
|
|
7
|
+
* @returns A pretty-printed string representation.
|
|
13
8
|
*
|
|
14
9
|
* @example
|
|
15
10
|
* ```typescript
|
|
16
|
-
*
|
|
17
|
-
* const formatted = formatJsonString(jsonString);
|
|
18
|
-
* console.log(formatted);
|
|
19
|
-
* // Output:
|
|
11
|
+
* formatJsonString('{"name":"John","hobbies":["reading","gaming"]}');
|
|
20
12
|
* // {
|
|
21
13
|
* // "name": "John",
|
|
22
|
-
* // "age": 30,
|
|
23
14
|
* // "hobbies": [
|
|
24
15
|
* // "reading",
|
|
25
16
|
* // "gaming"
|
|
26
17
|
* // ]
|
|
27
18
|
* // }
|
|
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
19
|
* ```
|
|
36
20
|
*/
|
|
37
21
|
const formatJsonString = (jsonString) => {
|
|
@@ -1,33 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* This function takes a string and capitalizes the first letter of each word
|
|
5
|
-
* while the remaining letters are lowercase.
|
|
2
|
+
* Capitalizes the first letter of each word and lowercases the rest.
|
|
6
3
|
* Words are separated by spaces.
|
|
7
4
|
*
|
|
8
|
-
* @param sentence - The
|
|
9
|
-
* @returns The sentence
|
|
5
|
+
* @param sentence - The string to format.
|
|
6
|
+
* @returns The sentence with every word title-cased.
|
|
10
7
|
*
|
|
11
8
|
* @example
|
|
12
9
|
* ```typescript
|
|
13
|
-
* //
|
|
14
|
-
* formatToCapitalizeFirstWordLetter("
|
|
15
|
-
* // Returns: "Hello World"
|
|
16
|
-
*
|
|
17
|
-
* // With capitalized text.
|
|
18
|
-
* formatToCapitalizeFirstWordLetter("HELLO WORLD");
|
|
19
|
-
* // Returns: "Hello World"
|
|
20
|
-
*
|
|
21
|
-
* // With mixed text.
|
|
22
|
-
* formatToCapitalizeFirstWordLetter("hELLO WoRLd"); * // Returns: "Hello World"
|
|
23
|
-
*
|
|
24
|
-
* // With multiple words
|
|
25
|
-
* formatToCapitalizeFirstWordLetter("javascript is an amazing language");
|
|
26
|
-
* // Returns: "Javascript is an amazing language"
|
|
27
|
-
*
|
|
28
|
-
* // Empty string
|
|
29
|
-
* formatToCapitalizeFirstWordLetter("");
|
|
30
|
-
* // Returns: ""
|
|
10
|
+
* formatToCapitalizeFirstWordLetter("hello world"); // "Hello World"
|
|
11
|
+
* formatToCapitalizeFirstWordLetter("HELLO WORLD"); // "Hello World"
|
|
31
12
|
* ```
|
|
32
13
|
*/
|
|
33
14
|
declare function formatToCapitalizeFirstWordLetter(sentence: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatToCapitalizeFirstWordLetter.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCapitalizeFirstWordLetter.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"formatToCapitalizeFirstWordLetter.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCapitalizeFirstWordLetter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,iBAAS,iCAAiC,CAAC,QAAQ,EAAE,MAAM,UAU1D;AAED,OAAO,EAAE,iCAAiC,EAAE,CAAC"}
|
|
@@ -1,33 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* This function takes a string and capitalizes the first letter of each word
|
|
5
|
-
* while the remaining letters are lowercase.
|
|
2
|
+
* Capitalizes the first letter of each word and lowercases the rest.
|
|
6
3
|
* Words are separated by spaces.
|
|
7
4
|
*
|
|
8
|
-
* @param sentence - The
|
|
9
|
-
* @returns The sentence
|
|
5
|
+
* @param sentence - The string to format.
|
|
6
|
+
* @returns The sentence with every word title-cased.
|
|
10
7
|
*
|
|
11
8
|
* @example
|
|
12
9
|
* ```typescript
|
|
13
|
-
* //
|
|
14
|
-
* formatToCapitalizeFirstWordLetter("
|
|
15
|
-
* // Returns: "Hello World"
|
|
16
|
-
*
|
|
17
|
-
* // With capitalized text.
|
|
18
|
-
* formatToCapitalizeFirstWordLetter("HELLO WORLD");
|
|
19
|
-
* // Returns: "Hello World"
|
|
20
|
-
*
|
|
21
|
-
* // With mixed text.
|
|
22
|
-
* formatToCapitalizeFirstWordLetter("hELLO WoRLd"); * // Returns: "Hello World"
|
|
23
|
-
*
|
|
24
|
-
* // With multiple words
|
|
25
|
-
* formatToCapitalizeFirstWordLetter("javascript is an amazing language");
|
|
26
|
-
* // Returns: "Javascript is an amazing language"
|
|
27
|
-
*
|
|
28
|
-
* // Empty string
|
|
29
|
-
* formatToCapitalizeFirstWordLetter("");
|
|
30
|
-
* // Returns: ""
|
|
10
|
+
* formatToCapitalizeFirstWordLetter("hello world"); // "Hello World"
|
|
11
|
+
* formatToCapitalizeFirstWordLetter("HELLO WORLD"); // "Hello World"
|
|
31
12
|
* ```
|
|
32
13
|
*/
|
|
33
14
|
function formatToCapitalizeFirstWordLetter(sentence) {
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
* and attempts to format it as a CEP in the pattern `XXXXX-XXX`.
|
|
6
6
|
* If the input does not match the expected format, an error is thrown.
|
|
7
7
|
*
|
|
8
|
-
* @param
|
|
9
|
-
*
|
|
10
|
-
* @returns {string} The formatted CEP string in the pattern `XXXXX-XXX`.
|
|
8
|
+
* @param value - Input string with 8 numeric digits (special characters are stripped).
|
|
9
|
+
* @returns The formatted CEP string in the pattern `XXXXX-XXX`.
|
|
11
10
|
*
|
|
12
11
|
* @throws {Error} If the input does not match the expected CEP format.
|
|
13
12
|
*
|
|
@@ -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;;;;;;;;;;;;;;;;;GAiBG;AAEH,iBAAS,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ1C;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -6,9 +6,8 @@ import { removeNonNumeric } from "../utilities/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
|
|
10
|
-
*
|
|
11
|
-
* @returns {string} The formatted CEP string in the pattern `XXXXX-XXX`.
|
|
9
|
+
* @param value - Input string with 8 numeric digits (special characters are stripped).
|
|
10
|
+
* @returns The formatted CEP string in the pattern `XXXXX-XXX`.
|
|
12
11
|
*
|
|
13
12
|
* @throws {Error} If the input does not match the expected CEP format.
|
|
14
13
|
*
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The CNPJ format is: `XX.XXX.XXX/XXXX-XX`, where `X` represents a digit.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
*
|
|
8
|
-
* @returns {string} The formatted CNPJ string in the pattern `XX.XXX.XXX/XXXX-XX`.
|
|
6
|
+
* @param value - Input string with 14 numeric digits (special characters are stripped).
|
|
7
|
+
* @returns The formatted CNPJ string in the pattern `XX.XXX.XXX/XXXX-XX`.
|
|
9
8
|
*
|
|
10
9
|
* @throws {Error} Throws an error if the input does not contain exactly 14 numeric digits.
|
|
11
10
|
*
|
|
@@ -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;;;;;;;;;;;;;;;GAeG;AAEH,iBAAS,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ3C;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -4,9 +4,8 @@ import { removeNonNumeric } from "../utilities/removeNonNumeric";
|
|
|
4
4
|
*
|
|
5
5
|
* The CNPJ format is: `XX.XXX.XXX/XXXX-XX`, where `X` represents a digit.
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
8
|
-
*
|
|
9
|
-
* @returns {string} The formatted CNPJ string in the pattern `XX.XXX.XXX/XXXX-XX`.
|
|
7
|
+
* @param value - Input string with 14 numeric digits (special characters are stripped).
|
|
8
|
+
* @returns The formatted CNPJ string in the pattern `XX.XXX.XXX/XXXX-XX`.
|
|
10
9
|
*
|
|
11
10
|
* @throws {Error} Throws an error if the input does not contain exactly 14 numeric digits.
|
|
12
11
|
*
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
* This function ensures the input is cleaned of non-numeric characters and
|
|
6
6
|
* then formats it into the standard CPF format: `XXX.XXX.XXX-XX`.
|
|
7
7
|
*
|
|
8
|
-
* @param
|
|
9
|
-
*
|
|
10
|
-
* @returns {string} The formatted CPF string.
|
|
8
|
+
* @param value - Input string with 11 numeric digits (special characters are stripped).
|
|
9
|
+
* @returns The formatted CPF string in the pattern `XXX.XXX.XXX-XX`.
|
|
11
10
|
*
|
|
12
11
|
* @throws {Error} If the input string does not match the expected CPF format.
|
|
13
12
|
*
|
|
@@ -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;;;;;;;;;;;;;;;;;GAiBG;AAEH,iBAAS,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ1C;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -6,9 +6,8 @@ import { removeNonNumeric } from "../utilities/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
|
|
10
|
-
*
|
|
11
|
-
* @returns {string} The formatted CPF string.
|
|
9
|
+
* @param value - Input string with 11 numeric digits (special characters are stripped).
|
|
10
|
+
* @returns The formatted CPF string in the pattern `XXX.XXX.XXX-XX`.
|
|
12
11
|
*
|
|
13
12
|
* @throws {Error} If the input string does not match the expected CPF format.
|
|
14
13
|
*
|
|
@@ -1,34 +1,17 @@
|
|
|
1
1
|
import { countryCurrencies } from "@arkyn/templates";
|
|
2
2
|
type Currencies = keyof typeof countryCurrencies;
|
|
3
3
|
/**
|
|
4
|
-
* Formats a
|
|
4
|
+
* Formats a number into a locale-aware currency string using `Intl.NumberFormat`.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @
|
|
6
|
+
* @param value - The numeric value to format.
|
|
7
|
+
* @param currency - A currency code from `@arkyn/templates` (e.g. `"BRL"`, `"USD"`).
|
|
8
|
+
* @param config.showPrefix - Whether to include the currency symbol. Defaults to `true`.
|
|
9
|
+
* @returns The formatted currency string.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
13
|
-
* @example Format a value in USD with prefix
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const formatted = formatToCurrency(1234.56, "USD", { showPrefix: true });
|
|
16
|
-
* console.log(formatted); // "$1,234.56"
|
|
17
|
-
* ```
|
|
18
|
-
* @example Format a value in USD without prefix
|
|
19
|
-
* ```typescript
|
|
20
|
-
* const withoutPrefix = formatToCurrency(1234.56, "USD", { showPrefix: false });
|
|
21
|
-
* console.log(withoutPrefix); // "1,234.56"
|
|
22
|
-
* ```
|
|
23
|
-
* @example Format a value in BRL with prefix
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const formattedBRL = formatToCurrency(1234.56, "BRL", { showPrefix: true });
|
|
26
|
-
* console.log(formattedBRL); // "R$ 1.234,56"
|
|
27
|
-
* ```
|
|
28
|
-
* @example Format a value in BRL without prefix
|
|
11
|
+
* @example
|
|
29
12
|
* ```typescript
|
|
30
|
-
*
|
|
31
|
-
*
|
|
13
|
+
* formatToCurrency(1234.56, "BRL"); // "R$ 1.234,56"
|
|
14
|
+
* formatToCurrency(1234.56, "USD", { showPrefix: false }); // "1,234.56"
|
|
32
15
|
* ```
|
|
33
16
|
*/
|
|
34
17
|
declare function formatToCurrency(value: number, currency: Currencies, config?: {
|
|
@@ -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;;;;;;;;;;;;;GAaG;AACH,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,34 +1,17 @@
|
|
|
1
1
|
import { countryCurrencies } from "@arkyn/templates";
|
|
2
2
|
import { removeCurrencySymbols } from "../utilities/removeCurrencySymbols";
|
|
3
3
|
/**
|
|
4
|
-
* Formats a
|
|
4
|
+
* Formats a number into a locale-aware currency string using `Intl.NumberFormat`.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @
|
|
6
|
+
* @param value - The numeric value to format.
|
|
7
|
+
* @param currency - A currency code from `@arkyn/templates` (e.g. `"BRL"`, `"USD"`).
|
|
8
|
+
* @param config.showPrefix - Whether to include the currency symbol. Defaults to `true`.
|
|
9
|
+
* @returns The formatted currency string.
|
|
10
10
|
*
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
13
|
-
* @example Format a value in USD with prefix
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const formatted = formatToCurrency(1234.56, "USD", { showPrefix: true });
|
|
16
|
-
* console.log(formatted); // "$1,234.56"
|
|
17
|
-
* ```
|
|
18
|
-
* @example Format a value in USD without prefix
|
|
19
|
-
* ```typescript
|
|
20
|
-
* const withoutPrefix = formatToCurrency(1234.56, "USD", { showPrefix: false });
|
|
21
|
-
* console.log(withoutPrefix); // "1,234.56"
|
|
22
|
-
* ```
|
|
23
|
-
* @example Format a value in BRL with prefix
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const formattedBRL = formatToCurrency(1234.56, "BRL", { showPrefix: true });
|
|
26
|
-
* console.log(formattedBRL); // "R$ 1.234,56"
|
|
27
|
-
* ```
|
|
28
|
-
* @example Format a value in BRL without prefix
|
|
11
|
+
* @example
|
|
29
12
|
* ```typescript
|
|
30
|
-
*
|
|
31
|
-
*
|
|
13
|
+
* formatToCurrency(1234.56, "BRL"); // "R$ 1.234,56"
|
|
14
|
+
* formatToCurrency(1234.56, "USD", { showPrefix: false }); // "1,234.56"
|
|
32
15
|
* ```
|
|
33
16
|
*/
|
|
34
17
|
function formatToCurrency(value, currency, config) {
|