@arkyn/shared 1.4.57 → 1.5.0

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/formatBrazilianDateHour.d.ts +3 -0
  2. package/dist/formats/formatBrazilianDateHour.d.ts.map +1 -0
  3. package/dist/formats/formatBrazilianDateHour.js +12 -0
  4. package/dist/formats/formatBrazilianDateToDate.d.ts +3 -0
  5. package/dist/formats/formatBrazilianDateToDate.d.ts.map +1 -0
  6. package/dist/formats/formatBrazilianDateToDate.js +9 -0
  7. package/dist/formats/formatDateHour.d.ts +3 -0
  8. package/dist/formats/formatDateHour.d.ts.map +1 -0
  9. package/dist/formats/formatDateHour.js +11 -0
  10. package/dist/formats/formatJsonObject.d.ts +1 -31
  11. package/dist/formats/formatJsonObject.d.ts.map +1 -1
  12. package/dist/formats/formatJsonObject.js +26 -67
  13. package/dist/formats/formatJsonString.d.ts +1 -37
  14. package/dist/formats/formatJsonString.d.ts.map +1 -1
  15. package/dist/formats/formatJsonString.js +4 -38
  16. package/dist/formats/formatToBRL.d.ts +3 -0
  17. package/dist/formats/formatToBRL.d.ts.map +1 -0
  18. package/dist/formats/formatToBRL.js +8 -0
  19. package/dist/formats/formatToCNPJ.d.ts +3 -0
  20. package/dist/formats/formatToCNPJ.d.ts.map +1 -0
  21. package/dist/formats/formatToCNPJ.js +9 -0
  22. package/dist/formats/formatToCPF.d.ts +3 -0
  23. package/dist/formats/formatToCPF.d.ts.map +1 -0
  24. package/dist/formats/formatToCPF.js +9 -0
  25. package/dist/formats/formatToCep.d.ts +1 -27
  26. package/dist/formats/formatToCep.d.ts.map +1 -1
  27. package/dist/formats/formatToCep.js +6 -31
  28. package/dist/formats/formatToCpfCnpj.d.ts +1 -22
  29. package/dist/formats/formatToCpfCnpj.d.ts.map +1 -1
  30. package/dist/formats/formatToCpfCnpj.js +7 -27
  31. package/dist/formats/formatToEllipsis.d.ts +1 -14
  32. package/dist/formats/formatToEllipsis.d.ts.map +1 -1
  33. package/dist/formats/formatToEllipsis.js +3 -20
  34. package/dist/formats/formatToHiddenDigits.d.ts +2 -30
  35. package/dist/formats/formatToHiddenDigits.d.ts.map +1 -1
  36. package/dist/formats/formatToHiddenDigits.js +3 -49
  37. package/dist/formats/formatToPhone.d.ts +1 -32
  38. package/dist/formats/formatToPhone.d.ts.map +1 -1
  39. package/dist/formats/formatToPhone.js +6 -128
  40. package/dist/generators/generateColorByString.d.ts +1 -13
  41. package/dist/generators/generateColorByString.d.ts.map +1 -1
  42. package/dist/generators/generateColorByString.js +4 -15
  43. package/dist/generators/generateId.d.ts +4 -26
  44. package/dist/generators/generateId.d.ts.map +1 -1
  45. package/dist/generators/generateId.js +5 -11
  46. package/dist/generators/generateSlug.d.ts +1 -15
  47. package/dist/generators/generateSlug.d.ts.map +1 -1
  48. package/dist/generators/generateSlug.js +2 -16
  49. package/dist/index.d.ts +10 -7
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +15 -7
  52. package/dist/parsers/parseToCharacters.d.ts +17 -0
  53. package/dist/parsers/parseToCharacters.d.ts.map +1 -0
  54. package/dist/parsers/parseToCharacters.js +13 -0
  55. package/dist/services/calculateCardInstallment.d.ts +5 -31
  56. package/dist/services/calculateCardInstallment.d.ts.map +1 -1
  57. package/dist/services/calculateCardInstallment.js +11 -52
  58. package/dist/services/maskSensitiveData.d.ts +1 -24
  59. package/dist/services/maskSensitiveData.d.ts.map +1 -1
  60. package/dist/services/maskSensitiveData.js +2 -24
  61. package/dist/services/range.d.ts +4 -0
  62. package/dist/services/range.d.ts.map +1 -0
  63. package/dist/services/range.js +9 -0
  64. package/dist/services/truncateLargeFields.d.ts +1 -30
  65. package/dist/services/truncateLargeFields.d.ts.map +1 -1
  66. package/dist/services/truncateLargeFields.js +6 -34
  67. package/dist/validations/regex.d.ts +15 -0
  68. package/dist/validations/regex.d.ts.map +1 -0
  69. package/dist/validations/regex.js +25 -0
  70. package/dist/validations/validateCPF.d.ts +3 -0
  71. package/dist/validations/validateCPF.d.ts.map +1 -0
  72. package/dist/validations/validateCPF.js +36 -0
  73. package/dist/validations/validateDate.d.ts +6 -27
  74. package/dist/validations/validateDate.d.ts.map +1 -1
  75. package/dist/validations/validateDate.js +6 -32
  76. package/dist/validations/validatePhone.d.ts +1 -27
  77. package/dist/validations/validatePhone.d.ts.map +1 -1
  78. package/dist/validations/validatePhone.js +2 -27
  79. package/package.json +2 -4
  80. package/src/formats/formatBrazilianDateHour.ts +17 -0
  81. package/src/formats/formatBrazilianDateToDate.ts +13 -0
  82. package/src/formats/formatDateHour.ts +15 -0
  83. package/src/formats/formatJsonObject.ts +26 -68
  84. package/src/formats/formatJsonString.ts +4 -40
  85. package/src/formats/formatToBRL.ts +10 -0
  86. package/src/formats/formatToCNPJ.ts +10 -0
  87. package/src/formats/formatToCPF.ts +10 -0
  88. package/src/formats/formatToCep.ts +7 -35
  89. package/src/formats/formatToCpfCnpj.ts +7 -31
  90. package/src/formats/formatToEllipsis.ts +3 -23
  91. package/src/formats/formatToHiddenDigits.ts +7 -75
  92. package/src/formats/formatToPhone.ts +6 -156
  93. package/src/generators/generateColorByString.ts +4 -18
  94. package/src/generators/generateId.ts +5 -36
  95. package/src/generators/generateSlug.ts +2 -17
  96. package/src/index.ts +15 -7
  97. package/src/parsers/parseToCharacters.ts +34 -0
  98. package/src/services/calculateCardInstallment.ts +12 -57
  99. package/src/services/maskSensitiveData.ts +4 -29
  100. package/src/services/range.ts +15 -0
  101. package/src/services/truncateLargeFields.ts +6 -40
  102. package/src/validations/regex.ts +41 -0
  103. package/src/validations/validateCPF.ts +38 -0
  104. package/src/validations/validateDate.ts +11 -33
  105. package/src/validations/validatePhone.ts +2 -29
  106. package/tsconfig.json +1 -1
  107. package/dist/formats/formatDate.d.ts +0 -43
  108. package/dist/formats/formatDate.d.ts.map +0 -1
  109. package/dist/formats/formatDate.js +0 -77
  110. package/dist/formats/formatToCnpj.d.ts +0 -30
  111. package/dist/formats/formatToCnpj.d.ts.map +0 -1
  112. package/dist/formats/formatToCnpj.js +0 -35
  113. package/dist/formats/formatToCpf.d.ts +0 -30
  114. package/dist/formats/formatToCpf.d.ts.map +0 -1
  115. package/dist/formats/formatToCpf.js +0 -35
  116. package/dist/formats/formatToCurrency.d.ts +0 -29
  117. package/dist/formats/formatToCurrency.d.ts.map +0 -1
  118. package/dist/formats/formatToCurrency.js +0 -41
  119. package/dist/regex/index.d.ts +0 -6
  120. package/dist/regex/index.d.ts.map +0 -1
  121. package/dist/regex/index.js +0 -4
  122. package/dist/services/removeCurrencySymbols.d.ts +0 -20
  123. package/dist/services/removeCurrencySymbols.d.ts.map +0 -1
  124. package/dist/services/removeCurrencySymbols.js +0 -23
  125. package/dist/services/removeNonNumeric.d.ts +0 -15
  126. package/dist/services/removeNonNumeric.d.ts.map +0 -1
  127. package/dist/services/removeNonNumeric.js +0 -16
  128. package/dist/validations/validateCpf.d.ts +0 -24
  129. package/dist/validations/validateCpf.d.ts.map +0 -1
  130. package/dist/validations/validateCpf.js +0 -56
  131. package/src/formats/formatDate.ts +0 -97
  132. package/src/formats/formatToCnpj.ts +0 -39
  133. package/src/formats/formatToCpf.ts +0 -39
  134. package/src/formats/formatToCurrency.ts +0 -53
  135. package/src/regex/index.ts +0 -8
  136. package/src/services/removeCurrencySymbols.ts +0 -25
  137. package/src/services/removeNonNumeric.ts +0 -18
  138. package/src/validations/validateCpf.ts +0 -64
  139. package/vitest.config.ts +0 -5
