@arkyn/shared 1.4.52 → 1.4.55

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 (139) hide show
  1. package/dist/formats/formatDate.d.ts +43 -0
  2. package/dist/formats/formatDate.d.ts.map +1 -0
  3. package/dist/formats/formatDate.js +77 -0
  4. package/dist/formats/formatJsonObject.d.ts +31 -1
  5. package/dist/formats/formatJsonObject.d.ts.map +1 -1
  6. package/dist/formats/formatJsonObject.js +67 -26
  7. package/dist/formats/formatJsonString.d.ts +37 -1
  8. package/dist/formats/formatJsonString.d.ts.map +1 -1
  9. package/dist/formats/formatJsonString.js +38 -4
  10. package/dist/formats/formatToCep.d.ts +27 -1
  11. package/dist/formats/formatToCep.d.ts.map +1 -1
  12. package/dist/formats/formatToCep.js +31 -6
  13. package/dist/formats/formatToCnpj.d.ts +30 -0
  14. package/dist/formats/formatToCnpj.d.ts.map +1 -0
  15. package/dist/formats/formatToCnpj.js +35 -0
  16. package/dist/formats/formatToCpf.d.ts +30 -0
  17. package/dist/formats/formatToCpf.d.ts.map +1 -0
  18. package/dist/formats/formatToCpf.js +35 -0
  19. package/dist/formats/formatToCpfCnpj.d.ts +22 -1
  20. package/dist/formats/formatToCpfCnpj.d.ts.map +1 -1
  21. package/dist/formats/formatToCpfCnpj.js +27 -7
  22. package/dist/formats/formatToCurrency.d.ts +29 -0
  23. package/dist/formats/formatToCurrency.d.ts.map +1 -0
  24. package/dist/formats/formatToCurrency.js +41 -0
  25. package/dist/formats/formatToEllipsis.d.ts +14 -1
  26. package/dist/formats/formatToEllipsis.d.ts.map +1 -1
  27. package/dist/formats/formatToEllipsis.js +20 -3
  28. package/dist/formats/formatToHiddenDigits.d.ts +30 -2
  29. package/dist/formats/formatToHiddenDigits.d.ts.map +1 -1
  30. package/dist/formats/formatToHiddenDigits.js +49 -3
  31. package/dist/formats/formatToPhone.d.ts +32 -1
  32. package/dist/formats/formatToPhone.d.ts.map +1 -1
  33. package/dist/formats/formatToPhone.js +128 -6
  34. package/dist/generators/generateColorByString.d.ts +13 -1
  35. package/dist/generators/generateColorByString.d.ts.map +1 -1
  36. package/dist/generators/generateColorByString.js +15 -4
  37. package/dist/generators/generateId.d.ts +26 -4
  38. package/dist/generators/generateId.d.ts.map +1 -1
  39. package/dist/generators/generateId.js +11 -5
  40. package/dist/generators/generateSlug.d.ts +15 -1
  41. package/dist/generators/generateSlug.d.ts.map +1 -1
  42. package/dist/generators/generateSlug.js +16 -2
  43. package/dist/index.d.ts +7 -10
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +7 -15
  46. package/dist/regex/index.d.ts +6 -0
  47. package/dist/regex/index.d.ts.map +1 -0
  48. package/dist/regex/index.js +4 -0
  49. package/dist/services/calculateCardInstallment.d.ts +31 -5
  50. package/dist/services/calculateCardInstallment.d.ts.map +1 -1
  51. package/dist/services/calculateCardInstallment.js +52 -11
  52. package/dist/services/maskSensitiveData.d.ts +24 -1
  53. package/dist/services/maskSensitiveData.d.ts.map +1 -1
  54. package/dist/services/maskSensitiveData.js +24 -2
  55. package/dist/services/removeCurrencySymbols.d.ts +20 -0
  56. package/dist/services/removeCurrencySymbols.d.ts.map +1 -0
  57. package/dist/services/removeCurrencySymbols.js +23 -0
  58. package/dist/services/removeNonNumeric.d.ts +15 -0
  59. package/dist/services/removeNonNumeric.d.ts.map +1 -0
  60. package/dist/services/removeNonNumeric.js +16 -0
  61. package/dist/services/truncateLargeFields.d.ts +30 -1
  62. package/dist/services/truncateLargeFields.d.ts.map +1 -1
  63. package/dist/services/truncateLargeFields.js +34 -6
  64. package/dist/validations/validateCpf.d.ts +24 -0
  65. package/dist/validations/validateCpf.d.ts.map +1 -0
  66. package/dist/validations/validateCpf.js +56 -0
  67. package/dist/validations/validateDate.d.ts +27 -6
  68. package/dist/validations/validateDate.d.ts.map +1 -1
  69. package/dist/validations/validateDate.js +32 -6
  70. package/dist/validations/validatePhone.d.ts +27 -1
  71. package/dist/validations/validatePhone.d.ts.map +1 -1
  72. package/dist/validations/validatePhone.js +27 -2
  73. package/package.json +4 -2
  74. package/src/formats/formatDate.ts +97 -0
  75. package/src/formats/formatJsonObject.ts +68 -26
  76. package/src/formats/formatJsonString.ts +40 -4
  77. package/src/formats/formatToCep.ts +35 -7
  78. package/src/formats/formatToCnpj.ts +39 -0
  79. package/src/formats/formatToCpf.ts +39 -0
  80. package/src/formats/formatToCpfCnpj.ts +31 -7
  81. package/src/formats/formatToCurrency.ts +53 -0
  82. package/src/formats/formatToEllipsis.ts +23 -3
  83. package/src/formats/formatToHiddenDigits.ts +75 -7
  84. package/src/formats/formatToPhone.ts +156 -6
  85. package/src/generators/generateColorByString.ts +18 -4
  86. package/src/generators/generateId.ts +36 -5
  87. package/src/generators/generateSlug.ts +17 -2
  88. package/src/index.ts +7 -15
  89. package/src/regex/index.ts +8 -0
  90. package/src/services/calculateCardInstallment.ts +57 -12
  91. package/src/services/maskSensitiveData.ts +29 -4
  92. package/src/services/removeCurrencySymbols.ts +25 -0
  93. package/src/services/removeNonNumeric.ts +18 -0
  94. package/src/services/truncateLargeFields.ts +40 -6
  95. package/src/validations/validateCpf.ts +64 -0
  96. package/src/validations/validateDate.ts +33 -11
  97. package/src/validations/validatePhone.ts +29 -2
  98. package/tsconfig.json +1 -1
  99. package/vitest.config.ts +5 -0
  100. package/dist/formats/formatBrazilianDateHour.d.ts +0 -3
  101. package/dist/formats/formatBrazilianDateHour.d.ts.map +0 -1
  102. package/dist/formats/formatBrazilianDateHour.js +0 -12
  103. package/dist/formats/formatBrazilianDateToDate.d.ts +0 -3
  104. package/dist/formats/formatBrazilianDateToDate.d.ts.map +0 -1
  105. package/dist/formats/formatBrazilianDateToDate.js +0 -9
  106. package/dist/formats/formatDateHour.d.ts +0 -3
  107. package/dist/formats/formatDateHour.d.ts.map +0 -1
  108. package/dist/formats/formatDateHour.js +0 -11
  109. package/dist/formats/formatToBRL.d.ts +0 -3
  110. package/dist/formats/formatToBRL.d.ts.map +0 -1
  111. package/dist/formats/formatToBRL.js +0 -8
  112. package/dist/formats/formatToCNPJ.d.ts +0 -3
  113. package/dist/formats/formatToCNPJ.d.ts.map +0 -1
  114. package/dist/formats/formatToCNPJ.js +0 -9
  115. package/dist/formats/formatToCPF.d.ts +0 -3
  116. package/dist/formats/formatToCPF.d.ts.map +0 -1
  117. package/dist/formats/formatToCPF.js +0 -9
  118. package/dist/parsers/parseToCharacters.d.ts +0 -17
  119. package/dist/parsers/parseToCharacters.d.ts.map +0 -1
  120. package/dist/parsers/parseToCharacters.js +0 -13
  121. package/dist/services/range.d.ts +0 -4
  122. package/dist/services/range.d.ts.map +0 -1
  123. package/dist/services/range.js +0 -9
  124. package/dist/validations/regex.d.ts +0 -15
  125. package/dist/validations/regex.d.ts.map +0 -1
  126. package/dist/validations/regex.js +0 -25
  127. package/dist/validations/validateCPF.d.ts +0 -3
  128. package/dist/validations/validateCPF.d.ts.map +0 -1
  129. package/dist/validations/validateCPF.js +0 -36
  130. package/src/formats/formatBrazilianDateHour.ts +0 -17
  131. package/src/formats/formatBrazilianDateToDate.ts +0 -13
  132. package/src/formats/formatDateHour.ts +0 -15
  133. package/src/formats/formatToBRL.ts +0 -10
  134. package/src/formats/formatToCNPJ.ts +0 -10
  135. package/src/formats/formatToCPF.ts +0 -10
  136. package/src/parsers/parseToCharacters.ts +0 -34
  137. package/src/services/range.ts +0 -15
  138. package/src/validations/regex.ts +0 -41
  139. package/src/validations/validateCPF.ts +0 -38
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,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,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,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,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,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;AAExD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC"}
package/dist/index.js CHANGED
@@ -1,30 +1,22 @@
1
- // formats
2
- export { formatBrazilianDateHour } from "./formats/formatBrazilianDateHour";
3
- export { formatBrazilianDateToDate } from "./formats/formatBrazilianDateToDate";
4
- export { formatDateHour } from "./formats/formatDateHour";
1
+ export { formatDate } from "./formats/formatDate";
5
2
  export { formatJsonObject } from "./formats/formatJsonObject";
