@arkyn/shared 3.0.1-beta.14 → 3.0.1-beta.141
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 +26 -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,16 +1,19 @@
|
|
|
1
|
-
type FormatToEllipsisFunction = (value: string, maxLength: number) => string;
|
|
2
1
|
/**
|
|
3
2
|
* Truncates a given text to a specified maximum length and appends an ellipsis ("...")
|
|
4
3
|
* if the text exceeds the maximum length.
|
|
5
4
|
*
|
|
6
|
-
* @param text - The input string to be truncated.
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
5
|
+
* @param {string} text - The input string to be truncated.
|
|
6
|
+
*
|
|
7
|
+
* @param {number} maxLength - The maximum allowed length of the string before truncation.
|
|
8
|
+
*
|
|
9
|
+
* @returns {string} The truncated string with an ellipsis if the input exceeds the maximum length,
|
|
9
10
|
* or the original string if it does not.
|
|
10
11
|
* @example
|
|
12
|
+
* ```typescript
|
|
11
13
|
* const result = formatToEllipsis("Hello, world!", 5);
|
|
12
14
|
* console.log(result); // Output: "Hello..."
|
|
15
|
+
* ```
|
|
13
16
|
*/
|
|
14
|
-
declare
|
|
17
|
+
declare function formatToEllipsis(text: string, maxLength: number): string;
|
|
15
18
|
export { formatToEllipsis };
|
|
16
19
|
//# 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;;;;;;;;;;;;;;;GAeG;AAEH,iBAAS,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAsBjE;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -2,20 +2,34 @@
|
|
|
2
2
|
* Truncates a given text to a specified maximum length and appends an ellipsis ("...")
|
|
3
3
|
* if the text exceeds the maximum length.
|
|
4
4
|
*
|
|
5
|
-
* @param text - The input string to be truncated.
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
5
|
+
* @param {string} text - The input string to be truncated.
|
|
6
|
+
*
|
|
7
|
+
* @param {number} maxLength - The maximum allowed length of the string before truncation.
|
|
8
|
+
*
|
|
9
|
+
* @returns {string} The truncated string with an ellipsis if the input exceeds the maximum length,
|
|
8
10
|
* or the original string if it does not.
|
|
9
11
|
* @example
|
|
12
|
+
* ```typescript
|
|
10
13
|
* const result = formatToEllipsis("Hello, world!", 5);
|
|
11
14
|
* console.log(result); // Output: "Hello..."
|
|
15
|
+
* ```
|
|
12
16
|
*/
|
|
13
|
-
|
|
17
|
+
function formatToEllipsis(text, maxLength) {
|
|
14
18
|
if (text.length > maxLength) {
|
|
15
|
-
let trimmedText = text.substring(0, maxLength)
|
|
16
|
-
|
|
19
|
+
let trimmedText = text.substring(0, maxLength);
|
|
20
|
+
// Find the last space to avoid breaking words
|
|
21
|
+
const lastSpaceIndex = trimmedText.lastIndexOf(" ");
|
|
22
|
+
if (lastSpaceIndex > 0) {
|
|
23
|
+
trimmedText = trimmedText.substring(0, lastSpaceIndex);
|
|
24
|
+
}
|
|
25
|
+
// Remove trailing punctuation
|
|
26
|
+
trimmedText = trimmedText.replace(/[\s.,!?;:]+$/, "");
|
|
27
|
+
// If after removing punctuation the text is empty or only contains punctuation/spaces, return only "..."
|
|
28
|
+
if (trimmedText.trim().length === 0 || /^[.,!?;:\s]+$/.test(trimmedText)) {
|
|
29
|
+
return "...";
|
|
30
|
+
}
|
|
17
31
|
return `${trimmedText}...`;
|
|
18
32
|
}
|
|
19
33
|
return text;
|
|
20
|
-
}
|
|
34
|
+
}
|
|
21
35
|
export { formatToEllipsis };
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
type FormatToHiddenDigitsFunction = (value: string, options: {
|
|
2
|
-
range?: number | [number, number];
|
|
3
|
-
hider?: string;
|
|
4
|
-
}) => string;
|
|
5
1
|
/**
|
|
6
2
|
* Formats a string by hiding specific digits within a given range.
|
|
7
3
|
*
|
|
8
4
|
* This function takes a string input and replaces digits within a specified range
|
|
9
5
|
* with a hiding character (e.g., "*"). Non-digit characters remain unchanged.
|
|
10
6
|
*
|
|
11
|
-
* @param value - The input string to be formatted.
|
|
12
|
-
* @param options - Configuration options for formatting.
|
|
13
|
-
* @param options.range - The range of digits to hide. It can be:
|
|
7
|
+
* @param {string} value - The input string to be formatted.
|
|
8
|
+
* @param {FormatToHiddenDigitsOptions} options - Configuration options for formatting.
|
|
9
|
+
* @param {number | [number, number]} options.range - The range of digits to hide. It can be:
|
|
14
10
|
* - A single number (e.g., `3`), which hides the first `n` digits if positive,
|
|
15
11
|
* or the last `n` digits if negative.
|
|
16
12
|
* - A tuple `[start, end]` specifying the range of digits to hide (inclusive).
|
|
17
13
|
* - Defaults to `3`, hiding the first three digits.
|
|
18
|
-
* @param options.hider - The character used to hide digits. Defaults to `"*"`.
|
|
14
|
+
* @param {string} options.hider - The character used to hide digits. Defaults to `"*"`.
|
|
19
15
|
*
|
|
20
|
-
* @returns The formatted string with specified digits hidden.
|
|
16
|
+
* @returns {string} The formatted string with specified digits hidden.
|
|
21
17
|
*
|
|
22
18
|
* @example
|
|
23
19
|
* ```typescript
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* // Output: "***-456-7890"
|
|
20
|
+
* const formatted = formatToHiddenDigits("123-456-7890", { range: 3 });
|
|
21
|
+
* console.log(formatted); // Output: "***-456-7890"
|
|
22
|
+
* ```
|
|
28
23
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const formatted = formatToHiddenDigits("123-456-7890", { range: [4, 6], hider: "#" });
|
|
27
|
+
* console.log(formatted); // Output: "123-###-7890"
|
|
31
28
|
* ```
|
|
32
29
|
*/
|
|
33
|
-
declare
|
|
30
|
+
declare function formatToHiddenDigits(value: string, options?: {
|
|
31
|
+
range?: number | [number, number];
|
|
32
|
+
hider?: string;
|
|
33
|
+
}): string;
|
|
34
34
|
export { formatToHiddenDigits };
|
|
35
35
|
//# sourceMappingURL=formatToHiddenDigits.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatToHiddenDigits.d.ts","sourceRoot":"","sources":["../../src/formats/formatToHiddenDigits.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatToHiddenDigits.d.ts","sourceRoot":"","sources":["../../src/formats/formatToHiddenDigits.ts"],"names":[],"mappings":"AA6CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,iBAAS,oBAAoB,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9D,MAAM,CAWR;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -24,37 +24,37 @@ const within = (range, value) => value >= range[0] && value <= range[1];
|
|
|
24
24
|
* This function takes a string input and replaces digits within a specified range
|
|
25
25
|
* with a hiding character (e.g., "*"). Non-digit characters remain unchanged.
|
|
26
26
|
*
|
|
27
|
-
* @param value - The input string to be formatted.
|
|
28
|
-
* @param options - Configuration options for formatting.
|
|
29
|
-
* @param options.range - The range of digits to hide. It can be:
|
|
27
|
+
* @param {string} value - The input string to be formatted.
|
|
28
|
+
* @param {FormatToHiddenDigitsOptions} options - Configuration options for formatting.
|
|
29
|
+
* @param {number | [number, number]} options.range - The range of digits to hide. It can be:
|
|
30
30
|
* - A single number (e.g., `3`), which hides the first `n` digits if positive,
|
|
31
31
|
* or the last `n` digits if negative.
|
|
32
32
|
* - A tuple `[start, end]` specifying the range of digits to hide (inclusive).
|
|
33
33
|
* - Defaults to `3`, hiding the first three digits.
|
|
34
|
-
* @param options.hider - The character used to hide digits. Defaults to `"*"`.
|
|
34
|
+
* @param {string} options.hider - The character used to hide digits. Defaults to `"*"`.
|
|
35
35
|
*
|
|
36
|
-
* @returns The formatted string with specified digits hidden.
|
|
36
|
+
* @returns {string} The formatted string with specified digits hidden.
|
|
37
37
|
*
|
|
38
38
|
* @example
|
|
39
39
|
* ```typescript
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* // Output: "***-456-7890"
|
|
40
|
+
* const formatted = formatToHiddenDigits("123-456-7890", { range: 3 });
|
|
41
|
+
* console.log(formatted); // Output: "***-456-7890"
|
|
42
|
+
* ```
|
|
44
43
|
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const formatted = formatToHiddenDigits("123-456-7890", { range: [4, 6], hider: "#" });
|
|
47
|
+
* console.log(formatted); // Output: "123-###-7890"
|
|
47
48
|
* ```
|
|
48
49
|
*/
|
|
49
|
-
|
|
50
|
+
function formatToHiddenDigits(value, options) {
|
|
50
51
|
const characters = parseToCharacters(value);
|
|
51
|
-
const range = normalizeRange(options
|
|
52
|
-
|
|
53
|
-
.map((node) => {
|
|
52
|
+
const range = normalizeRange(options?.range ?? 3, characters.digits);
|
|
53
|
+
const mappedCharacters = characters.children.map((node) => {
|
|
54
54
|
if (node.kind === "digit" && within(range, node.digit))
|
|
55
|
-
return options
|
|
55
|
+
return options?.hider ?? "*";
|
|
56
56
|
return node.character;
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
}
|
|
57
|
+
});
|
|
58
|
+
return mappedCharacters.join("");
|
|
59
|
+
}
|
|
60
60
|
export { formatToHiddenDigits };
|
|
@@ -1,34 +1,23 @@
|
|
|
1
|
-
type FormatToPhoneFunction = (prop: string) => string;
|
|
2
1
|
/**
|
|
3
|
-
* Formats a phone number string
|
|
2
|
+
* Formats a phone number string according to the country mask defined in `@arkyn/templates`.
|
|
4
3
|
*
|
|
5
|
-
* The
|
|
6
|
-
*
|
|
4
|
+
* The function parses the input using libphonenumber-js to determine the country and
|
|
5
|
+
* national number, then applies the corresponding country's mask (underscore `_` used
|
|
6
|
+
* as digit placeholder) replacing placeholders with actual digits.
|
|
7
7
|
*
|
|
8
|
-
* @param
|
|
9
|
-
* Example formats:
|
|
10
|
-
* - "+55 32912345678"
|
|
11
|
-
* - "+1 1234567890"
|
|
8
|
+
* @param {string} phoneNumber - The input phone number (can include country code or be in national format).
|
|
12
9
|
*
|
|
13
|
-
* @returns The
|
|
10
|
+
* @returns {string} The phone number formatted following the country's mask.
|
|
14
11
|
*
|
|
15
|
-
* @throws {Error} If the
|
|
16
|
-
* @throws {Error} If the country code or phone number is missing from the input string.
|
|
17
|
-
* @throws {Error} If the provided country code and prefix combination is invalid.
|
|
18
|
-
* @throws {Error} If the provided country code is invalid.
|
|
19
|
-
* @throws {Error} If the provided country code has a prefix but none is supplied in the input.
|
|
12
|
+
* @throws {Error} If the phone number is invalid or if no country mask is found for the parsed country.
|
|
20
13
|
*
|
|
21
14
|
* @example
|
|
22
15
|
* ```typescript
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* console.log(formattedPhone1); // Output: "(11) 91234-5678" (brazilian phone number format)
|
|
27
|
-
*
|
|
28
|
-
* const formattedPhone2 = formatToPhone("+1-123 4567890");
|
|
29
|
-
* console.log(formattedPhone2); // Output: "(123) 456-7890" (us phone number format)
|
|
16
|
+
* console.log(formatToPhone("+5534920524282")); // Output: "(34) 92052-4282" (Brazilian format)
|
|
17
|
+
* console.log(formatToPhone("+553420524282")); // Output: "(34) 2052-4282" (Brazilian format with optional ninth digit)
|
|
18
|
+
* console.log(formatToPhone("+12125550199")); // Output: "(212) 555-0199" (American Samoa format)
|
|
30
19
|
* ```
|
|
31
20
|
*/
|
|
32
|
-
declare
|
|
21
|
+
declare function formatToPhone(phoneNumber: string): string;
|
|
33
22
|
export { formatToPhone };
|
|
34
23
|
//# sourceMappingURL=formatToPhone.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatToPhone.d.ts","sourceRoot":"","sources":["../../src/formats/formatToPhone.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatToPhone.d.ts","sourceRoot":"","sources":["../../src/formats/formatToPhone.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,iBAAS,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CA0BlD;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -1,131 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
function getMask(value) {
|
|
4
|
-
const mask = value.length > 10 ? "NINE" : "EIGTH";
|
|
5
|
-
return mask;
|
|
6
|
-
}
|
|
7
|
-
const TYPES = {
|
|
8
|
-
EIGTH: "(99) 9999-9999",
|
|
9
|
-
NINE: "(99) 99999-9999",
|
|
10
|
-
};
|
|
11
|
-
const MAX_LENGTH = removeNonNumeric(TYPES.NINE).length;
|
|
12
|
-
function applyMask(value, maskPattern) {
|
|
13
|
-
let result = "";
|
|
14
|
-
let digitIndex = 0;
|
|
15
|
-
for (let i = 0; i < maskPattern.length; i++) {
|
|
16
|
-
if (maskPattern[i] === "9") {
|
|
17
|
-
if (digitIndex < value.length) {
|
|
18
|
-
result += value[digitIndex];
|
|
19
|
-
digitIndex++;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
if (digitIndex < value.length) {
|
|
27
|
-
result += maskPattern[i];
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return result;
|
|
35
|
-
}
|
|
36
|
-
function formatPhoneNumber(phoneNumber, country) {
|
|
37
|
-
if (country.code === "+55") {
|
|
38
|
-
let value = removeNonNumeric(phoneNumber);
|
|
39
|
-
const mask = getMask(value);
|
|
40
|
-
let nextLength = value.length;
|
|
41
|
-
if (nextLength > MAX_LENGTH)
|
|
42
|
-
return value;
|
|
43
|
-
value = applyMask(value, TYPES[mask]);
|
|
44
|
-
return value;
|
|
45
|
-
}
|
|
46
|
-
const mask = country.mask;
|
|
47
|
-
let formattedNumber = mask;
|
|
48
|
-
if (country.prefix) {
|
|
49
|
-
const prefixRegex = /\$+/g;
|
|
50
|
-
formattedNumber = formattedNumber.replace(prefixRegex, country.prefix);
|
|
51
|
-
}
|
|
52
|
-
for (let i = 0, j = 0; i < formattedNumber.length && j < phoneNumber.length; i++) {
|
|
53
|
-
if (formattedNumber[i] === "_") {
|
|
54
|
-
formattedNumber =
|
|
55
|
-
formattedNumber.substring(0, i) +
|
|
56
|
-
phoneNumber[j] +
|
|
57
|
-
formattedNumber.substring(i + 1);
|
|
58
|
-
j++;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return formattedNumber;
|
|
62
|
-
}
|
|
63
|
-
function getCountryWithPrefixCode(countryCode, prefix) {
|
|
64
|
-
const country = countries.find((country) => country.code === countryCode && country.prefix === prefix);
|
|
65
|
-
if (!country)
|
|
66
|
-
throw new Error("Invalid country code or prefix");
|
|
67
|
-
if (country.prefix !== prefix) {
|
|
68
|
-
throw new Error("Invalid country code or prefix");
|
|
69
|
-
}
|
|
70
|
-
if (!country.prefix) {
|
|
71
|
-
throw new Error("Invalid country code or prefix");
|
|
72
|
-
}
|
|
73
|
-
return country;
|
|
74
|
-
}
|
|
75
|
-
function getCountryWithoutPrefixCode(countryCode) {
|
|
76
|
-
const country = countries.find((country) => country.code === countryCode);
|
|
77
|
-
if (!country)
|
|
78
|
-
throw new Error("Invalid country code");
|
|
79
|
-
if (country.prefix)
|
|
80
|
-
throw new Error("Invalid country code");
|
|
81
|
-
return country;
|
|
82
|
-
}
|
|
1
|
+
import { parsePhoneNumberWithError } from "libphonenumber-js";
|
|
2
|
+
import { findCountryMask } from "../utilities/findCountryMask";
|
|
83
3
|
/**
|
|
84
|
-
* Formats a phone number string
|
|
4
|
+
* Formats a phone number string according to the country mask defined in `@arkyn/templates`.
|
|
85
5
|
*
|
|
86
|
-
* The
|
|
87
|
-
*
|
|
6
|
+
* The function parses the input using libphonenumber-js to determine the country and
|
|
7
|
+
* national number, then applies the corresponding country's mask (underscore `_` used
|
|
8
|
+
* as digit placeholder) replacing placeholders with actual digits.
|
|
88
9
|
*
|
|
89
|
-
* @param
|
|
90
|
-
* Example formats:
|
|
91
|
-
* - "+55 32912345678"
|
|
92
|
-
* - "+1 1234567890"
|
|
10
|
+
* @param {string} phoneNumber - The input phone number (can include country code or be in national format).
|
|
93
11
|
*
|
|
94
|
-
* @returns The
|
|
12
|
+
* @returns {string} The phone number formatted following the country's mask.
|
|
95
13
|
*
|
|
96
|
-
* @throws {Error} If the
|
|
97
|
-
* @throws {Error} If the country code or phone number is missing from the input string.
|
|
98
|
-
* @throws {Error} If the provided country code and prefix combination is invalid.
|
|
99
|
-
* @throws {Error} If the provided country code is invalid.
|
|
100
|
-
* @throws {Error} If the provided country code has a prefix but none is supplied in the input.
|
|
14
|
+
* @throws {Error} If the phone number is invalid or if no country mask is found for the parsed country.
|
|
101
15
|
*
|
|
102
16
|
* @example
|
|
103
17
|
* ```typescript
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* console.log(formattedPhone1); // Output: "(11) 91234-5678" (brazilian phone number format)
|
|
108
|
-
*
|
|
109
|
-
* const formattedPhone2 = formatToPhone("+1-123 4567890");
|
|
110
|
-
* console.log(formattedPhone2); // Output: "(123) 456-7890" (us phone number format)
|
|
18
|
+
* console.log(formatToPhone("+5534920524282")); // Output: "(34) 92052-4282" (Brazilian format)
|
|
19
|
+
* console.log(formatToPhone("+553420524282")); // Output: "(34) 2052-4282" (Brazilian format with optional ninth digit)
|
|
20
|
+
* console.log(formatToPhone("+12125550199")); // Output: "(212) 555-0199" (American Samoa format)
|
|
111
21
|
* ```
|
|
112
22
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
23
|
+
function formatToPhone(phoneNumber) {
|
|
24
|
+
try {
|
|
25
|
+
const parsedPhone = parsePhoneNumberWithError(phoneNumber);
|
|
26
|
+
const phoneNumberDigits = parsedPhone.nationalNumber.toString();
|
|
27
|
+
let formattedNumber = findCountryMask(phoneNumber)[0];
|
|
28
|
+
for (let i = 0, j = 0; i < formattedNumber.length && j < phoneNumberDigits.length; i++) {
|
|
29
|
+
if (formattedNumber[i] === "_") {
|
|
30
|
+
formattedNumber =
|
|
31
|
+
formattedNumber.substring(0, i) +
|
|
32
|
+
phoneNumberDigits[j] +
|
|
33
|
+
formattedNumber.substring(i + 1);
|
|
34
|
+
j++;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return formattedNumber;
|
|
123
38
|
}
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
39
|
+
catch (rawError) {
|
|
40
|
+
const error = rawError;
|
|
41
|
+
throw new Error(error.message);
|
|
127
42
|
}
|
|
128
|
-
|
|
129
|
-
return formatPhoneNumber(phoneNumber, country);
|
|
130
|
-
};
|
|
43
|
+
}
|
|
131
44
|
export { formatToPhone };
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
type GenerateColorByStringFunction = (prop: string) => string;
|
|
2
1
|
/**
|
|
3
2
|
* Generates a hexadecimal color code based on the input string.
|
|
4
3
|
* The function creates a hash from the string and uses it to calculate
|
|
5
4
|
* RGB values, which are then converted to a hexadecimal color code.
|
|
6
5
|
*
|
|
7
|
-
* @param
|
|
8
|
-
*
|
|
6
|
+
* @param {string} rawString - The input string used to generate the color.
|
|
7
|
+
*
|
|
8
|
+
* @returns {string} A hexadecimal color code (e.g., "#a1b2c3") derived from the input string.
|
|
9
|
+
*
|
|
9
10
|
* @example
|
|
11
|
+
* ```typescript
|
|
10
12
|
* const color = generateColorByString("example");
|
|
11
13
|
* console.log(color); // Outputs a consistent hex color like "#5e8f9a"
|
|
14
|
+
* ```
|
|
12
15
|
*/
|
|
13
|
-
declare
|
|
16
|
+
declare function generateColorByString(rawString: string): string;
|
|
14
17
|
export { generateColorByString };
|
|
15
18
|
//# sourceMappingURL=generateColorByString.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateColorByString.d.ts","sourceRoot":"","sources":["../../src/generators/generateColorByString.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"generateColorByString.d.ts","sourceRoot":"","sources":["../../src/generators/generateColorByString.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,iBAAS,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAgBxD;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -3,16 +3,20 @@
|
|
|
3
3
|
* The function creates a hash from the string and uses it to calculate
|
|
4
4
|
* RGB values, which are then converted to a hexadecimal color code.
|
|
5
5
|
*
|
|
6
|
-
* @param
|
|
7
|
-
*
|
|
6
|
+
* @param {string} rawString - The input string used to generate the color.
|
|
7
|
+
*
|
|
8
|
+
* @returns {string} A hexadecimal color code (e.g., "#a1b2c3") derived from the input string.
|
|
9
|
+
*
|
|
8
10
|
* @example
|
|
11
|
+
* ```typescript
|
|
9
12
|
* const color = generateColorByString("example");
|
|
10
13
|
* console.log(color); // Outputs a consistent hex color like "#5e8f9a"
|
|
14
|
+
* ```
|
|
11
15
|
*/
|
|
12
|
-
|
|
16
|
+
function generateColorByString(rawString) {
|
|
13
17
|
var hash = 0;
|
|
14
|
-
for (var i = 0; i <
|
|
15
|
-
hash =
|
|
18
|
+
for (var i = 0; i < rawString.length; i++) {
|
|
19
|
+
hash = rawString.charCodeAt(i) + ((hash << 5) - hash);
|
|
16
20
|
}
|
|
17
21
|
var red = (hash & 0xff0000) >> 16;
|
|
18
22
|
var green = (hash & 0x00ff00) >> 8;
|
|
@@ -21,5 +25,5 @@ const generateColorByString = (prop) => {
|
|
|
21
25
|
var greenHex = green.toString(16).padStart(2, "0");
|
|
22
26
|
var blueHex = blue.toString(16).padStart(2, "0");
|
|
23
27
|
return "#" + redHex + greenHex + blueHex;
|
|
24
|
-
}
|
|
28
|
+
}
|
|
25
29
|
export { generateColorByString };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates a unique identifier (UUID) in the specified format and type.
|
|
3
3
|
*
|
|
4
|
-
* @param type - The desired output type of the UUID. Can be:
|
|
4
|
+
* @param {"text" | "binary"} type - The desired output type of the UUID. Can be:
|
|
5
5
|
* - `"text"`: Returns the UUID as a string.
|
|
6
6
|
* - `"binary"`: Returns the UUID as a `Uint8Array` in binary format.
|
|
7
|
-
* @param format - The version of the UUID to generate. Can be:
|
|
7
|
+
* @param {"v4" | "v7"} format - The version of the UUID to generate. Can be:
|
|
8
8
|
* - `"v4"`: Generates a random UUID (version 4).
|
|
9
9
|
* - `"v7"`: Generates a time-ordered UUID (version 7).
|
|
10
|
-
* @returns The generated UUID in the specified type and format.
|
|
10
|
+
* @returns {string | Uint8Array} The generated UUID in the specified type and format.
|
|
11
11
|
* - If `type` is `"text"`, a string representation of the UUID is returned.
|
|
12
12
|
* - If `type` is `"binary"`, a `Uint8Array` representation of the UUID is returned.
|
|
13
13
|
* @throws {Error} If an invalid `type` or `format` is provided.
|
|
@@ -9,9 +9,16 @@
|
|
|
9
9
|
* - Collapses multiple consecutive hyphens into a single hyphen.
|
|
10
10
|
* - Trims leading and trailing hyphens.
|
|
11
11
|
*
|
|
12
|
-
* @param string - The input string to be converted into a slug.
|
|
13
|
-
*
|
|
12
|
+
* @param {string} rawString - The input string to be converted into a slug.
|
|
13
|
+
*
|
|
14
|
+
* @returns {string} A URL-friendly slug derived from the input string.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const slug = generateSlug("Hello, World! This is a Test.");
|
|
19
|
+
* console.log(slug); // Outputs: "hello-world-this-is-a-test"
|
|
20
|
+
* ```
|
|
14
21
|
*/
|
|
15
|
-
declare function generateSlug(
|
|
22
|
+
declare function generateSlug(rawString: string): string;
|
|
16
23
|
export { generateSlug };
|
|
17
24
|
//# sourceMappingURL=generateSlug.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateSlug.d.ts","sourceRoot":"","sources":["../../src/generators/generateSlug.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"generateSlug.d.ts","sourceRoot":"","sources":["../../src/generators/generateSlug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,iBAAS,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAa/C;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -9,11 +9,18 @@
|
|
|
9
9
|
* - Collapses multiple consecutive hyphens into a single hyphen.
|
|
10
10
|
* - Trims leading and trailing hyphens.
|
|
11
11
|
*
|
|
12
|
-
* @param string - The input string to be converted into a slug.
|
|
13
|
-
*
|
|
12
|
+
* @param {string} rawString - The input string to be converted into a slug.
|
|
13
|
+
*
|
|
14
|
+
* @returns {string} A URL-friendly slug derived from the input string.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const slug = generateSlug("Hello, World! This is a Test.");
|
|
19
|
+
* console.log(slug); // Outputs: "hello-world-this-is-a-test"
|
|
20
|
+
* ```
|
|
14
21
|
*/
|
|
15
|
-
function generateSlug(
|
|
16
|
-
let slug =
|
|
22
|
+
function generateSlug(rawString) {
|
|
23
|
+
let slug = rawString.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
17
24
|
slug = slug
|
|
18
25
|
.replace(/[^\w\s-]/g, "")
|
|
19
26
|
.replace(/\s+/g, "-")
|
package/dist/index.d.ts
CHANGED
|
@@ -5,27 +5,22 @@ export { formatToCapitalizeFirstWordLetter } from "./formats/formatToCapitalizeF
|
|
|
5
5
|
export { formatToCep } from "./formats/formatToCep";
|
|
6
6
|
export { formatToCnpj } from "./formats/formatToCnpj";
|
|
7
7
|
export { formatToCpf } from "./formats/formatToCpf";
|
|
8
|
-
export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
|
|
9
8
|
export { formatToCurrency } from "./formats/formatToCurrency";
|
|
10
|
-
export { formatToDate } from "./formats/formatToDate";
|
|
11
9
|
export { formatToEllipsis } from "./formats/formatToEllipsis";
|
|
12
10
|
export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
|
|
13
11
|
export { formatToPhone } from "./formats/formatToPhone";
|
|
14
12
|
export { generateColorByString } from "./generators/generateColorByString";
|
|
15
13
|
export { generateId } from "./generators/generateId";
|
|
16
14
|
export { generateSlug } from "./generators/generateSlug";
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export { validatePassword } from "./validations/validatePassword";
|
|
29
|
-
export { validatePhone } from "./validations/validatePhone";
|
|
30
|
-
export { validateRg } from "./validations/validateRg";
|
|
15
|
+
export { parseLargeFields } from "./parsers/parseLargeFields";
|
|
16
|
+
export { parseSensitiveData } from "./parsers/parseSensitiveData";
|
|
17
|
+
export { parseToDate } from "./parsers/parseToDate";
|
|
18
|
+
export { ValidateDateService } from "./services/validateDateService";
|
|
19
|
+
export { calculateCardInstallment } from "./utilities/calculateCardInstallment";
|
|
20
|
+
export { ensureQuotes } from "./utilities/ensureQuotes";
|
|
21
|
+
export { findCountryMask } from "./utilities/findCountryMask";
|
|
22
|
+
export { isHtml } from "./utilities/isHtml";
|
|
23
|
+
export { removeCurrencySymbols } from "./utilities/removeCurrencySymbols";
|
|
24
|
+
export { removeNonNumeric } from "./utilities/removeNonNumeric";
|
|
25
|
+
export { stripHtmlTags } from "./utilities/stripHtmlTags";
|
|
31
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,iCAAiC,EAAE,MAAM,6CAA6C,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,iCAAiC,EAAE,MAAM,6CAA6C,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC"}
|