@arkyn/shared 3.0.1-beta.115 → 3.0.1-beta.117
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 +342 -282
- package/dist/bundle.umd.cjs +6 -6
- package/dist/formats/formatDate.d.ts +43 -15
- package/dist/formats/formatDate.d.ts.map +1 -1
- package/dist/formats/formatDate.js +60 -25
- 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 +1 -1
- package/dist/formats/formatToPhone.d.ts.map +1 -1
- package/dist/formats/formatToPhone.js +3 -3
- 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 +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -10
- package/dist/parsers/parseDate.d.ts +41 -0
- package/dist/parsers/parseDate.d.ts.map +1 -0
- package/dist/parsers/parseDate.js +67 -0
- 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/services/validateDateService.d.ts +9 -0
- package/dist/services/validateDateService.d.ts.map +1 -0
- package/dist/services/validateDateService.js +56 -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/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 +1 -4
- 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/isHtml.d.ts +0 -22
- package/dist/services/isHtml.d.ts.map +0 -1
- package/dist/services/isHtml.js +0 -24
- 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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
class ValidateDateService {
|
|
2
|
+
isLeapYear(year) {
|
|
3
|
+
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
4
|
+
}
|
|
5
|
+
getDaysInMonth(month, year) {
|
|
6
|
+
const daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
7
|
+
if (month === 2 && this.isLeapYear(year))
|
|
8
|
+
return 29;
|
|
9
|
+
return daysInMonth[month - 1];
|
|
10
|
+
}
|
|
11
|
+
validateDayInMonth(day, month, year) {
|
|
12
|
+
const maxDays = this.getDaysInMonth(month, year);
|
|
13
|
+
if (day > maxDays) {
|
|
14
|
+
const monthNames = [
|
|
15
|
+
"January",
|
|
16
|
+
"February",
|
|
17
|
+
"March",
|
|
18
|
+
"April",
|
|
19
|
+
"May",
|
|
20
|
+
"June",
|
|
21
|
+
"July",
|
|
22
|
+
"August",
|
|
23
|
+
"September",
|
|
24
|
+
"October",
|
|
25
|
+
"November",
|
|
26
|
+
"December",
|
|
27
|
+
];
|
|
28
|
+
const errorMessage = `Day ${day} is not valid for ${monthNames[month - 1]}`;
|
|
29
|
+
const leapYearMessage = `Day ${day} is not valid for February ${year} (non-leap year)`;
|
|
30
|
+
if (month === 2 && day === 29)
|
|
31
|
+
throw new Error(leapYearMessage);
|
|
32
|
+
throw new Error(errorMessage);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
validateDateParts(year, month, day) {
|
|
36
|
+
const messageErrors = {
|
|
37
|
+
year: "Year should be four digits",
|
|
38
|
+
month: "Month should be between 1 and 12",
|
|
39
|
+
day: "Day should be between 1 and 31",
|
|
40
|
+
};
|
|
41
|
+
if (`${year}`.length !== 4)
|
|
42
|
+
throw new Error(messageErrors.year);
|
|
43
|
+
if (month < 1 || month > 12)
|
|
44
|
+
throw new Error(messageErrors.month);
|
|
45
|
+
if (day < 1 || day > 31)
|
|
46
|
+
throw new Error(messageErrors.day);
|
|
47
|
+
this.validateDayInMonth(day, month, year);
|
|
48
|
+
}
|
|
49
|
+
validateInputFormat(format) {
|
|
50
|
+
const validFormats = ["brazilianDate", "isoDate", "timestamp"];
|
|
51
|
+
if (!validFormats.includes(format)) {
|
|
52
|
+
throw new Error(`Invalid input format: ${format}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export { ValidateDateService };
|
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
type CalculateCardInstallmentFunction = (props: {
|
|
2
|
-
cashPrice: number;
|
|
3
|
-
numberInstallments: number;
|
|
4
|
-
fees?: number;
|
|
5
|
-
}) => {
|
|
6
|
-
totalPrice: number;
|
|
7
|
-
installmentPrice: number;
|
|
8
|
-
};
|
|
9
1
|
/**
|
|
10
2
|
* Calculates the installment price and total price for a card payment plan.
|
|
11
3
|
*
|
|
12
4
|
* @remarks
|
|
13
5
|
* **Important:** When the interest amount (`fees`) is equal to 0 or the number of installments (`numberInstallments`) is equal to 1, no interest will be charged.
|
|
14
6
|
*
|
|
15
|
-
* @
|
|
16
|
-
* @
|
|
7
|
+
* @param {object} props - The input parameters for the calculation.
|
|
8
|
+
* @param {number} props.cashPrice - The total cash price of the product or service.
|
|
9
|
+
* @param {number} props.numberInstallments - The number of installments for the payment plan.
|
|
10
|
+
* @param {number} [props.fees=0.0349] - The interest rate per installment (default is 0.0349).
|
|
17
11
|
*
|
|
18
|
-
* @
|
|
19
|
-
* @
|
|
20
|
-
* @param props.numberInstallments - The number of installments for the payment plan.
|
|
21
|
-
* @param props.fees - The interest rate per installment (default is 0.0349).
|
|
12
|
+
* @throws {Error} If `numberInstallments` is less than or equal to 0.
|
|
13
|
+
* @throws {Error} If `fees` is less than 0.
|
|
22
14
|
*
|
|
23
|
-
* @returns An object containing:
|
|
15
|
+
* @returns {object} An object containing:
|
|
24
16
|
* - `totalPrice`: The total price to be paid, rounded to two decimal places.
|
|
25
17
|
* - `installmentPrice`: The price of each installment, rounded to two decimal places.
|
|
26
18
|
*
|
|
@@ -31,10 +23,16 @@ type CalculateCardInstallmentFunction = (props: {
|
|
|
31
23
|
* numberInstallments: 12,
|
|
32
24
|
* fees: 0.02,
|
|
33
25
|
* });
|
|
34
|
-
* console.log(result);
|
|
35
|
-
* // Output: { totalPrice: 1124.62, installmentPrice: 93.72 }
|
|
26
|
+
* console.log(result); // Output: { totalPrice: 1124.62, installmentPrice: 93.72 }
|
|
36
27
|
* ```
|
|
37
28
|
*/
|
|
38
|
-
declare
|
|
29
|
+
declare function calculateCardInstallment(props: {
|
|
30
|
+
cashPrice: number;
|
|
31
|
+
numberInstallments: number;
|
|
32
|
+
fees?: number;
|
|
33
|
+
}): {
|
|
34
|
+
totalPrice: number;
|
|
35
|
+
installmentPrice: number;
|
|
36
|
+
};
|
|
39
37
|
export { calculateCardInstallment };
|
|
40
38
|
//# sourceMappingURL=calculateCardInstallment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculateCardInstallment.d.ts","sourceRoot":"","sources":["../../src/utilities/calculateCardInstallment.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,iBAAS,wBAAwB,CAAC,KAAK,EAAE;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,CA4BnD;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* @remarks
|
|
5
5
|
* **Important:** When the interest amount (`fees`) is equal to 0 or the number of installments (`numberInstallments`) is equal to 1, no interest will be charged.
|
|
6
6
|
*
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
7
|
+
* @param {object} props - The input parameters for the calculation.
|
|
8
|
+
* @param {number} props.cashPrice - The total cash price of the product or service.
|
|
9
|
+
* @param {number} props.numberInstallments - The number of installments for the payment plan.
|
|
10
|
+
* @param {number} [props.fees=0.0349] - The interest rate per installment (default is 0.0349).
|
|
9
11
|
*
|
|
10
|
-
* @
|
|
11
|
-
* @
|
|
12
|
-
* @param props.numberInstallments - The number of installments for the payment plan.
|
|
13
|
-
* @param props.fees - The interest rate per installment (default is 0.0349).
|
|
12
|
+
* @throws {Error} If `numberInstallments` is less than or equal to 0.
|
|
13
|
+
* @throws {Error} If `fees` is less than 0.
|
|
14
14
|
*
|
|
15
|
-
* @returns An object containing:
|
|
15
|
+
* @returns {object} An object containing:
|
|
16
16
|
* - `totalPrice`: The total price to be paid, rounded to two decimal places.
|
|
17
17
|
* - `installmentPrice`: The price of each installment, rounded to two decimal places.
|
|
18
18
|
*
|
|
@@ -23,11 +23,10 @@
|
|
|
23
23
|
* numberInstallments: 12,
|
|
24
24
|
* fees: 0.02,
|
|
25
25
|
* });
|
|
26
|
-
* console.log(result);
|
|
27
|
-
* // Output: { totalPrice: 1124.62, installmentPrice: 93.72 }
|
|
26
|
+
* console.log(result); // Output: { totalPrice: 1124.62, installmentPrice: 93.72 }
|
|
28
27
|
* ```
|
|
29
28
|
*/
|
|
30
|
-
|
|
29
|
+
function calculateCardInstallment(props) {
|
|
31
30
|
const { cashPrice, numberInstallments, fees = 0.0349 } = props;
|
|
32
31
|
if (fees === 0 || numberInstallments === 1) {
|
|
33
32
|
return {
|
|
@@ -41,15 +40,13 @@ const calculateCardInstallment = (props) => {
|
|
|
41
40
|
if (fees < 0) {
|
|
42
41
|
throw new Error("Fees must be greater than or equal to 0");
|
|
43
42
|
}
|
|
44
|
-
let installmentPrice = 0;
|
|
45
|
-
let totalPrice = 0;
|
|
46
43
|
let numerator = Math.pow(1 + fees, numberInstallments) * fees;
|
|
47
44
|
let denominator = Math.pow(1 + fees, numberInstallments) - 1;
|
|
48
|
-
installmentPrice = cashPrice * (numerator / denominator);
|
|
49
|
-
totalPrice =
|
|
45
|
+
const installmentPrice = +(cashPrice * (numerator / denominator)).toFixed(2);
|
|
46
|
+
const totalPrice = +(installmentPrice * numberInstallments).toFixed(2);
|
|
50
47
|
return {
|
|
51
48
|
totalPrice: +totalPrice.toFixed(2),
|
|
52
49
|
installmentPrice: +installmentPrice.toFixed(2),
|
|
53
50
|
};
|
|
54
|
-
}
|
|
51
|
+
}
|
|
55
52
|
export { calculateCardInstallment };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensures that a given rawValue string is enclosed in quotes.
|
|
3
|
+
*
|
|
4
|
+
* This function checks if the input string is already enclosed in either single
|
|
5
|
+
* quotes (`'`) or double quotes (`"`). If the string is already quoted, it is
|
|
6
|
+
* returned as-is. Otherwise, the function wraps the string in double quotes.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} rawValue - The raw string to be checked and potentially quoted.
|
|
9
|
+
*
|
|
10
|
+
* @returns {string} The input string, either unchanged if it is already quoted, or wrapped in double quotes.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* ensureQuotes('example'); // Returns: '"example"'
|
|
15
|
+
* ensureQuotes('"already quoted"'); // Returns: '"already quoted"'
|
|
16
|
+
* ensureQuotes("'single quoted'"); // Returns: "'single quoted'"
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function ensureQuotes(rawValue: string): string;
|
|
20
|
+
export { ensureQuotes };
|
|
21
|
+
//# sourceMappingURL=ensureQuotes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureQuotes.d.ts","sourceRoot":"","sources":["../../src/utilities/ensureQuotes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,iBAAS,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAS9C;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -5,15 +5,23 @@
|
|
|
5
5
|
* quotes (`'`) or double quotes (`"`). If the string is already quoted, it is
|
|
6
6
|
* returned as-is. Otherwise, the function wraps the string in double quotes.
|
|
7
7
|
*
|
|
8
|
-
* @param
|
|
9
|
-
*
|
|
8
|
+
* @param {string} rawValue - The raw string to be checked and potentially quoted.
|
|
9
|
+
*
|
|
10
|
+
* @returns {string} The input string, either unchanged if it is already quoted, or wrapped in double quotes.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* ensureQuotes('example'); // Returns: '"example"'
|
|
15
|
+
* ensureQuotes('"already quoted"'); // Returns: '"already quoted"'
|
|
16
|
+
* ensureQuotes("'single quoted'"); // Returns: "'single quoted'"
|
|
17
|
+
* ```
|
|
10
18
|
*/
|
|
11
|
-
|
|
19
|
+
function ensureQuotes(rawValue) {
|
|
12
20
|
const hasSingleQuotes = rawValue.startsWith("'") && rawValue.endsWith("'");
|
|
13
21
|
const hasDoubleQuotes = rawValue.startsWith('"') && rawValue.endsWith('"');
|
|
14
22
|
if (hasSingleQuotes || hasDoubleQuotes) {
|
|
15
23
|
return rawValue;
|
|
16
24
|
}
|
|
17
25
|
return `"${rawValue}"`;
|
|
18
|
-
}
|
|
26
|
+
}
|
|
19
27
|
export { ensureQuotes };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a string contains HTML markup.
|
|
3
|
+
*
|
|
4
|
+
* This function uses a regular expression to detect the presence of HTML tags
|
|
5
|
+
* in a string. The check is case-insensitive and detects both opening
|
|
6
|
+
* and closing tags.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} rawString - A string to be checked
|
|
9
|
+
*
|
|
10
|
+
* @returns {boolean} `true` if the string contains HTML markup, `false` otherwise
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* isHtml('<p>Hello world</p>'); // true
|
|
15
|
+
* isHtml('<div>Content</div>'); // true
|
|
16
|
+
* isHtml('Plain text'); // false
|
|
17
|
+
* isHtml(''); // false
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function isHtml(rawString: string): boolean;
|
|
21
|
+
export { isHtml };
|
|
22
|
+
//# sourceMappingURL=isHtml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isHtml.d.ts","sourceRoot":"","sources":["../../src/utilities/isHtml.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,iBAAS,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAG1C;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a string contains HTML markup.
|
|
3
|
+
*
|
|
4
|
+
* This function uses a regular expression to detect the presence of HTML tags
|
|
5
|
+
* in a string. The check is case-insensitive and detects both opening
|
|
6
|
+
* and closing tags.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} rawString - A string to be checked
|
|
9
|
+
*
|
|
10
|
+
* @returns {boolean} `true` if the string contains HTML markup, `false` otherwise
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* isHtml('<p>Hello world</p>'); // true
|
|
15
|
+
* isHtml('<div>Content</div>'); // true
|
|
16
|
+
* isHtml('Plain text'); // false
|
|
17
|
+
* isHtml(''); // false
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
function isHtml(rawString) {
|
|
21
|
+
const htmlRegex = /<\/?[a-z][\s\S]*>/i;
|
|
22
|
+
return htmlRegex.test(rawString);
|
|
23
|
+
}
|
|
24
|
+
export { isHtml };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
type RemoveCurrencySymbolsFunction = (formattedValue: string) => string;
|
|
2
1
|
/**
|
|
3
2
|
* Removes currency symbols from a given formatted string.
|
|
4
3
|
*
|
|
@@ -6,16 +5,19 @@ type RemoveCurrencySymbolsFunction = (formattedValue: string) => string;
|
|
|
6
5
|
* and removes them using a regular expression. The resulting string
|
|
7
6
|
* is also trimmed of any leading or trailing whitespace.
|
|
8
7
|
*
|
|
9
|
-
* @param
|
|
10
|
-
*
|
|
8
|
+
* @param {string} rawString - The input string containing currency symbols.
|
|
9
|
+
*
|
|
10
|
+
* @returns {string} A string with all currency symbols removed and trimmed of whitespace.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
|
+
* ```typescript
|
|
13
14
|
* removeCurrencySymbols("R$13,45"); // "13,45"
|
|
14
15
|
* removeCurrencySymbols("$123.45"); // "123.45"
|
|
15
16
|
* removeCurrencySymbols("€99.99"); // "99.99"
|
|
16
17
|
* removeCurrencySymbols("¥1,000"); // "1,000"
|
|
17
18
|
* removeCurrencySymbols("123.45"); // "123.45" (no symbols to remove)
|
|
19
|
+
* ```
|
|
18
20
|
*/
|
|
19
|
-
declare
|
|
21
|
+
declare function removeCurrencySymbols(rawString: string): string;
|
|
20
22
|
export { removeCurrencySymbols };
|
|
21
23
|
//# sourceMappingURL=removeCurrencySymbols.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeCurrencySymbols.d.ts","sourceRoot":"","sources":["../../src/utilities/removeCurrencySymbols.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,iBAAS,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -5,19 +5,20 @@
|
|
|
5
5
|
* and removes them using a regular expression. The resulting string
|
|
6
6
|
* is also trimmed of any leading or trailing whitespace.
|
|
7
7
|
*
|
|
8
|
-
* @param
|
|
9
|
-
*
|
|
8
|
+
* @param {string} rawString - The input string containing currency symbols.
|
|
9
|
+
*
|
|
10
|
+
* @returns {string} A string with all currency symbols removed and trimmed of whitespace.
|
|
10
11
|
*
|
|
11
12
|
* @example
|
|
13
|
+
* ```typescript
|
|
12
14
|
* removeCurrencySymbols("R$13,45"); // "13,45"
|
|
13
15
|
* removeCurrencySymbols("$123.45"); // "123.45"
|
|
14
16
|
* removeCurrencySymbols("€99.99"); // "99.99"
|
|
15
17
|
* removeCurrencySymbols("¥1,000"); // "1,000"
|
|
16
18
|
* removeCurrencySymbols("123.45"); // "123.45" (no symbols to remove)
|
|
19
|
+
* ```
|
|
17
20
|
*/
|
|
18
|
-
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
.trim();
|
|
22
|
-
};
|
|
21
|
+
function removeCurrencySymbols(rawString) {
|
|
22
|
+
return rawString.replace(/(?:R\$|\p{Sc}|[$€¥£])/gu, "").trim();
|
|
23
|
+
}
|
|
23
24
|
export { removeCurrencySymbols };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes all non-numeric characters from a given string.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} rawString - The input string from which non-numeric characters will be removed.
|
|
5
|
+
*
|
|
6
|
+
* @returns {string} A new string containing only numeric characters from the input.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const result = removeNonNumeric("abc123def456");
|
|
11
|
+
* console.log(result); // Output: "123456"
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
declare function removeNonNumeric(rawString: string): string;
|
|
15
|
+
export { removeNonNumeric };
|
|
16
|
+
//# sourceMappingURL=removeNonNumeric.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeNonNumeric.d.ts","sourceRoot":"","sources":["../../src/utilities/removeNonNumeric.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,iBAAS,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes all non-numeric characters from a given string.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} rawString - The input string from which non-numeric characters will be removed.
|
|
5
|
+
*
|
|
6
|
+
* @returns {string} A new string containing only numeric characters from the input.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const result = removeNonNumeric("abc123def456");
|
|
11
|
+
* console.log(result); // Output: "123456"
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
function removeNonNumeric(rawString) {
|
|
15
|
+
return rawString.replace(/[^0-9]/g, "");
|
|
16
|
+
}
|
|
17
|
+
export { removeNonNumeric };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strips HTML tags from a string.
|
|
3
|
+
*
|
|
4
|
+
* This function removes all HTML tags from the provided string by replacing any content
|
|
5
|
+
* that matches the HTML tag pattern with an empty string.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} rawHtml - The HTML string to be processed
|
|
8
|
+
*
|
|
9
|
+
* @returns {string} The input string with all HTML tags removed
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const strippedHtml = stripHtmlTags("<p>Hello <strong>World</strong></p>");
|
|
14
|
+
* console.log(strippedHtml); // "Hello World"
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function stripHtmlTags(rawHtml: string): string;
|
|
18
|
+
export { stripHtmlTags };
|
|
19
|
+
//# sourceMappingURL=stripHtmlTags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripHtmlTags.d.ts","sourceRoot":"","sources":["../../src/utilities/stripHtmlTags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,iBAAS,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAM9C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strips HTML tags from a string.
|
|
3
|
+
*
|
|
4
|
+
* This function removes all HTML tags from the provided string by replacing any content
|
|
5
|
+
* that matches the HTML tag pattern with an empty string.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} rawHtml - The HTML string to be processed
|
|
8
|
+
*
|
|
9
|
+
* @returns {string} The input string with all HTML tags removed
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const strippedHtml = stripHtmlTags("<p>Hello <strong>World</strong></p>");
|
|
14
|
+
* console.log(strippedHtml); // "Hello World"
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
function stripHtmlTags(rawHtml) {
|
|
18
|
+
return rawHtml
|
|
19
|
+
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "")
|
|
20
|
+
.replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, "")
|
|
21
|
+
.replace(/<!--[\s\S]*?-->/g, "")
|
|
22
|
+
.replace(/<\/?[a-z][a-z0-9]*[^>]*>/gi, "");
|
|
23
|
+
}
|
|
24
|
+
export { stripHtmlTags };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkyn/shared",
|
|
3
|
-
"version": "3.0.1-beta.
|
|
3
|
+
"version": "3.0.1-beta.117",
|
|
4
4
|
"main": "./dist/bundle.js",
|
|
5
5
|
"module": "./dist/bundle.js",
|
|
6
6
|
"type": "module",
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"keywords": [
|
|
12
12
|
"utilities",
|
|
13
13
|
"formatting",
|
|
14
|
-
"validation",
|
|
15
14
|
"brazilian-documents",
|
|
16
15
|
"cpf",
|
|
17
16
|
"cnpj",
|
|
@@ -27,13 +26,11 @@
|
|
|
27
26
|
"directory": "packages/shared"
|
|
28
27
|
},
|
|
29
28
|
"scripts": {
|
|
30
|
-
"clean": "rm -rf dist",
|
|
31
29
|
"build": "bunx vite build && tsc",
|
|
32
30
|
"test": "vitest --config vitest.config.ts",
|
|
33
31
|
"typecheck": "bunx tsc --project tsconfig.json --noEmit"
|
|
34
32
|
},
|
|
35
33
|
"dependencies": {
|
|
36
|
-
"util": "^0.12.5",
|
|
37
34
|
"uuid": "^10.0.0"
|
|
38
35
|
},
|
|
39
36
|
"devDependencies": {
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
type FormatToCpfCnpjFunction = (value: string) => string;
|
|
2
|
-
/**
|
|
3
|
-
* Formats a given string value into either a CPF or CNPJ format based on its length.
|
|
4
|
-
*
|
|
5
|
-
* - If the input contains 11 numeric characters, it is formatted as a CPF.
|
|
6
|
-
* - If the input contains 14 numeric characters, it is formatted as a CNPJ.
|
|
7
|
-
* - Throws an error if the input length is neither 11 nor 14 after removing non-numeric characters.
|
|
8
|
-
*
|
|
9
|
-
* @param value - The string value to be formatted. It may contain non-numeric characters, which will be removed.
|
|
10
|
-
* @returns The formatted CPF or CNPJ string.
|
|
11
|
-
* @throws {Error} If the input does not have a valid CPF or CNPJ length.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* formatToCpfCnpj("123.456.789-09"); // Returns "123.456.789-09" (CPF format)
|
|
16
|
-
* formatToCpfCnpj("12.345.678/0001-95"); // Returns "12.345.678/0001-95" (CNPJ format)
|
|
17
|
-
* formatToCpfCnpj("12345678909"); // Returns "123.456.789-09" (CPF format)
|
|
18
|
-
* formatToCpfCnpj("12345678000195"); // Returns "12.345.678/0001-95" (CNPJ format)
|
|
19
|
-
* formatToCpfCnpj("123"); // Throws an error: "Invalid CPF or CNPJ length"
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
declare const formatToCpfCnpj: FormatToCpfCnpjFunction;
|
|
23
|
-
export { formatToCpfCnpj };
|
|
24
|
-
//# sourceMappingURL=formatToCpfCnpj.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatToCpfCnpj.d.ts","sourceRoot":"","sources":["../../src/formats/formatToCpfCnpj.ts"],"names":[],"mappings":"AAGA,KAAK,uBAAuB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,QAAA,MAAM,eAAe,EAAE,uBAStB,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { formatToCnpj } from "./formatToCnpj";
|
|
2
|
-
import { formatToCpf } from "./formatToCpf";
|
|
3
|
-
/**
|
|
4
|
-
* Formats a given string value into either a CPF or CNPJ format based on its length.
|
|
5
|
-
*
|
|
6
|
-
* - If the input contains 11 numeric characters, it is formatted as a CPF.
|
|
7
|
-
* - If the input contains 14 numeric characters, it is formatted as a CNPJ.
|
|
8
|
-
* - Throws an error if the input length is neither 11 nor 14 after removing non-numeric characters.
|
|
9
|
-
*
|
|
10
|
-
* @param value - The string value to be formatted. It may contain non-numeric characters, which will be removed.
|
|
11
|
-
* @returns The formatted CPF or CNPJ string.
|
|
12
|
-
* @throws {Error} If the input does not have a valid CPF or CNPJ length.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* formatToCpfCnpj("123.456.789-09"); // Returns "123.456.789-09" (CPF format)
|
|
17
|
-
* formatToCpfCnpj("12.345.678/0001-95"); // Returns "12.345.678/0001-95" (CNPJ format)
|
|
18
|
-
* formatToCpfCnpj("12345678909"); // Returns "123.456.789-09" (CPF format)
|
|
19
|
-
* formatToCpfCnpj("12345678000195"); // Returns "12.345.678/0001-95" (CNPJ format)
|
|
20
|
-
* formatToCpfCnpj("123"); // Throws an error: "Invalid CPF or CNPJ length"
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
const formatToCpfCnpj = (value) => {
|
|
24
|
-
const cleaned = value.replace(/\D/g, "");
|
|
25
|
-
if (cleaned.length === 11) {
|
|
26
|
-
return formatToCpf(cleaned);
|
|
27
|
-
}
|
|
28
|
-
else if (cleaned.length === 14) {
|
|
29
|
-
return formatToCnpj(cleaned);
|
|
30
|
-
}
|
|
31
|
-
throw new Error("Invalid CPF or CNPJ length");
|
|
32
|
-
};
|
|
33
|
-
export { formatToCpfCnpj };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
type InputFormatTypes = "brazilianDate" | "timestamp" | "isoDate";
|
|
2
|
-
type FormatToDateFunction = (date: string[], // [date: string, time?: string]
|
|
3
|
-
inputFormat: InputFormatTypes, timezone?: number) => Date;
|
|
4
|
-
/**
|
|
5
|
-
* Converts a date and time input into a JavaScript `Date` object, formatted according to the specified input format and timezone.
|
|
6
|
-
*
|
|
7
|
-
* @param param0 - A tuple containing the date string and an optional time string.
|
|
8
|
-
* The date string format depends on the `inputFormat` parameter.
|
|
9
|
-
* The time string defaults to "00:00:00" if not provided.
|
|
10
|
-
* @param inputFormat - The format of the input date string.
|
|
11
|
-
* Supported formats are:
|
|
12
|
-
* - `"brazilianDate"`: Expects the date in `DD/MM/YYYY` format.
|
|
13
|
-
* - `"isoDate"`: Expects the date in `YYYY-MM-DD` format.
|
|
14
|
-
* - `"timestamp"`: Expects the date in `YYYY-MM-DD` format (similar to `isoDate`).
|
|
15
|
-
* @param timezone - An optional timezone offset in hours. Defaults to `0` (UTC).
|
|
16
|
-
*
|
|
17
|
-
* @returns A `Date` object representing the parsed date and time, adjusted for the specified timezone.
|
|
18
|
-
*
|
|
19
|
-
* @throws {Error} If the `inputFormat` is invalid.
|
|
20
|
-
* @throws {Error} If the provided date or time is invalid.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* import { formatToDate } from "./formatToIsoDate";
|
|
25
|
-
*
|
|
26
|
-
* const date = formatToDate(["25/12/2023", "15:30:00"], "brazilianDate", -3);
|
|
27
|
-
* console.log(date); // Outputs a Date object for "2023-12-25T18:30:00.000Z" (UTC)
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
declare const formatToDate: FormatToDateFunction;
|
|
31
|
-
export { formatToDate };
|
|
32
|
-
//# sourceMappingURL=formatToDate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatToDate.d.ts","sourceRoot":"","sources":["../../src/formats/formatToDate.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG,eAAe,GAAG,WAAW,GAAG,SAAS,CAAC;AAElE,KAAK,oBAAoB,GAAG,CAC1B,IAAI,EAAE,MAAM,EAAE,EAAE,gCAAgC;AAChD,WAAW,EAAE,gBAAgB,EAC7B,QAAQ,CAAC,EAAE,MAAM,KACd,IAAI,CAAC;AAEV;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,QAAA,MAAM,YAAY,EAAE,oBAgCnB,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a date and time input into a JavaScript `Date` object, formatted according to the specified input format and timezone.
|
|
3
|
-
*
|
|
4
|
-
* @param param0 - A tuple containing the date string and an optional time string.
|
|
5
|
-
* The date string format depends on the `inputFormat` parameter.
|
|
6
|
-
* The time string defaults to "00:00:00" if not provided.
|
|
7
|
-
* @param inputFormat - The format of the input date string.
|
|
8
|
-
* Supported formats are:
|
|
9
|
-
* - `"brazilianDate"`: Expects the date in `DD/MM/YYYY` format.
|
|
10
|
-
* - `"isoDate"`: Expects the date in `YYYY-MM-DD` format.
|
|
11
|
-
* - `"timestamp"`: Expects the date in `YYYY-MM-DD` format (similar to `isoDate`).
|
|
12
|
-
* @param timezone - An optional timezone offset in hours. Defaults to `0` (UTC).
|
|
13
|
-
*
|
|
14
|
-
* @returns A `Date` object representing the parsed date and time, adjusted for the specified timezone.
|
|
15
|
-
*
|
|
16
|
-
* @throws {Error} If the `inputFormat` is invalid.
|
|
17
|
-
* @throws {Error} If the provided date or time is invalid.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { formatToDate } from "./formatToIsoDate";
|
|
22
|
-
*
|
|
23
|
-
* const date = formatToDate(["25/12/2023", "15:30:00"], "brazilianDate", -3);
|
|
24
|
-
* console.log(date); // Outputs a Date object for "2023-12-25T18:30:00.000Z" (UTC)
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
const formatToDate = ([date, time = "00:00:00"], inputFormat, timezone = 0) => {
|
|
28
|
-
const dateParts = date.split(/[-/]/).map(Number);
|
|
29
|
-
const timeParts = time.split(".")[0].split(":").map(Number);
|
|
30
|
-
let day, month, year;
|
|
31
|
-
const [hours = 0, minutes = 0, seconds = 0] = timeParts;
|
|
32
|
-
switch (inputFormat) {
|
|
33
|
-
case "brazilianDate":
|
|
34
|
-
[day, month, year] = dateParts;
|
|
35
|
-
break;
|
|
36
|
-
case "isoDate":
|
|
37
|
-
[year, month, day] = dateParts;
|
|
38
|
-
break;
|
|
39
|
-
case "timestamp":
|
|
40
|
-
[year, month, day] = dateParts.map(Number);
|
|
41
|
-
break;
|
|
42
|
-
default:
|
|
43
|
-
throw new Error("Invalid input format");
|
|
44
|
-
}
|
|
45
|
-
const utcDate = new Date(Date.UTC(year, month - 1, day, hours - timezone, minutes, seconds));
|
|
46
|
-
if (isNaN(utcDate.getTime()))
|
|
47
|
-
throw new Error("Invalid date");
|
|
48
|
-
return utcDate;
|
|
49
|
-
};
|
|
50
|
-
export { formatToDate };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculateCardInstallment.d.ts","sourceRoot":"","sources":["../../src/services/calculateCardInstallment.ts"],"names":[],"mappings":"AAAA,KAAK,gCAAgC,GAAG,CAAC,KAAK,EAAE;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,KAAK;IACJ,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,QAAA,MAAM,wBAAwB,EAAE,gCA+B/B,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
type EnsureQuotesFunction = (rawValue: string) => string;
|
|
2
|
-
/**
|
|
3
|
-
* Ensures that a given rawValue string is enclosed in quotes.
|
|
4
|
-
*
|
|
5
|
-
* This function checks if the input string is already enclosed in either single
|
|
6
|
-
* quotes (`'`) or double quotes (`"`). If the string is already quoted, it is
|
|
7
|
-
* returned as-is. Otherwise, the function wraps the string in double quotes.
|
|
8
|
-
*
|
|
9
|
-
* @param url - The URL string to be checked and potentially quoted.
|
|
10
|
-
* @returns The input string, either unchanged if it is already quoted, or wrapped in double quotes.
|
|
11
|
-
*/
|
|
12
|
-
declare const ensureQuotes: EnsureQuotesFunction;
|
|
13
|
-
export { ensureQuotes };
|
|
14
|
-
//# sourceMappingURL=ensureQuotes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ensureQuotes.d.ts","sourceRoot":"","sources":["../../src/services/ensureQuotes.ts"],"names":[],"mappings":"AAAA,KAAK,oBAAoB,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;AAEzD;;;;;;;;;GASG;AAEH,QAAA,MAAM,YAAY,EAAE,oBASnB,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
|