6
3
  export { formatJsonString } from "./formats/formatJsonString";
7
- export { formatToBRL } from "./formats/formatToBRL";
8
4
  export { formatToCep } from "./formats/formatToCep";
9
- export { formatToCNPJ } from "./formats/formatToCNPJ";
10
- export { formatToCPF } from "./formats/formatToCPF";
5
+ export { formatToCnpj } from "./formats/formatToCnpj";
6
+ export { formatToCpf } from "./formats/formatToCpf";
11
7
  export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
8
+ export { formatToCurrency } from "./formats/formatToCurrency";
12
9
  export { formatToEllipsis } from "./formats/formatToEllipsis";
13
10
  export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
14
11
  export { formatToPhone } from "./formats/formatToPhone";
15
- // generators
16
12
  export { generateColorByString } from "./generators/generateColorByString";
17
13
  export { generateId } from "./generators/generateId";
18
14
  export { generateSlug } from "./generators/generateSlug";
19
- // parsers
20
- export { parseToCharacters } from "./parsers/parseToCharacters";
21
- // services
15
+ export { regex } from "./regex";
22
16
  export { calculateCardInstallment } from "./services/calculateCardInstallment";
23
17
  export { maskSensitiveData } from "./services/maskSensitiveData";
24
- export { normalizeRange, within } from "./services/range";
18
+ export { removeNonNumeric } from "./services/removeNonNumeric";
25
19
  export { truncateLargeFields } from "./services/truncateLargeFields";
