@arkyn/shared 3.0.1-beta.12 → 3.0.1-beta.121

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.
Files changed (147) hide show
  1. package/README.md +452 -67
  2. package/dist/bundle.js +2439 -0
  3. package/dist/bundle.umd.cjs +6 -0
  4. package/dist/formats/formatDate.d.ts +43 -15
  5. package/dist/formats/formatDate.d.ts.map +1 -1
  6. package/dist/formats/formatDate.js +60 -25
  7. package/dist/formats/formatJsonObject.d.ts +6 -7
  8. package/dist/formats/formatJsonObject.d.ts.map +1 -1
  9. package/dist/formats/formatJsonObject.js +17 -17
  10. package/dist/formats/formatToCapitalizeFirstWordLetter.d.ts +17 -18
  11. package/dist/formats/formatToCapitalizeFirstWordLetter.d.ts.map +1 -1
  12. package/dist/formats/formatToCapitalizeFirstWordLetter.js +17 -18
  13. package/dist/formats/formatToCep.d.ts +5 -12
  14. package/dist/formats/formatToCep.d.ts.map +1 -1
  15. package/dist/formats/formatToCep.js +11 -16
  16. package/dist/formats/formatToCnpj.d.ts +3 -13
  17. package/dist/formats/formatToCnpj.d.ts.map +1 -1
  18. package/dist/formats/formatToCnpj.js +9 -17
  19. package/dist/formats/formatToCpf.d.ts +5 -13
  20. package/dist/formats/formatToCpf.d.ts.map +1 -1
  21. package/dist/formats/formatToCpf.js +11 -17
  22. package/dist/formats/formatToCurrency.d.ts +18 -14
  23. package/dist/formats/formatToCurrency.d.ts.map +1 -1
  24. package/dist/formats/formatToCurrency.js +21 -14
  25. package/dist/formats/formatToEllipsis.d.ts +8 -5
  26. package/dist/formats/formatToEllipsis.d.ts.map +1 -1
  27. package/dist/formats/formatToEllipsis.js +21 -7
  28. package/dist/formats/formatToHiddenDigits.d.ts +16 -16
  29. package/dist/formats/formatToHiddenDigits.d.ts.map +1 -1
  30. package/dist/formats/formatToHiddenDigits.js +19 -19
  31. package/dist/formats/formatToPhone.d.ts +1 -1
  32. package/dist/formats/formatToPhone.d.ts.map +1 -1
  33. package/dist/formats/formatToPhone.js +3 -3
  34. package/dist/generators/generateColorByString.d.ts +7 -4
  35. package/dist/generators/generateColorByString.d.ts.map +1 -1
  36. package/dist/generators/generateColorByString.js +10 -6
  37. package/dist/generators/generateId.d.ts +3 -3
  38. package/dist/generators/generateSlug.d.ts +10 -3
  39. package/dist/generators/generateSlug.d.ts.map +1 -1
  40. package/dist/generators/generateSlug.js +11 -4
  41. package/dist/index.d.ts +10 -16
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +12 -17
  44. package/dist/{services/truncateLargeFields.d.ts → parsers/parseLargeFields.d.ts} +9 -11
  45. package/dist/parsers/parseLargeFields.d.ts.map +1 -0
  46. package/dist/{services/truncateLargeFields.js → parsers/parseLargeFields.js} +12 -13
  47. package/dist/parsers/parseSensitiveData.d.ts +23 -0
  48. package/dist/parsers/parseSensitiveData.d.ts.map +1 -0
  49. package/dist/{services/maskSensitiveData.js → parsers/parseSensitiveData.js} +10 -12
  50. package/dist/parsers/parseToDate.d.ts +41 -0
  51. package/dist/parsers/parseToDate.d.ts.map +1 -0
  52. package/dist/parsers/parseToDate.js +67 -0
  53. package/dist/services/validateDateService.d.ts +85 -0
  54. package/dist/services/validateDateService.d.ts.map +1 -0
  55. package/dist/services/validateDateService.js +132 -0
  56. package/dist/{services → utilities}/calculateCardInstallment.d.ts +16 -18
  57. package/dist/utilities/calculateCardInstallment.d.ts.map +1 -0
  58. package/dist/{services → utilities}/calculateCardInstallment.js +12 -15
  59. package/dist/utilities/ensureQuotes.d.ts +21 -0
  60. package/dist/utilities/ensureQuotes.d.ts.map +1 -0
  61. package/dist/{services → utilities}/ensureQuotes.js +12 -4
  62. package/dist/utilities/isHtml.d.ts +22 -0
  63. package/dist/utilities/isHtml.d.ts.map +1 -0
  64. package/dist/utilities/isHtml.js +24 -0
  65. package/dist/{services → utilities}/removeCurrencySymbols.d.ts +6 -4
  66. package/dist/utilities/removeCurrencySymbols.d.ts.map +1 -0
  67. package/dist/{services → utilities}/removeCurrencySymbols.js +8 -7
  68. package/dist/utilities/removeNonNumeric.d.ts +16 -0
  69. package/dist/utilities/removeNonNumeric.d.ts.map +1 -0
  70. package/dist/utilities/removeNonNumeric.js +17 -0
  71. package/dist/utilities/stripHtmlTags.d.ts +19 -0
  72. package/dist/utilities/stripHtmlTags.d.ts.map +1 -0
  73. package/dist/utilities/stripHtmlTags.js +24 -0
  74. package/package.json +24 -7
  75. package/dist/formats/formatToCpfCnpj.d.ts +0 -24
  76. package/dist/formats/formatToCpfCnpj.d.ts.map +0 -1
  77. package/dist/formats/formatToCpfCnpj.js +0 -33
  78. package/dist/formats/formatToDate.d.ts +0 -32
  79. package/dist/formats/formatToDate.d.ts.map +0 -1
  80. package/dist/formats/formatToDate.js +0 -50
  81. package/dist/services/calculateCardInstallment.d.ts.map +0 -1
  82. package/dist/services/ensureQuotes.d.ts +0 -14
  83. package/dist/services/ensureQuotes.d.ts.map +0 -1
  84. package/dist/services/maskSensitiveData.d.ts +0 -26
  85. package/dist/services/maskSensitiveData.d.ts.map +0 -1
  86. package/dist/services/removeCurrencySymbols.d.ts.map +0 -1
  87. package/dist/services/removeNonNumeric.d.ts +0 -16
  88. package/dist/services/removeNonNumeric.d.ts.map +0 -1
  89. package/dist/services/removeNonNumeric.js +0 -16
  90. package/dist/services/stripHtmlTags.d.ts +0 -16
  91. package/dist/services/stripHtmlTags.d.ts.map +0 -1
  92. package/dist/services/stripHtmlTags.js +0 -16
  93. package/dist/services/truncateLargeFields.d.ts.map +0 -1
  94. package/dist/validations/validateCep.d.ts +0 -24
  95. package/dist/validations/validateCep.d.ts.map +0 -1
  96. package/dist/validations/validateCep.js +0 -33
  97. package/dist/validations/validateCnpj.d.ts +0 -22
  98. package/dist/validations/validateCnpj.d.ts.map +0 -1
  99. package/dist/validations/validateCnpj.js +0 -52
  100. package/dist/validations/validateCpf.d.ts +0 -24
  101. package/dist/validations/validateCpf.d.ts.map +0 -1
  102. package/dist/validations/validateCpf.js +0 -54
  103. package/dist/validations/validateDate.d.ts +0 -34
  104. package/dist/validations/validateDate.d.ts.map +0 -1
  105. package/dist/validations/validateDate.js +0 -73
  106. package/dist/validations/validatePassword.d.ts +0 -21
  107. package/dist/validations/validatePassword.d.ts.map +0 -1
  108. package/dist/validations/validatePassword.js +0 -34
  109. package/dist/validations/validatePhone.d.ts +0 -29
  110. package/dist/validations/validatePhone.d.ts.map +0 -1
  111. package/dist/validations/validatePhone.js +0 -44
  112. package/dist/validations/validateRg.d.ts +0 -22
  113. package/dist/validations/validateRg.d.ts.map +0 -1
  114. package/dist/validations/validateRg.js +0 -31
  115. package/src/formats/formatDate.ts +0 -92
  116. package/src/formats/formatJsonObject.ts +0 -90
  117. package/src/formats/formatJsonString.ts +0 -50
  118. package/src/formats/formatToCapitalizeFirstWordLetter.ts +0 -46
  119. package/src/formats/formatToCep.ts +0 -39
  120. package/src/formats/formatToCnpj.ts +0 -40
  121. package/src/formats/formatToCpf.ts +0 -40
  122. package/src/formats/formatToCpfCnpj.ts +0 -38
  123. package/src/formats/formatToCurrency.ts +0 -63
  124. package/src/formats/formatToDate.ts +0 -70
  125. package/src/formats/formatToEllipsis.ts +0 -25
  126. package/src/formats/formatToHiddenDigits.ts +0 -92
  127. package/src/formats/formatToPhone.ts +0 -170
  128. package/src/generators/generateColorByString.ts +0 -33
  129. package/src/generators/generateId.ts +0 -61
  130. package/src/generators/generateSlug.ts +0 -31
  131. package/src/index.ts +0 -37
  132. package/src/services/calculateCardInstallment.ts +0 -73
  133. package/src/services/ensureQuotes.ts +0 -25
  134. package/src/services/maskSensitiveData.ts +0 -68
  135. package/src/services/removeCurrencySymbols.ts +0 -29
  136. package/src/services/removeNonNumeric.ts +0 -20
  137. package/src/services/stripHtmlTags.ts +0 -20
  138. package/src/services/truncateLargeFields.ts +0 -69
  139. package/src/validations/validateCep.ts +0 -41
  140. package/src/validations/validateCnpj.ts +0 -65
  141. package/src/validations/validateCpf.ts +0 -62
  142. package/src/validations/validateDate.ts +0 -86
  143. package/src/validations/validatePassword.ts +0 -41
  144. package/src/validations/validatePhone.ts +0 -50
  145. package/src/validations/validateRg.ts +0 -37
  146. package/tsconfig.json +0 -20
  147. package/vitest.config.ts +0 -5
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Service for validating date components and input formats.
3
+ *
4
+ * This service provides methods to validate date parts (year, month, day) and
5
+ * input format strings used in date parsing operations. It includes leap year
6
+ * validation and month-specific day validation.
7
+ *
8
+ * @remarks
9
+ * The service validates:
10
+ * - Year must be exactly 4 digits (1000-9999)
11
+ * - Month must be between 1 and 12
12
+ * - Day must be between 1 and 31
13
+ * - Day must be valid for the specific month (e.g., no February 30)
14
+ * - Leap year rules for February 29
15
+ *
16
+ * @example Validate a valid date
17
+ * ```typescript
18
+ * const service = new ValidateDateService();
19
+ * service.validateDateParts(2024, 1, 15); // No error thrown
20
+ * ```
21
+ *
22
+ * @example Validate an invalid date
23
+ * ```typescript
24
+ * const service = new ValidateDateService();
25
+ * service.validateDateParts(2023, 2, 29); // Throws: "Day 29 is not valid for February 2023 (non-leap year)"
26
+ * ```
27
+ *
28
+ * @example Validate input format
29
+ * ```typescript
30
+ * const service = new ValidateDateService();
31
+ * service.validateInputFormat("brazilianDate"); // No error thrown
32
+ * service.validateInputFormat("invalidFormat"); // Throws: "Invalid input format: invalidFormat"
33
+ * ```
34
+ */
35
+ class ValidateDateService {
36
+ isLeapYear(year) {
37
+ return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
38
+ }
39
+ getDaysInMonth(month, year) {
40
+ const daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
41
+ if (month === 2 && this.isLeapYear(year))
42
+ return 29;
43
+ return daysInMonth[month - 1];
44
+ }
45
+ validateDayInMonth(day, month, year) {
46
+ const maxDays = this.getDaysInMonth(month, year);
47
+ if (day > maxDays) {
48
+ const monthNames = [
49
+ "January",
50
+ "February",
51
+ "March",
52
+ "April",
53
+ "May",
54
+ "June",
55
+ "July",
56
+ "August",
57
+ "September",
58
+ "October",
59
+ "November",
60
+ "December",
61
+ ];
62
+ const errorMessage = `Day ${day} is not valid for ${monthNames[month - 1]}`;
63
+ const leapYearMessage = `Day ${day} is not valid for February ${year} (non-leap year)`;
64
+ if (month === 2 && day === 29)
65
+ throw new Error(leapYearMessage);
66
+ throw new Error(errorMessage);
67
+ }
68
+ }
69
+ /**
70
+ * Validates the components of a date (year, month, and day).
71
+ *
72
+ * @param {number} year - The year to validate (must be 4 digits).
73
+ * @param {number} month - The month to validate (must be between 1 and 12).
74
+ * @param {number} day - The day to validate (must be between 1 and 31, and valid for the month).
75
+ *
76
+ * @throws {Error} "Year should be four digits" - If the year doesn't have exactly 4 digits.
77
+ * @throws {Error} "Month should be between 1 and 12" - If the month is out of valid range.
78
+ * @throws {Error} "Day should be between 1 and 31" - If the day is out of valid range.
79
+ * @throws {Error} Month-specific error - If the day is invalid for the specific month.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const service = new ValidateDateService();
84
+ * service.validateDateParts(2024, 2, 29); // Valid leap year date
85
+ * service.validateDateParts(2023, 2, 29); // Throws error - not a leap year
86
+ * service.validateDateParts(2024, 4, 31); // Throws error - April has only 30 days
87
+ * ```
88
+ */
89
+ validateDateParts(year, month, day) {
90
+ const messageErrors = {
91
+ year: "Year should be four digits",
92
+ month: "Month should be between 1 and 12",
93
+ day: "Day should be between 1 and 31",
94
+ };
95
+ if (`${year}`.length !== 4)
96
+ throw new Error(messageErrors.year);
97
+ if (month < 1 || month > 12)
98
+ throw new Error(messageErrors.month);
99
+ if (day < 1 || day > 31)
100
+ throw new Error(messageErrors.day);
101
+ this.validateDayInMonth(day, month, year);
102
+ }
103
+ /**
104
+ * Validates that a given format string is supported.
105
+ *
106
+ * @param {string} format - The format string to validate.
107
+ *
108
+ * @throws {Error} "Invalid input format: {format}" - If the format is not one of the valid formats.
109
+ *
110
+ * @remarks
111
+ * Valid formats are:
112
+ * - "brazilianDate": DD/MM/YYYY format
113
+ * - "isoDate": MM-DD-YYYY format
114
+ * - "timestamp": YYYY-MM-DD format
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const service = new ValidateDateService();
119
+ * service.validateInputFormat("brazilianDate"); // Valid
120
+ * service.validateInputFormat("isoDate"); // Valid
121
+ * service.validateInputFormat("timestamp"); // Valid
122
+ * service.validateInputFormat("customFormat"); // Throws error
123
+ * ```
124
+ */
125
+ validateInputFormat(format) {
126
+ const validFormats = ["brazilianDate", "isoDate", "timestamp"];
127
+ if (!validFormats.includes(format)) {
128
+ throw new Error(`Invalid input format: ${format}`);
129
+ }
130
+ }
131
+ }
132
+ 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
- * @throws Will throw an error if the number of installments is less than or equal to 0.
16
- * @throws Will throw an error if the fees are less than 0.
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
- * @param props - The input parameters for the calculation.
19
- * @param props.cashPrice - The total cash price of the product or service.
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 const calculateCardInstallment: CalculateCardInstallmentFunction;
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
- * @throws Will throw an error if the number of installments is less than or equal to 0.
8
- * @throws Will throw an error if the fees are less than 0.
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
- * @param props - The input parameters for the calculation.
11
- * @param props.cashPrice - The total cash price of the product or service.
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
- const calculateCardInstallment = (props) => {
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 = numberInstallments * installmentPrice;
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 url - The URL string to be checked and potentially quoted.
9
- * @returns The input string, either unchanged if it is already quoted, or wrapped in double quotes.
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
- const ensureQuotes = (rawValue) => {
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 formattedValue - The input string containing currency symbols.
10
- * @returns A string with all currency symbols removed and trimmed of whitespace.
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 const removeCurrencySymbols: RemoveCurrencySymbolsFunction;
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 formattedValue - The input string containing currency symbols.
9
- * @returns A string with all currency symbols removed and trimmed of whitespace.
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
- const removeCurrencySymbols = (formattedValue) => {
19
- return formattedValue
20
- .replace(/(?:R\$|\p{Sc}|[$€¥£])/gu, "") // Inclui "R$" e outros símbolos comuns
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,16 +1,32 @@
1
1
  {
2
2
  "name": "@arkyn/shared",
3
- "version": "3.0.1-beta.12",
3
+ "version": "3.0.1-beta.121",
4
4
  "main": "./dist/bundle.js",
5
- "module": "./src/index.ts",
5
+ "module": "./dist/bundle.js",
6
6
  "type": "module",
7
7
  "types": "./dist/index.d.ts",
8
8
  "license": "Apache-2.0",
9
9
  "author": "Arkyn | Lucas Gonçalves",
10
- "description": "Shared utilities and types for projects.",
10
+ "description": "Comprehensive collection of reusable utilities for data formatting, validation, generation, and manipulation, featuring Brazilian document validators and financial tools.",
11
+ "keywords": [
12
+ "utilities",
13
+ "formatting",
14
+ "brazilian-documents",
15
+ "cpf",
16
+ "cnpj",
17
+ "cep",
18
+ "currency",
19
+ "typescript",
20
+ "generators"
21
+ ],
22
+ "homepage": "https://docs.arkyn.dev/en/shared/introduction",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/Lucas-Eduardo-Goncalves/arkyn.git",
26
+ "directory": "packages/shared"
27
+ },
11
28
  "scripts": {
12
- "clean": "rm -rf dist",
13
- "build": "bun run clean && bunx tsc --project tsconfig.json",
29
+ "build": "bunx vite build && tsc",
14
30
  "test": "vitest --config vitest.config.ts",
15
31
  "typecheck": "bunx tsc --project tsconfig.json --noEmit"
16
32
  },
@@ -20,7 +36,8 @@
20
36
  "devDependencies": {
21
37
  "@types/uuid": "^10.0.0",
22
38
  "bun-types": "latest",
23
- "vitest": "^3.1.1",
24
- "typescript": "^5.8.3"
39
+ "vitest": "^3.2.4",
40
+ "typescript": "^5.9.2",
41
+ "vite": "^5.4.19"
25
42
  }
26
43
  }
@@ -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