@@ -1,52 +1,6 @@
1
- const DIGIT = /^\d$/;
2
- const parseToCharacters = (value) => {
3
- let digits = 0;
4
- const children = value
5
- .split("")
6
- .map((character) => {
7
- if (DIGIT.test(character))
8
- return { character, kind: "digit", digit: ++digits };
9
- return { character, kind: "other" };
10
- });
11
- return { digits, children, kind: "root" };
12
- };
13
- const normalizeRange = (range, limit) => {
14
- if (Array.isArray(range))
15
- return range;
16
- if (range >= 0)
17
- return [0, range];
18
- return [limit + 1 - Math.abs(range), limit];
19
- };
20
- const within = (range, value) => value >= range[0] && value <= range[1];
21
- /**
22
- * Formats a string by hiding specific digits within a given range.
23
- *
24
- * This function takes a string input and replaces digits within a specified range
25
- * with a hiding character (e.g., "*"). Non-digit characters remain unchanged.
26
- *
27
- * @param value - The input string to be formatted.
28
- * @param options - Configuration options for formatting.
29
- * @param options.range - The range of digits to hide. It can be:
30
- * - A single number (e.g., `3`), which hides the first `n` digits if positive,
31
- * or the last `n` digits if negative.
32
- * - A tuple `[start, end]` specifying the range of digits to hide (inclusive).
33
- * - Defaults to `3`, hiding the first three digits.
34
- * @param options.hider - The character used to hide digits. Defaults to `"*"`.
35
- *
36
- * @returns The formatted string with specified digits hidden.
37
- *
38
- * @example
39
- * ```typescript
40
- * import { formatToHiddenDigits } from "./formatToHiddenDigits";
41
- *
42
- * formatToHiddenDigits("123-456-7890", { range: 3 });
43
- * // Output: "***-456-7890"
44
- *
45
- * formatToHiddenDigits("123-456-7890", { range: [4, 6], hider: "#" });
46
- * // Output: "123-###-7890"
47
- * ```
48
- */
49
- const formatToHiddenDigits = (value, options) => {
1
+ import { parseToCharacters } from "../parsers/parseToCharacters";
2
+ import { normalizeRange, within } from "../services/range";
3
+ const formatToHiddenDigits = (value, options = {}) => {
50
4
  const characters = parseToCharacters(value);
51
5
  const range = normalizeRange(options.range ?? 3, characters.digits);
52
6
  return characters.children
@@ -1,34 +1,3 @@
1
- import type { FormatToPhoneFunction } from "@arkyn/types";
2
- /**
3
- * Formats a phone number string based on the provided country code and optional prefix.
4
- *
5
- * The input string should follow the format: `"<countryCode>-<prefix> <phoneNumber>"` or `"<countryCode> <phoneNumber>"`.
6
- * The function determines the appropriate formatting mask based on the country and applies it to the phone number.
7
- *
8
- * @param prop - The phone number string to be formatted. It must include the country code and optionally a prefix.
9
- * Example formats:
10
- * - "+55-11 912345678"
11
- * - "+1 1234567890"
12
- *
13
- * @returns The formatted phone number string based on the country's formatting rules.
14
- *
15
- * @throws {Error} If the input phone number does not match the expected format.
16
- * @throws {Error} If the country code or phone number is missing from the input string.
17
- * @throws {Error} If the provided country code and prefix combination is invalid.
18
- * @throws {Error} If the provided country code is invalid.
19
- * @throws {Error} If the provided country code has a prefix but none is supplied in the input.
20
- *
21
- * @example
22
- * ```typescript
23
- * import { formatToPhone } from "./formatToPhone";
24
- *
25
- * const formattedPhone1 = formatToPhone("+55 11912345678");
26
- * console.log(formattedPhone1); // Output: "(11) 91234-5678" (brazilian phone number format)
27
- *
28
- * const formattedPhone2 = formatToPhone("+1-123 4567890");
29
- * console.log(formattedPhone2); // Output: "(123) 456-7890" (us phone number format)
30
- * ```
31
- */
32
- declare const formatToPhone: FormatToPhoneFunction;
1
+ declare function formatToPhone(value: string): string;
33
2
  export { formatToPhone };
34
3
  //# sourceMappingURL=formatToPhone.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatToPhone.d.ts","sourceRoot":"","sources":["../../src/formats/formatToPhone.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAqGvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,QAAA,MAAM,aAAa,EAAE,qBAwBpB,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"formatToPhone.d.ts","sourceRoot":"","sources":["../../src/formats/formatToPhone.ts"],"names":[],"mappings":"AAAA,iBAAS,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO5C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -1,131 +1,9 @@
1
- import { countries } from "@arkyn/templates";
2
- import { removeNonNumeric } from "../services/removeNonNumeric";
3
- function getMask(value) {
4
- const mask = value.length > 10 ? "NINE" : "EIGTH";
5
- return mask;
6
- }
7
- const TYPES = {
8
- EIGTH: "(99) 9999-9999",
9
- NINE: "(99) 99999-9999",
10
- };
11
- const MAX_LENGTH = removeNonNumeric(TYPES.NINE).length;
12
- function applyMask(value, maskPattern) {
13
- let result = "";
14
- let digitIndex = 0;
15
- for (let i = 0; i < maskPattern.length; i++) {
16
- if (maskPattern[i] === "9") {
17
- if (digitIndex < value.length) {
18
- result += value[digitIndex];
19
- digitIndex++;
20
- }
21
- else {
22
- break;
23
- }
24
- }
25
- else {
26
- if (digitIndex < value.length) {
27
- result += maskPattern[i];
28
- }
29
- else {
30
- break;
31
- }
32
- }
33
- }
34
- return result;
35
- }
36
- function formatPhoneNumber(phoneNumber, country) {
37
- if (country.code === "+55") {
38
- let value = removeNonNumeric(phoneNumber);
39
- const mask = getMask(value);
40
- let nextLength = value.length;
41
- if (nextLength > MAX_LENGTH)
42
- return value;
43
- value = applyMask(value, TYPES[mask]);
44
- return value;
45
- }
46
- const mask = country.mask;
47
- let formattedNumber = mask;
48
- if (country.prefix) {
49
- const prefixRegex = /\$+/g;
50
- formattedNumber = formattedNumber.replace(prefixRegex, country.prefix);
51
- }
52
- for (let i = 0, j = 0; i < formattedNumber.length && j < phoneNumber.length; i++) {
53
- if (formattedNumber[i] === "_") {
54
- formattedNumber =
55
- formattedNumber.substring(0, i) +
56
- phoneNumber[j] +
57
- formattedNumber.substring(i + 1);
58
- j++;
59
- }
60
- }
61
- return formattedNumber;
62
- }
63
- function getCountryWithPrefixCode(countryCode, prefix) {
64
- const country = countries.find((country) => country.code === countryCode && country.prefix === prefix);
65
- if (!country)
66
- throw new Error("Invalid country code or prefix");
67
- if (country.prefix !== prefix) {
68
- throw new Error("Invalid country code or prefix");
69
- }
70
- if (!country.prefix) {
71
- throw new Error("Invalid country code or prefix");
1
+ function formatToPhone(value) {
2
+ const cleaned = value.replace(/\D/g, "");
3
+ const match = cleaned.match(/^(\d{2})(\d{5})(\d{4})$/);
4
+ if (match) {
5
+ return `(${match[1]}) ${match[2]}-${match[3]}`;
72
6
  }
73
- return country;
74
- }
75
- function getCountryWithoutPrefixCode(countryCode) {
76
- const country = countries.find((country) => country.code === countryCode);
77
- if (!country)
78
- throw new Error("Invalid country code");
79
- if (country.prefix)
80
- throw new Error("Invalid country code");
81
- return country;
7
+ return value;
82
8
  }
83
- /**
84
- * Formats a phone number string based on the provided country code and optional prefix.
85
- *
86
- * The input string should follow the format: `"<countryCode>-<prefix> <phoneNumber>"` or `"<countryCode> <phoneNumber>"`.
87
- * The function determines the appropriate formatting mask based on the country and applies it to the phone number.
88
- *
89
- * @param prop - The phone number string to be formatted. It must include the country code and optionally a prefix.
90
- * Example formats:
91
- * - "+55-11 912345678"
92
- * - "+1 1234567890"
93
- *
94
- * @returns The formatted phone number string based on the country's formatting rules.
95
- *
96
- * @throws {Error} If the input phone number does not match the expected format.
97
- * @throws {Error} If the country code or phone number is missing from the input string.
98
- * @throws {Error} If the provided country code and prefix combination is invalid.
99
- * @throws {Error} If the provided country code is invalid.
100
- * @throws {Error} If the provided country code has a prefix but none is supplied in the input.
101
- *
102
- * @example
103
- * ```typescript
104
- * import { formatToPhone } from "./formatToPhone";
105
- *
106
- * const formattedPhone1 = formatToPhone("+55 11912345678");
107
- * console.log(formattedPhone1); // Output: "(11) 91234-5678" (brazilian phone number format)
108
- *
109
- * const formattedPhone2 = formatToPhone("+1-123 4567890");
110
- * console.log(formattedPhone2); // Output: "(123) 456-7890" (us phone number format)
111
- * ```
112
- */
113
- const formatToPhone = (prop) => {
114
- const phoneRegex = /^\+\d{1,4}(-\d{1,4})? \d+$/;
115
- if (!phoneRegex.test(prop)) {
116
- throw new Error("Invalid phone number format. Expected format: +<countryCode>-<optionalPrefix> <phoneNumber>");
117
- }
118
- const countryCode = prop.split(" ")[0].split("-")[0];
119
- const prefixCode = prop.split(" ")[0].split("-")[1];
120
- const phoneNumber = prop.split(" ")[1];
121
- if (!countryCode || !phoneNumber) {
122
- throw new Error("Invalid phone number format");
123
- }
124
- if (prefixCode) {
125
- const country = getCountryWithPrefixCode(countryCode, prefixCode);
126
- return formatPhoneNumber(phoneNumber, country);
127
- }
128
- const country = getCountryWithoutPrefixCode(countryCode);
129
- return formatPhoneNumber(phoneNumber, country);
130
- };
131
9
  export { formatToPhone };
@@ -1,15 +1,3 @@
1
- import type { GenerateColorByStringFunction } from "@arkyn/types";
2
- /**
3
- * Generates a hexadecimal color code based on the input string.
4
- * The function creates a hash from the string and uses it to calculate
5
- * RGB values, which are then converted to a hexadecimal color code.
6
- *
7
- * @param prop - The input string used to generate the color.
8
- * @returns A hexadecimal color code (e.g., "#a1b2c3") derived from the input string.
9
- * @example
10
- * const color = generateColorByString("example");
11
- * console.log(color); // Outputs a consistent hex color like "#5e8f9a"
12
- */
13
- declare const generateColorByString: GenerateColorByStringFunction;
1
+ declare function generateColorByString(string: string): string;
14
2
  export { generateColorByString };
15
3
  //# sourceMappingURL=generateColorByString.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateColorByString.d.ts","sourceRoot":"","sources":["../../src/generators/generateColorByString.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAElE;;;;;;;;;;GAUG;AAEH,QAAA,MAAM,qBAAqB,EAAE,6BAgB5B,CAAC;AAEF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
1
+ {"version":3,"file":"generateColorByString.d.ts","sourceRoot":"","sources":["../../src/generators/generateColorByString.ts"],"names":[],"mappings":"AAAA,iBAAS,qBAAqB,CAAC,MAAM,EAAE,MAAM,UAgB5C;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
@@ -1,18 +1,7 @@
1
- /**
2
- * Generates a hexadecimal color code based on the input string.
3
- * The function creates a hash from the string and uses it to calculate
4
- * RGB values, which are then converted to a hexadecimal color code.
5
- *
6
- * @param prop - The input string used to generate the color.
7
- * @returns A hexadecimal color code (e.g., "#a1b2c3") derived from the input string.
8
- * @example
9
- * const color = generateColorByString("example");
10
- * console.log(color); // Outputs a consistent hex color like "#5e8f9a"
11
- */
12
- const generateColorByString = (prop) => {
1
+ function generateColorByString(string) {
13
2
  var hash = 0;
14
- for (var i = 0; i < prop.length; i++) {
15
- hash = prop.charCodeAt(i) + ((hash << 5) - hash);
3
+ for (var i = 0; i < string.length; i++) {
4
+ hash = string.charCodeAt(i) + ((hash << 5) - hash);
16
5
  }
17
6
  var red = (hash & 0xff0000) >> 16;
18
7
  var green = (hash & 0x00ff00) >> 8;
@@ -21,5 +10,5 @@ const generateColorByString = (prop) => {
21
10
  var greenHex = green.toString(16).padStart(2, "0");
22
11
  var blueHex = blue.toString(16).padStart(2, "0");
23
12
  return "#" + redHex + greenHex + blueHex;
24
- };
13
+ }
25
14
  export { generateColorByString };
@@ -1,28 +1,6 @@
1
- /**
2
- * Generates a unique identifier (UUID) in the specified format and type.
3
- *
4
- * @param type - The desired output type of the UUID. Can be:
5
- * - `"text"`: Returns the UUID as a string.
6
- * - `"binary"`: Returns the UUID as a `Uint8Array` in binary format.
7
- * @param format - The version of the UUID to generate. Can be:
8
- * - `"v4"`: Generates a random UUID (version 4).
9
- * - `"v7"`: Generates a time-ordered UUID (version 7).
10
- * @returns The generated UUID in the specified type and format.
11
- * - If `type` is `"text"`, a string representation of the UUID is returned.
12
- * - If `type` is `"binary"`, a `Uint8Array` representation of the UUID is returned.
13
- * @throws {Error} If an invalid `type` or `format` is provided.
14
- *
15
- * @example
16
- * // Generate a version 4 UUID as a string
17
- * const idTextV4 = generateId("text", "v4");
18
- * console.log(idTextV4); // e.g., "550e8400-e29b-41d4-a716-446655440000"
19
- *
20
- * @example
21
- * // Generate a version 7 UUID as binary
22
- * const idBinaryV7 = generateId("binary", "v7");
23
- * console.log(idBinaryV7); // Uint8Array([...])
24
- */
25
- declare function generateId(type: "text", format: "v4" | "v7"): string;
26
- declare function generateId(type: "binary", format: "v4" | "v7"): Uint8Array;
1
+ declare function generateId(type: "text" | "binary"): {
2
+ v4: string | Uint8Array<ArrayBuffer>;
3
+ v7: string | Uint8Array<ArrayBuffer>;
4
+ };
27
5
  export { generateId };
28
6
  //# sourceMappingURL=generateId.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateId.d.ts","sourceRoot":"","sources":["../../src/generators/generateId.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;AAC/D,iBAAS,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,UAAU,CAAC;AAYrE,OAAO,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"generateId.d.ts","sourceRoot":"","sources":["../../src/generators/generateId.ts"],"names":[],"mappings":"AAsBA,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ;;;EAK1C;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -1,6 +1,5 @@
1
1
  import { v4, v7 } from "uuid";
2
2
  function hexToBin(hex) {
3
- hex = hex.replace(/-/g, "");
4
3
  const buffer = new Uint8Array(hex.length / 2);
5
4
  for (let i = 0; i < hex.length; i += 2) {
6
5
  buffer[i / 2] = parseInt(hex.substring(i, i + 2), 16);
@@ -15,15 +14,10 @@ function uuidV7() {
15
14
  const uuid = v7();
16
15
  return { text: uuid, binary: hexToBin(uuid) };
17
16
  }
18
- function generateId(type, format) {
19
- if (type === "text" && format === "v4")
20
- return uuidV4().text;
21
- if (type === "binary" && format === "v4")
22
- return uuidV4().binary;
23
- if (type === "text" && format === "v7")
24
- return uuidV7().text;
25
- if (type === "binary" && format === "v7")
26
- return uuidV7().binary;
27
- throw new Error("Invalid type or format");
17
+ function generateId(type) {
18
+ return {
19
+ v4: uuidV4()[type],
20
+ v7: uuidV7()[type],
21
+ };
28
22
  }
29
23
  export { generateId };
@@ -1,17 +1,3 @@
1
- /**
2
- * Generates a URL-friendly slug from a given string.
3
- *
4
- * The function performs the following transformations:
5
- * - Normalizes the string to remove diacritical marks (e.g., accents).
6
- * - Removes non-alphanumeric characters except for spaces and hyphens.
7
- * - Replaces spaces with hyphens.
8
- * - Converts the string to lowercase.
9
- * - Collapses multiple consecutive hyphens into a single hyphen.
10
- * - Trims leading and trailing hyphens.
11
- *
12
- * @param string - The input string to be converted into a slug.
13
- * @returns A URL-friendly slug derived from the input string.
14
- */
15
- declare function generateSlug(prop: string): string;
1
+ declare function generateSlug(string: string): string;
16
2
  export { generateSlug };
17
3
  //# sourceMappingURL=generateSlug.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateSlug.d.ts","sourceRoot":"","sources":["../../src/generators/generateSlug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,iBAAS,YAAY,CAAC,IAAI,EAAE,MAAM,UAajC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"generateSlug.d.ts","sourceRoot":"","sources":["../../src/generators/generateSlug.ts"],"names":[],"mappings":"AAAA,iBAAS,YAAY,CAAC,MAAM,EAAE,MAAM,UAanC;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,19 +1,5 @@
1
- /**
2
- * Generates a URL-friendly slug from a given string.
3
- *
4
- * The function performs the following transformations:
5
- * - Normalizes the string to remove diacritical marks (e.g., accents).
6
- * - Removes non-alphanumeric characters except for spaces and hyphens.
7
- * - Replaces spaces with hyphens.
8
- * - Converts the string to lowercase.
9
- * - Collapses multiple consecutive hyphens into a single hyphen.
10
- * - Trims leading and trailing hyphens.
11
- *
12
- * @param string - The input string to be converted into a slug.
13
- * @returns A URL-friendly slug derived from the input string.
14
- */
15
- function generateSlug(prop) {
16
- let slug = prop.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
1
+ function generateSlug(string) {
2
+ let slug = string.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
17
3
  slug = slug
18
4
  .replace(/[^\w\s-]/g, "")
19
5
  .replace(/\s+/g, "-")
package/dist/index.d.ts CHANGED
@@ -1,23 +1,26 @@
1
- export { formatDate } from "./formats/formatDate";
1
+ export { formatBrazilianDateHour } from "./formats/formatBrazilianDateHour";
2
+ export { formatBrazilianDateToDate } from "./formats/formatBrazilianDateToDate";
3
+ export { formatDateHour } from "./formats/formatDateHour";
2
4
  export { formatJsonObject } from "./formats/formatJsonObject";
3
5
  export { formatJsonString } from "./formats/formatJsonString";
6
+ export { formatToBRL } from "./formats/formatToBRL";
4
7
  export { formatToCep } from "./formats/formatToCep";
5
- export { formatToCnpj } from "./formats/formatToCnpj";
6
- export { formatToCpf } from "./formats/formatToCpf";
8
+ export { formatToCNPJ } from "./formats/formatToCNPJ";
9
+ export { formatToCPF } from "./formats/formatToCPF";
7
10
  export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
8
- export { formatToCurrency } from "./formats/formatToCurrency";
9
11
  export { formatToEllipsis } from "./formats/formatToEllipsis";
10
12
  export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
11
13
  export { formatToPhone } from "./formats/formatToPhone";
12
14
  export { generateColorByString } from "./generators/generateColorByString";
13
15
  export { generateId } from "./generators/generateId";
14
16
  export { generateSlug } from "./generators/generateSlug";
15
- export { regex } from "./regex";
17
+ export { parseToCharacters } from "./parsers/parseToCharacters";
16
18
  export { calculateCardInstallment } from "./services/calculateCardInstallment";
17
19
  export { maskSensitiveData } from "./services/maskSensitiveData";
18
- export { removeNonNumeric } from "./services/removeNonNumeric";
20
+ export { normalizeRange, within } from "./services/range";
19
21
  export { truncateLargeFields } from "./services/truncateLargeFields";
20
- export { validateCpf } from "./validations/validateCpf";
22
+ export { regex } from "./validations/regex";
23
+ export { validateCPF } from "./validations/validateCPF";
21
24
  export { validateDate } from "./validations/validateDate";
22
25
  export { validatePhone } from "./validations/validatePhone";
23
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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;AA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
1
- export { formatDate } from "./formats/formatDate";
1
+ // formats
2
+ export { formatBrazilianDateHour } from "./formats/formatBrazilianDateHour";
3
+ export { formatBrazilianDateToDate } from "./formats/formatBrazilianDateToDate";
4
+ export { formatDateHour } from "./formats/formatDateHour";
2
5
  export { formatJsonObject } from "./formats/formatJsonObject";
3
6
  export { formatJsonString } from "./formats/formatJsonString";
7
+ export { formatToBRL } from "./formats/formatToBRL";
4
8
  export { formatToCep } from "./formats/formatToCep";
5
- export { formatToCnpj } from "./formats/formatToCnpj";
6
- export { formatToCpf } from "./formats/formatToCpf";
9
+ export { formatToCNPJ } from "./formats/formatToCNPJ";
10
+ export { formatToCPF } from "./formats/formatToCPF";
7
11
  export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
8
- export { formatToCurrency } from "./formats/formatToCurrency";
9
12
  export { formatToEllipsis } from "./formats/formatToEllipsis";
10
13
  export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
11
14
  export { formatToPhone } from "./formats/formatToPhone";
15
+ // generators
12
16
  export { generateColorByString } from "./generators/generateColorByString";
13
17
  export { generateId } from "./generators/generateId";
14
18
  export { generateSlug } from "./generators/generateSlug";
15
- export { regex } from "./regex";
19
+ // parsers
20
+ export { parseToCharacters } from "./parsers/parseToCharacters";
21
+ // services
16
22
  export { calculateCardInstallment } from "./services/calculateCardInstallment";
17
23
  export { maskSensitiveData } from "./services/maskSensitiveData";
18
- export { removeNonNumeric } from "./services/removeNonNumeric";
24
+ export { normalizeRange, within } from "./services/range";
19
25
  export { truncateLargeFields } from "./services/truncateLargeFields";
20
- export { validateCpf } from "./validations/validateCpf";
26
+ // validations
27
+ export { regex } from "./validations/regex";
28
+ export { validateCPF } from "./validations/validateCPF";
21
29
  export { validateDate } from "./validations/validateDate";
22
30
  export { validatePhone } from "./validations/validatePhone";
@@ -0,0 +1,17 @@
1
+ type DigitCharacterNode = {
2
+ kind: "digit";
3
+ digit: number;
4
+ character: string;
5
+ };
6
+ type OtherCharacterNode = {
7
+ kind: "other";
8
+ character: string;
9
+ };
10
+ type RootCharacterNode = {
11
+ kind: "root";
12
+ digits: number;
13
+ children: (DigitCharacterNode | OtherCharacterNode)[];
14
+ };
15
+ declare const parseToCharacters: (value: string) => RootCharacterNode;
16
+ export { parseToCharacters };
17
+ //# sourceMappingURL=parseToCharacters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseToCharacters.d.ts","sourceRoot":"","sources":["../../src/parsers/parseToCharacters.ts"],"names":[],"mappings":"AAEA,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,CAAC,kBAAkB,GAAG,kBAAkB,CAAC,EAAE,CAAC;CACvD,CAAC;AAEF,QAAA,MAAM,iBAAiB,GAAI,OAAO,MAAM,KAAG,iBAY1C,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,13 @@
1
+ const DIGIT = /^\d$/;
2
+ const parseToCharacters = (value) => {
3
+ let digits = 0;
4
+ const children = value
5
+ .split("")
6
+ .map((character) => {
7
+ if (DIGIT.test(character))
8
+ return { character, kind: "digit", digit: ++digits };
9
+ return { character, kind: "other" };
10
+ });
11
+ return { digits, children, kind: "root" };
12
+ };
13
+ export { parseToCharacters };
@@ -1,33 +1,7 @@
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;
1
+ import type { CalculateCardInstallmentProps } from "@arkyn/types";
2
+ declare function calculateCardInstallment(args: CalculateCardInstallmentProps): {
3
+ total_price: number;
4
+ installment_price: number;
5
+ };
32
6
  export { calculateCardInstallment };
33
7
  //# 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,gCAAgC,EAAE,MAAM,cAAc,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,QAAA,MAAM,wBAAwB,EAAE,gCA+B/B,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
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,55 +1,14 @@
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;
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;
50
9
  return {
51
- totalPrice: +totalPrice.toFixed(2),
52
- installmentPrice: +installmentPrice.toFixed(2),
10
+ total_price: +total_price.toFixed(2),
11
+ installment_price: +installment_price.toFixed(2),
53
12
  };
54
- };
13
+ }
55
14
  export { calculateCardInstallment };