26
- // validations
27
- export { regex } from "./validations/regex";
28
- export { validateCPF } from "./validations/validateCPF";
20
+ export { validateCpf } from "./validations/validateCpf";
29
21
  export { validateDate } from "./validations/validateDate";
30
22
  export { validatePhone } from "./validations/validatePhone";
@@ -0,0 +1,6 @@
1
+ declare const regex: {
2
+ RG: RegExp;
3
+ PASSWORD: RegExp;
4
+ };
5
+ export { regex };
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/regex/index.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,KAAK;;;CAAmB,CAAC;AAE/B,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ const RG = /(^\d{1,2}).?(\d{3}).?(\d{3})-?(\d{1}|X|x$)/;
2
+ const PASSWORD = /(?=^.{8,}$)((?=.*\w)(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[|!"$%&\/\(\)\?\^\'\\\+\-\*]))^.*/;
3
+ const regex = { RG, PASSWORD };
4
+ export { regex };
@@ -1,7 +1,33 @@
1
- import type { CalculateCardInstallmentProps } from "@arkyn/types";
2
- declare function calculateCardInstallment(args: CalculateCardInstallmentProps): {
3
- total_price: number;
4
- installment_price: number;
5
- };
1
+ import type { CalculateCardInstallmentFunction } from "@arkyn/types";
2
+ /**
3
+ * Calculates the installment price and total price for a card payment plan.
4
+ *
5
+ * @remarks
6
+ * **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.
7
+ *
8
+ * @throws Will throw an error if the number of installments is less than or equal to 0.
9
+ * @throws Will throw an error if the fees are less than 0.
10
+ *
11
+ * @param props - The input parameters for the calculation.
12
+ * @param props.cashPrice - The total cash price of the product or service.
13
+ * @param props.numberInstallments - The number of installments for the payment plan.
14
+ * @param props.fees - The interest rate per installment (default is 0.0349).
15
+ *
16
+ * @returns An object containing:
17
+ * - `totalPrice`: The total price to be paid, rounded to two decimal places.
18
+ * - `installmentPrice`: The price of each installment, rounded to two decimal places.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const result = calculateCardInstallment({
23
+ * cashPrice: 1000,
24
+ * numberInstallments: 12,
25
+ * fees: 0.02,
26
+ * });
27
+ * console.log(result);
28
+ * // Output: { totalPrice: 1124.62, installmentPrice: 93.72 }
29
+ * ```
30
+ */
31
+ declare const calculateCardInstallment: CalculateCardInstallmentFunction;
6
32
  export { calculateCardInstallment };
7
33
  //# sourceMappingURL=calculateCardInstallment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"calculateCardInstallment.d.ts","sourceRoot":"","sources":["../../src/services/calculateCardInstallment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAElE,iBAAS,wBAAwB,CAAC,IAAI,EAAE,6BAA6B;;;EAgBpE;AAED,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
1
+ {"version":3,"file":"calculateCardInstallment.d.ts","sourceRoot":"","sources":["../../src/services/calculateCardInstallment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,cAAc,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,QAAA,MAAM,wBAAwB,EAAE,gCA+B/B,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
@@ -1,14 +1,55 @@
1
- function calculateCardInstallment(args) {
2
- const { cash_price, number_installments, fees = 0.0349 } = args;
3
- let installment_price = 0;
4
- let total_price = 0;
5
- let numerator = Math.pow(1 + fees, number_installments) * fees;
6
- let denominator = Math.pow(1 + fees, number_installments) - 1;
7
- installment_price = cash_price * (numerator / denominator);
8
- total_price = number_installments * installment_price;
1
+ /**
2
+ * Calculates the installment price and total price for a card payment plan.
3
+ *
4
+ * @remarks
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
+ *
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.
9
+ *
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).
14
+ *
15
+ * @returns An object containing:
16
+ * - `totalPrice`: The total price to be paid, rounded to two decimal places.
17
+ * - `installmentPrice`: The price of each installment, rounded to two decimal places.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const result = calculateCardInstallment({
22
+ * cashPrice: 1000,
23
+ * numberInstallments: 12,
24
+ * fees: 0.02,
25
+ * });
26
+ * console.log(result);
27
+ * // Output: { totalPrice: 1124.62, installmentPrice: 93.72 }
28
+ * ```
29
+ */
30
+ const calculateCardInstallment = (props) => {
31
+ const { cashPrice, numberInstallments, fees = 0.0349 } = props;
32
+ if (fees === 0 || numberInstallments === 1) {
33
+ return {
34
+ totalPrice: cashPrice,
35
+ installmentPrice: cashPrice / numberInstallments,
36
+ };
37
+ }
38
+ if (numberInstallments <= 0) {
39
+ throw new Error("Number of installments must be greater than 0");
40
+ }
41
+ if (fees < 0) {
42
+ throw new Error("Fees must be greater than or equal to 0");
43
+ }
44
+ let installmentPrice = 0;
45
+ let totalPrice = 0;
46
+ let numerator = Math.pow(1 + fees, numberInstallments) * fees;
47
+ let denominator = Math.pow(1 + fees, numberInstallments) - 1;
48
+ installmentPrice = cashPrice * (numerator / denominator);
49
+ totalPrice = numberInstallments * installmentPrice;
9
50
  return {
10
- total_price: +total_price.toFixed(2),
11
- installment_price: +installment_price.toFixed(2),
51
+ totalPrice: +totalPrice.toFixed(2),
52
+ installmentPrice: +installmentPrice.toFixed(2),
12
53
  };
13
- }
54
+ };
14
55
  export { calculateCardInstallment };
@@ -1,3 +1,26 @@
1
- declare function maskSensitiveData(jsonString: string, sensitiveKeys?: string[]): string;
1
+ import type { MaskSensitiveDataFunction } from "@arkyn/types";
2
+ /**
3
+ * Masks sensitive data in a JSON string by replacing the values of specified keys with "****".
4
+ *
5
+ * @param jsonString - The JSON string to be processed.
6
+ * @param sensitiveKeys - An array of keys whose values should be masked. Defaults to `["password", "confirmPassword", "creditCard"]`.
7
+ * @returns A JSON string with sensitive data masked. If the input is not a valid JSON string, it returns the original string.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const jsonString = JSON.stringify({
12
+ * username: "user123",
13
+ * password: "secret",
14
+ * profile: {
15
+ * creditCard: "1234-5678-9012-3456",
16
+ * },
17
+ * });
18
+ *
19
+ * const result = maskSensitiveData(jsonString, ["password", "creditCard"]);
20
+ * console.log(result);
21
+ * // Output: '{"username":"user123","password":"****","profile":{"creditCard":"****"}}'
22
+ * ```
23
+ */
24
+ declare const maskSensitiveData: MaskSensitiveDataFunction;
2
25
  export { maskSensitiveData };
3
26
  //# sourceMappingURL=maskSensitiveData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"maskSensitiveData.d.ts","sourceRoot":"","sources":["../../src/services/maskSensitiveData.ts"],"names":[],"mappings":"AAAA,iBAAS,iBAAiB,CACxB,UAAU,EAAE,MAAM,EAClB,aAAa,WAAgD,GAC5D,MAAM,CAkCR;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"maskSensitiveData.d.ts","sourceRoot":"","sources":["../../src/services/maskSensitiveData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,QAAA,MAAM,iBAAiB,EAAE,yBAqCxB,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1,4 +1,26 @@
1
- function maskSensitiveData(jsonString, sensitiveKeys = ["password", "confirmPassword", "creditCard"]) {
1
+ /**
2
+ * Masks sensitive data in a JSON string by replacing the values of specified keys with "****".
3
+ *
4
+ * @param jsonString - The JSON string to be processed.
5
+ * @param sensitiveKeys - An array of keys whose values should be masked. Defaults to `["password", "confirmPassword", "creditCard"]`.
6
+ * @returns A JSON string with sensitive data masked. If the input is not a valid JSON string, it returns the original string.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const jsonString = JSON.stringify({
11
+ * username: "user123",
12
+ * password: "secret",
13
+ * profile: {
14
+ * creditCard: "1234-5678-9012-3456",
15
+ * },
16
+ * });
17
+ *
18
+ * const result = maskSensitiveData(jsonString, ["password", "creditCard"]);
19
+ * console.log(result);
20
+ * // Output: '{"username":"user123","password":"****","profile":{"creditCard":"****"}}'
21
+ * ```
22
+ */
23
+ const maskSensitiveData = (jsonString, sensitiveKeys = ["password", "confirmPassword", "creditCard"]) => {
2
24
  function maskValue(key, value) {
3
25
  if (sensitiveKeys.includes(key))
4
26
  return "****";
@@ -34,5 +56,5 @@ function maskSensitiveData(jsonString, sensitiveKeys = ["password", "confirmPass
34
56
  catch (error) {
35
57
  return jsonString;
36
58
  }
37
- }
59
+ };
38
60
  export { maskSensitiveData };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Removes currency symbols from a given formatted string.
3
+ *
4
+ * This function takes a string that may contain currency symbols
5
+ * and removes them using a regular expression. The resulting string
6
+ * is also trimmed of any leading or trailing whitespace.
7
+ *
8
+ * @param formattedValue - The input string containing currency symbols.
9
+ * @returns A string with all currency symbols removed and trimmed of whitespace.
10
+ *
11
+ * @example
12
+ * removeCurrencySymbols("R$13,45"); // "13,45"
13
+ * removeCurrencySymbols("$123.45"); // "123.45"
14
+ * removeCurrencySymbols("€99.99"); // "99.99"
15
+ * removeCurrencySymbols("¥1,000"); // "1,000"
16
+ * removeCurrencySymbols("123.45"); // "123.45" (no symbols to remove)
17
+ */
18
+ declare const removeCurrencySymbols: (formattedValue: string) => string;
19
+ export { removeCurrencySymbols };
20
+ //# sourceMappingURL=removeCurrencySymbols.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removeCurrencySymbols.d.ts","sourceRoot":"","sources":["../../src/services/removeCurrencySymbols.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,QAAA,MAAM,qBAAqB,GAAI,gBAAgB,MAAM,KAAG,MAIvD,CAAC;AAEF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Removes currency symbols from a given formatted string.
3
+ *
4
+ * This function takes a string that may contain currency symbols
5
+ * and removes them using a regular expression. The resulting string
6
+ * is also trimmed of any leading or trailing whitespace.
7
+ *
8
+ * @param formattedValue - The input string containing currency symbols.
9
+ * @returns A string with all currency symbols removed and trimmed of whitespace.
10
+ *
11
+ * @example
12
+ * removeCurrencySymbols("R$13,45"); // "13,45"
13
+ * removeCurrencySymbols("$123.45"); // "123.45"
14
+ * removeCurrencySymbols("€99.99"); // "99.99"
15
+ * removeCurrencySymbols("¥1,000"); // "1,000"
16
+ * removeCurrencySymbols("123.45"); // "123.45" (no symbols to remove)
17
+ */
18
+ const removeCurrencySymbols = (formattedValue) => {
19
+ return formattedValue
20
+ .replace(/(?:R\$|\p{Sc}|[$€¥£])/gu, "") // Inclui "R$" e outros símbolos comuns
21
+ .trim();
22
+ };
23
+ export { removeCurrencySymbols };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Removes all non-numeric characters from a given string.
3
+ *
4
+ * @param prop - The input string from which non-numeric characters will be removed.
5
+ * @returns A new string containing only numeric characters from the input.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const result = removeNonNumeric("abc123def456");
10
+ * console.log(result); // Output: "123456"
11
+ * ```
12
+ */
13
+ declare function removeNonNumeric(prop: string): string;
14
+ export { removeNonNumeric };
15
+ //# sourceMappingURL=removeNonNumeric.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removeNonNumeric.d.ts","sourceRoot":"","sources":["../../src/services/removeNonNumeric.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,iBAAS,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Removes all non-numeric characters from a given string.
3
+ *
4
+ * @param prop - The input string from which non-numeric characters will be removed.
5
+ * @returns A new string containing only numeric characters from the input.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const result = removeNonNumeric("abc123def456");
10
+ * console.log(result); // Output: "123456"
11
+ * ```
12
+ */
13
+ function removeNonNumeric(prop) {
14
+ return prop.replace(/[^0-9]/g, "");
15
+ }
16
+ export { removeNonNumeric };
@@ -1,3 +1,32 @@
1
- declare function truncateLargeFields(jsonString: string, maxLength?: number): string;
1
+ import type { TruncateLargeFieldsFunction } from "@arkyn/types";
2
+ /**
3
+ * Truncates large string fields in a JSON string to a specified maximum length.
4
+ *
5
+ * This function parses a JSON string, traverses its structure recursively, and truncates
6
+ * any string fields that exceed the specified maximum length. If a string field is truncated,
7
+ * it is replaced with a message indicating the original length of the field.
8
+ *
9
+ * @param jsonString - The JSON string to process.
10
+ * @param maxLength - The maximum allowed length for string fields. Defaults to 1000.
11
+ * @returns A JSON string with large string fields truncated.
12
+ *
13
+ * @throws {Error} Throws an error if the input is not a valid JSON string.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const json = JSON.stringify({
18
+ * name: "John",
19
+ * description: "A very long description that exceeds the maximum length...",
20
+ * nested: {
21
+ * details: "Another long string that needs truncation."
22
+ * }
23
+ * });
24
+ *
25
+ * const result = truncateLargeFields(json, 50);
26
+ * console.log(result);
27
+ * // Output: '{"name":"John","description":"To large information: field as 57 characters","nested":{"details":"To large information: field as 43 characters"}}'
28
+ * ```
29
+ */
30
+ declare const truncateLargeFields: TruncateLargeFieldsFunction;
2
31
  export { truncateLargeFields };
3
32
  //# sourceMappingURL=truncateLargeFields.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"truncateLargeFields.d.ts","sourceRoot":"","sources":["../../src/services/truncateLargeFields.ts"],"names":[],"mappings":"AAAA,iBAAS,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,SAAO,GAAG,MAAM,CA6BzE;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
1
+ {"version":3,"file":"truncateLargeFields.d.ts","sourceRoot":"","sources":["../../src/services/truncateLargeFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,QAAA,MAAM,mBAAmB,EAAE,2BAgC1B,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
@@ -1,5 +1,33 @@
1
- function truncateLargeFields(jsonString, maxLength = 1000) {
2
- function truncateValue(key, value) {
1
+ /**
2
+ * Truncates large string fields in a JSON string to a specified maximum length.
3
+ *
4
+ * This function parses a JSON string, traverses its structure recursively, and truncates
5
+ * any string fields that exceed the specified maximum length. If a string field is truncated,
6
+ * it is replaced with a message indicating the original length of the field.
7
+ *
8
+ * @param jsonString - The JSON string to process.
9
+ * @param maxLength - The maximum allowed length for string fields. Defaults to 1000.
10
+ * @returns A JSON string with large string fields truncated.
11
+ *
12
+ * @throws {Error} Throws an error if the input is not a valid JSON string.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const json = JSON.stringify({
17
+ * name: "John",
18
+ * description: "A very long description that exceeds the maximum length...",
19
+ * nested: {
20
+ * details: "Another long string that needs truncation."
21
+ * }
22
+ * });
23
+ *
24
+ * const result = truncateLargeFields(json, 50);
25
+ * console.log(result);
26
+ * // Output: '{"name":"John","description":"To large information: field as 57 characters","nested":{"details":"To large information: field as 43 characters"}}'
27
+ * ```
28
+ */
29
+ const truncateLargeFields = (jsonString, maxLength = 1000) => {
30
+ function truncateValue(value) {
3
31
  if (typeof value === "string" && value.length > maxLength) {
4
32
  return `To large information: field as ${value.length} characters`;
5
33
  }
@@ -7,15 +35,15 @@ function truncateLargeFields(jsonString, maxLength = 1000) {
7
35
  }
8
36
  function recursiveTruncate(obj) {
9
37
  if (Array.isArray(obj)) {
10
- return obj.map(recursiveTruncate);
38
+ return obj.map((item) => recursiveTruncate(item)); // Corrigido para processar elementos do array
11
39
  }
12
40
  else if (obj !== null && typeof obj === "object") {
13
41
  return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
14
42
  key,
15
- truncateValue(key, recursiveTruncate(value)),
43
+ recursiveTruncate(value), // Corrigido para aplicar recursão corretamente
16
44
  ]));
17
45
  }
18
- return obj;
46
+ return truncateValue(obj); // Corrigido para truncar valores diretamente
19
47
  }
20
48
  try {
21
49
  const parsedJson = JSON.parse(jsonString);
@@ -25,5 +53,5 @@ function truncateLargeFields(jsonString, maxLength = 1000) {
25
53
  catch (error) {
26
54
  throw new Error("Invalid JSON string");
27
55
  }
28
- }
56
+ };
29
57
  export { truncateLargeFields };
@@ -0,0 +1,24 @@
1
+ import type { ValidateCpfFunction } from "@arkyn/types";
2
+ /**
3
+ * Validates a Brazilian CPF (Cadastro de Pessoas Físicas) number.
4
+ *
5
+ * The CPF is a unique identifier assigned to Brazilian citizens and residents.
6
+ * This function checks if the provided CPF is valid by performing the following steps:
7
+ * - Removes any non-digit characters from the input.
8
+ * - Verifies if the CPF has the correct length (11 digits).
9
+ * - Ensures that all digits are not the same (e.g., "111.111.111-11" is invalid).
10
+ * - Calculates the first and second verification digits using the CPF algorithm.
11
+ * - Compares the calculated verification digits with the ones provided in the CPF.
12
+ *
13
+ * @param rawCpf - The raw CPF string, which may include formatting characters (e.g., dots or dashes).
14
+ * @returns `true` if the CPF is valid, otherwise `false`.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * validateCpf("123.456.789-09"); // false
19
+ * validateCpf("111.444.777-35"); // true
20
+ * ```
21
+ */
22
+ declare const validateCpf: ValidateCpfFunction;
23
+ export { validateCpf };
24
+ //# sourceMappingURL=validateCpf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validateCpf.d.ts","sourceRoot":"","sources":["../../src/validations/validateCpf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AA6BxD;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,QAAA,MAAM,WAAW,EAAE,mBAWlB,CAAC;AAEF,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,56 @@
1
+ function removeNonDigits(cpf) {
2
+ return cpf.replace(/\D/g, "");
3
+ }
4
+ function isInvalidLength(cpf) {
5
+ const CPF_LENGTH = 11;
6
+ return cpf.length !== CPF_LENGTH;
7
+ }
8
+ function hasAllDigitsEqual(cpf) {
9
+ const [firstCpfDigit] = cpf;
10
+ return [...cpf].every((digit) => digit === firstCpfDigit);
11
+ }
12
+ function calculateDigit(cpf, factor) {
13
+ let total = 0;
14
+ for (const digit of cpf) {
15
+ if (factor > 1)
16
+ total += parseInt(digit) * factor--;
17
+ }
18
+ const rest = total % 11;
19
+ return rest < 2 ? 0 : 11 - rest;
20
+ }
21
+ function extractDigit(cpf) {
22
+ return cpf.slice(9);
23
+ }
24
+ /**
25
+ * Validates a Brazilian CPF (Cadastro de Pessoas Físicas) number.
26
+ *
27
+ * The CPF is a unique identifier assigned to Brazilian citizens and residents.
28
+ * This function checks if the provided CPF is valid by performing the following steps:
29
+ * - Removes any non-digit characters from the input.
30
+ * - Verifies if the CPF has the correct length (11 digits).
31
+ * - Ensures that all digits are not the same (e.g., "111.111.111-11" is invalid).
32
+ * - Calculates the first and second verification digits using the CPF algorithm.
33
+ * - Compares the calculated verification digits with the ones provided in the CPF.
34
+ *
35
+ * @param rawCpf - The raw CPF string, which may include formatting characters (e.g., dots or dashes).
36
+ * @returns `true` if the CPF is valid, otherwise `false`.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * validateCpf("123.456.789-09"); // false
41
+ * validateCpf("111.444.777-35"); // true
42
+ * ```
43
+ */
44
+ const validateCpf = (rawCpf) => {
45
+ if (!rawCpf)
46
+ return false;
47
+ const cpf = removeNonDigits(rawCpf);
48
+ if (isInvalidLength(cpf))
49
+ return false;
50
+ if (hasAllDigitsEqual(cpf))
51
+ return false;
52
+ const digit1 = calculateDigit(cpf, 10);
53
+ const digit2 = calculateDigit(cpf, 11);
54
+ return extractDigit(cpf) === `${digit1}${digit2}`;
55
+ };
56
+ export { validateCpf };
@@ -1,8 +1,29 @@
1
- type Format = "DD/MM/YYYY" | "MM-DD-YYYY" | "YYYY-MM-DD";
2
- type Config = {
3
- minYear?: number;
4
- maxYear?: number;
5
- };
6
- declare function validateDate(date: string, format: Format, config?: Config): boolean;
1
+ import type { ValidateDateFunction } from "@arkyn/types";
2
+ /**
3
+ * Validates a date string based on the provided format and configuration.
4
+ *
5
+ * @param date - The date string to validate.
6
+ * @param config - Optional configuration object to customize validation.
7
+ * @param config.inputFormat - The expected format of the input date.
8
+ * Supported formats are "DD/MM/YYYY", "MM-DD-YYYY", and "YYYY-MM-DD".
9
+ * Defaults to "DD/MM/YYYY".
10
+ * @param config.minYear - The minimum allowed year for the date. Defaults to 1900.
11
+ * @param config.maxYear - The maximum allowed year for the date. Defaults to 3000.
12
+ *
13
+ * @returns `true` if the date is valid according to the specified format and configuration, otherwise `false`.
14
+ *
15
+ * @throws {Error} If an invalid date format is provided in the configuration.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * validateDate("31/12/2023"); // true
20
+ * validateDate("12-31-2023", { inputFormat: "MM-DD-YYYY" }); // true
21
+ * validateDate("2023-12-31", { inputFormat: "YYYY-MM-DD", minYear: 2000, maxYear: 2100 }); // true
22
+ * validateDate("29/02/2024", { inputFormat: "DD/MM/YYYY" }); // true (leap year)
23
+ * validateDate("29/02/2023", { inputFormat: "DD/MM/YYYY" }); // false (not a leap year)
24
+ * validateDate("31/04/2023", { inputFormat: "DD/MM/YYYY" }); // false (April has 30 days)
25
+ * ```
26
+ */
27
+ declare const validateDate: ValidateDateFunction;
7
28
  export { validateDate };
8
29
  //# sourceMappingURL=validateDate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validateDate.d.ts","sourceRoot":"","sources":["../../src/validations/validateDate.ts"],"names":[],"mappings":"AAAA,KAAK,MAAM,GAAG,YAAY,GAAG,YAAY,GAAG,YAAY,CAAC;AAEzD,KAAK,MAAM,GAAG;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,iBAAS,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CA6C5E;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"validateDate.d.ts","sourceRoot":"","sources":["../../src/validations/validateDate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,QAAA,MAAM,YAAY,EAAE,oBA8CnB,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,20 +1,46 @@
1
- function validateDate(date, format, config) {
1
+ /**
2
+ * Validates a date string based on the provided format and configuration.
3
+ *
4
+ * @param date - The date string to validate.
5
+ * @param config - Optional configuration object to customize validation.
6
+ * @param config.inputFormat - The expected format of the input date.
7
+ * Supported formats are "DD/MM/YYYY", "MM-DD-YYYY", and "YYYY-MM-DD".
8
+ * Defaults to "DD/MM/YYYY".
9
+ * @param config.minYear - The minimum allowed year for the date. Defaults to 1900.
10
+ * @param config.maxYear - The maximum allowed year for the date. Defaults to 3000.
11
+ *
12
+ * @returns `true` if the date is valid according to the specified format and configuration, otherwise `false`.
13
+ *
14
+ * @throws {Error} If an invalid date format is provided in the configuration.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * validateDate("31/12/2023"); // true
19
+ * validateDate("12-31-2023", { inputFormat: "MM-DD-YYYY" }); // true
20
+ * validateDate("2023-12-31", { inputFormat: "YYYY-MM-DD", minYear: 2000, maxYear: 2100 }); // true
21
+ * validateDate("29/02/2024", { inputFormat: "DD/MM/YYYY" }); // true (leap year)
22
+ * validateDate("29/02/2023", { inputFormat: "DD/MM/YYYY" }); // false (not a leap year)
23
+ * validateDate("31/04/2023", { inputFormat: "DD/MM/YYYY" }); // false (April has 30 days)
24
+ * ```
25
+ */
26
+ const validateDate = (date, config) => {
2
27
  let day, month, year;
3
- const minYear = config?.minYear || 0;
28
+ const inputFormat = config?.inputFormat || "DD/MM/YYYY";
29
+ const minYear = config?.minYear || 1900;
4
30
  const maxYear = config?.maxYear || 3000;
5
- if (format === "DD/MM/YYYY") {
31
+ if (inputFormat === "DD/MM/YYYY") {
6
32
  const dateRegex = /^(\d{2})\/(\d{2})\/(\d{4})$/;
7
33
  if (!dateRegex.test(date))
8
34
  return false;
9
35
  [, day, month, year] = date.match(dateRegex) || [];
10
36
  }
11
- else if (format === "MM-DD-YYYY") {
37
+ else if (inputFormat === "MM-DD-YYYY") {
12
38
  const dateRegex = /^(\d{2})-(\d{2})-(\d{4})$/;
13
39
  if (!dateRegex.test(date))
14
40
  return false;
15
41
  [, month, day, year] = date.match(dateRegex) || [];
16
42
  }
17
- else if (format === "YYYY-MM-DD") {
43
+ else if (inputFormat === "YYYY-MM-DD") {
18
44
  const dateRegex = /^(\d{4})-(\d{2})-(\d{2})$/;
19
45
  if (!dateRegex.test(date))
20
46
  return false;
@@ -43,5 +69,5 @@ function validateDate(date, format, config) {
43
69
  return false;
44
70
  const isValidDate = new Date(yearNum, monthNum - 1, dayNum).getDate() === dayNum;
45
71
  return isValidDate;
46
- }
72
+ };
47
73
  export { validateDate };