@arkyn/shared 3.0.1-beta.159 → 3.0.1-beta.166

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 (29) hide show
  1. package/dist/generators/generateId.d.ts.map +1 -1
  2. package/dist/index.js +343 -344
  3. package/dist/modules/formats/formatDate.js +33 -40
  4. package/dist/modules/formats/formatJsonObject.js +22 -31
  5. package/dist/modules/formats/formatJsonString.js +10 -12
  6. package/dist/modules/formats/formatToCapitalizeFirstWordLetter.js +5 -8
  7. package/dist/modules/formats/formatToCep.js +8 -8
  8. package/dist/modules/formats/formatToCnpj.js +8 -8
  9. package/dist/modules/formats/formatToCpf.js +8 -8
  10. package/dist/modules/formats/formatToCurrency.js +12 -14
  11. package/dist/modules/formats/formatToEllipsis.js +9 -10
  12. package/dist/modules/formats/formatToHiddenDigits.js +21 -11
  13. package/dist/modules/formats/formatToPhone.js +13 -16
  14. package/dist/modules/generators/generateColorByString.js +7 -8
  15. package/dist/modules/generators/generateId.js +28 -22
  16. package/dist/modules/generators/generateSlug.js +6 -6
  17. package/dist/modules/index.js +26 -52
  18. package/dist/modules/parsers/parseLargeFields.js +16 -21
  19. package/dist/modules/parsers/parseSensitiveData.js +27 -25
  20. package/dist/modules/parsers/parseToDate.js +22 -26
  21. package/dist/modules/services/validateDateService.js +60 -58
  22. package/dist/modules/utilities/calculateCardInstallment.js +16 -20
  23. package/dist/modules/utilities/ensureQuotes.js +6 -6
  24. package/dist/modules/utilities/findCountryMask.js +22 -24
  25. package/dist/modules/utilities/isHtml.js +5 -5
  26. package/dist/modules/utilities/removeCurrencySymbols.js +5 -5
  27. package/dist/modules/utilities/removeNonNumeric.js +5 -5
  28. package/dist/modules/utilities/stripHtmlTags.js +5 -5
  29. package/package.json +16 -12
package/dist/index.js CHANGED
@@ -1,371 +1,370 @@
1
- import { countryCurrencies as y, countries as S } from "@arkyn/templates";
2
- import { parsePhoneNumberWithError as D } from "libphonenumber-js";
3
- import { v4 as $, v7 as N } from "uuid";
4
- class v {
5
- isLeapYear(r) {
6
- return r % 4 === 0 && r % 100 !== 0 || r % 400 === 0;
7
- }
8
- getDaysInMonth(r, e) {
9
- const n = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
10
- return r === 2 && this.isLeapYear(e) ? 29 : n[r - 1];
11
- }
12
- validateDayInMonth(r, e, n) {
13
- const a = this.getDaysInMonth(e, n);
14
- if (r > a) {
15
- const o = `Day ${r} is not valid for ${[
16
- "January",
17
- "February",
18
- "March",
19
- "April",
20
- "May",
21
- "June",
22
- "July",
23
- "August",
24
- "September",
25
- "October",
26
- "November",
27
- "December"
28
- ][e - 1]}`, i = `Day ${r} is not valid for February ${n} (non-leap year)`;
29
- throw e === 2 && r === 29 ? new Error(i) : new Error(o);
30
- }
31
- }
32
- /**
33
- * Throws if year, month, or day are out of valid range or inconsistent with the calendar.
34
- *
35
- * @param year - 4-digit year (1000–9999).
36
- * @param month - Month number (1–12).
37
- * @param day - Day number (1–31, validated against the specific month).
38
- */
39
- validateDateParts(r, e, n) {
40
- const a = {
41
- year: "Year should be four digits",
42
- month: "Month should be between 1 and 12",
43
- day: "Day should be between 1 and 31"
44
- };
45
- if (`${r}`.length !== 4) throw new Error(a.year);
46
- if (e < 1 || e > 12) throw new Error(a.month);
47
- if (n < 1 || n > 31) throw new Error(a.day);
48
- this.validateDayInMonth(n, e, r);
49
- }
50
- /**
51
- * Throws if `format` is not one of `"brazilianDate"`, `"isoDate"`, or `"timestamp"`.
52
- *
53
- * @param format - The format string to check.
54
- */
55
- validateInputFormat(r) {
56
- if (!["brazilianDate", "isoDate", "timestamp"].includes(r))
57
- throw new Error(`Invalid input format: ${r}`);
58
- }
59
- }
60
- function E(t, r) {
61
- const e = (a) => a.toString().padStart(2, "0"), n = {
62
- YYYY: t.getUTCFullYear().toString(),
63
- YY: t.getUTCFullYear().toString().slice(-2),
64
- MM: e(t.getUTCMonth() + 1),
65
- DD: e(t.getUTCDate()),
66
- hh: e(t.getUTCHours()),
67
- mm: e(t.getUTCMinutes()),
68
- ss: e(t.getUTCSeconds())
69
- };
70
- return r.replace(
71
- /YYYY|YY|MM|DD|hh|mm|ss/g,
72
- (a) => n[a]
73
- );
1
+ import { countries as e, countryCurrencies as t } from "@arkyn/templates";
2
+ import { parsePhoneNumberWithError as n } from "libphonenumber-js";
3
+ //#region src/services/validateDateService.ts
4
+ var r = class {
5
+ isLeapYear(e) {
6
+ return e % 4 == 0 && e % 100 != 0 || e % 400 == 0;
7
+ }
8
+ getDaysInMonth(e, t) {
9
+ return e === 2 && this.isLeapYear(t) ? 29 : [
10
+ 31,
11
+ 28,
12
+ 31,
13
+ 30,
14
+ 31,
15
+ 30,
16
+ 31,
17
+ 31,
18
+ 30,
19
+ 31,
20
+ 30,
21
+ 31
22
+ ][e - 1];
23
+ }
24
+ validateDayInMonth(e, t, n) {
25
+ if (e > this.getDaysInMonth(t, n)) {
26
+ let r = `Day ${e} is not valid for ${[
27
+ "January",
28
+ "February",
29
+ "March",
30
+ "April",
31
+ "May",
32
+ "June",
33
+ "July",
34
+ "August",
35
+ "September",
36
+ "October",
37
+ "November",
38
+ "December"
39
+ ][t - 1]}`, i = `Day ${e} is not valid for February ${n} (non-leap year)`;
40
+ throw Error(t === 2 && e === 29 ? i : r);
41
+ }
42
+ }
43
+ validateDateParts(e, t, n) {
44
+ let r = {
45
+ year: "Year should be four digits",
46
+ month: "Month should be between 1 and 12",
47
+ day: "Day should be between 1 and 31"
48
+ };
49
+ if (`${e}`.length !== 4) throw Error(r.year);
50
+ if (t < 1 || t > 12) throw Error(r.month);
51
+ if (n < 1 || n > 31) throw Error(r.day);
52
+ this.validateDayInMonth(n, t, e);
53
+ }
54
+ validateInputFormat(e) {
55
+ if (![
56
+ "brazilianDate",
57
+ "isoDate",
58
+ "timestamp"
59
+ ].includes(e)) throw Error(`Invalid input format: ${e}`);
60
+ }
61
+ };
62
+ //#endregion
63
+ //#region src/formats/formatDate.ts
64
+ function i(e, t) {
65
+ let n = (e) => e.toString().padStart(2, "0"), r = {
66
+ YYYY: e.getUTCFullYear().toString(),
67
+ YY: e.getUTCFullYear().toString().slice(-2),
68
+ MM: n(e.getUTCMonth() + 1),
69
+ DD: n(e.getUTCDate()),
70
+ hh: n(e.getUTCHours()),
71
+ mm: n(e.getUTCMinutes()),
72
+ ss: n(e.getUTCSeconds())
73
+ };
74
+ return t.replace(/YYYY|YY|MM|DD|hh|mm|ss/g, (e) => r[e]);
74
75
  }
75
- function x([t, r = "00:00:00"], e, n, a = 0) {
76
- const s = new v();
77
- s.validateInputFormat(e);
78
- const o = t.split(/[-/]/).map(Number), i = r.split(".")[0].split(":").map(Number);
79
- let c, u, l;
80
- const [g = 0, p = 0, f = 0] = i;
81
- switch (e) {
82
- case "brazilianDate":
83
- [c, u, l] = o, s.validateDateParts(l, u, c);
84
- break;
85
- case "isoDate":
86
- [u, c, l] = o, s.validateDateParts(l, u, c);
87
- break;
88
- case "timestamp":
89
- [l, u, c] = o, s.validateDateParts(l, u, c);
90
- break;
91
- }
92
- const d = new Date(
93
- Date.UTC(l, u - 1, c, g, p, f)
94
- );
95
- if (isNaN(d.getTime())) throw new Error("Invalid date");
96
- return d.setUTCHours(d.getUTCHours() + a), E(d, n);
76
+ function a([e, t = "00:00:00"], n, a, o = 0) {
77
+ let s = new r();
78
+ s.validateInputFormat(n);
79
+ let c = e.split(/[-/]/).map(Number), l = t.split(".")[0].split(":").map(Number), u, d, f, [p = 0, m = 0, h = 0] = l;
80
+ switch (n) {
81
+ case "brazilianDate":
82
+ [u, d, f] = c, s.validateDateParts(f, d, u);
83
+ break;
84
+ case "isoDate":
85
+ [d, u, f] = c, s.validateDateParts(f, d, u);
86
+ break;
87
+ case "timestamp":
88
+ [f, d, u] = c, s.validateDateParts(f, d, u);
89
+ break;
90
+ }
91
+ let g = new Date(Date.UTC(f, d - 1, u, p, m, h));
92
+ if (isNaN(g.getTime())) throw Error("Invalid date");
93
+ return g.setUTCHours(g.getUTCHours() + o), i(g, a);
97
94
  }
98
- const m = (t, r) => {
99
- const e = " ".repeat(r);
100
- let n = "";
101
- if (typeof t == "object" && t !== null)
102
- if (Array.isArray(t))
103
- t.length === 0 ? n += "[]" : (n += `[
104
- `, t.forEach((a, s) => {
105
- n += e + " " + m(a, r + 1), s < t.length - 1 && (n += ","), n += `
106
- `;
107
- }), n += e + "]");
108
- else {
109
- const a = Object.keys(t);
110
- a.length === 0 ? n += "{}" : (n += `{
111
- `, a.forEach((s, o) => {
112
- n += e + ' "' + s + '": ' + m(t[s], r + 1), o < a.length - 1 && (n += ","), n += `
113
- `;
114
- }), n += e + "}");
115
- }
116
- else if (typeof t == "string")
117
- try {
118
- const a = JSON.parse(t);
119
- n += m(a, r);
120
- } catch {
121
- n += '"' + t + '"';
122
- }
123
- else
124
- n += t;
125
- return n;
126
- }, U = (t) => {
127
- try {
128
- const r = JSON.parse(t);
129
- return m(r, 0);
130
- } catch (r) {
131
- throw new Error(`Invalid JSON string
132
- ${r}`);
133
- }
95
+ //#endregion
96
+ //#region src/formats/formatJsonObject.ts
97
+ var o = (e, t) => {
98
+ let n = " ".repeat(t), r = "";
99
+ if (typeof e == "object" && e) if (Array.isArray(e)) e.length === 0 ? r += "[]" : (r += "[\n", e.forEach((i, a) => {
100
+ r += n + " " + o(i, t + 1), a < e.length - 1 && (r += ","), r += "\n";
101
+ }), r += n + "]");
102
+ else {
103
+ let i = Object.keys(e);
104
+ i.length === 0 ? r += "{}" : (r += "{\n", i.forEach((a, s) => {
105
+ r += n + " \"" + a + "\": " + o(e[a], t + 1), s < i.length - 1 && (r += ","), r += "\n";
106
+ }), r += n + "}");
107
+ }
108
+ else if (typeof e == "string") try {
109
+ let n = JSON.parse(e);
110
+ r += o(n, t);
111
+ } catch {
112
+ r += "\"" + e + "\"";
113
+ }
114
+ else r += e;
115
+ return r;
116
+ }, s = (e) => {
117
+ try {
118
+ return o(JSON.parse(e), 0);
119
+ } catch (e) {
120
+ throw Error(`Invalid JSON string \n ${e}`);
121
+ }
134
122
  };
135
- function A(t) {
136
- return t.split(" ").map((n) => {
137
- const a = n.charAt(0).toUpperCase(), s = n.slice(1).toLowerCase();
138
- return a + s;
139
- }).join(" ");
123
+ //#endregion
124
+ //#region src/formats/formatToCapitalizeFirstWordLetter.ts
125
+ function c(e) {
126
+ return e.split(" ").map((e) => e.charAt(0).toUpperCase() + e.slice(1).toLowerCase()).join(" ");
140
127
  }
141
- function h(t) {
142
- return t.replace(/[^0-9]/g, "");
128
+ //#endregion
129
+ //#region src/utilities/removeNonNumeric.ts
130
+ function l(e) {
131
+ return e.replace(/[^0-9]/g, "");
143
132
  }
144
- function z(t) {
145
- const e = h(t).match(/^(\d{5})(\d{3})$/), n = `CEP must be contain 8 numeric digits: ${t}`;
146
- if (!e) throw new Error(n);
147
- return `${e[1]}-${e[2]}`;
133
+ //#endregion
134
+ //#region src/formats/formatToCep.ts
135
+ function u(e) {
136
+ let t = l(e).match(/^(\d{5})(\d{3})$/), n = `CEP must be contain 8 numeric digits: ${e}`;
137
+ if (!t) throw Error(n);
138
+ return `${t[1]}-${t[2]}`;
148
139
  }
149
- function H(t) {
150
- const e = h(t).match(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/), n = `CNPJ must be contain 14 numeric digits: ${t}`;
151
- if (!e) throw new Error(n);
152
- return `${e[1]}.${e[2]}.${e[3]}/${e[4]}-${e[5]}`;
140
+ //#endregion
141
+ //#region src/formats/formatToCnpj.ts
142
+ function d(e) {
143
+ let t = l(e).match(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/), n = `CNPJ must be contain 14 numeric digits: ${e}`;
144
+ if (!t) throw Error(n);
145
+ return `${t[1]}.${t[2]}.${t[3]}/${t[4]}-${t[5]}`;
153
146
  }
154
- function W(t) {
155
- const e = h(t).match(/^(\d{3})(\d{3})(\d{3})(\d{2})$/), n = `CPF must be contain 11 numeric digits: ${t}`;
156
- if (!e) throw new Error(n);
157
- return `${e[1]}.${e[2]}.${e[3]}-${e[4]}`;
147
+ //#endregion
148
+ //#region src/formats/formatToCpf.ts
149
+ function f(e) {
150
+ let t = l(e).match(/^(\d{3})(\d{3})(\d{3})(\d{2})$/), n = `CPF must be contain 11 numeric digits: ${e}`;
151
+ if (!t) throw Error(n);
152
+ return `${t[1]}.${t[2]}.${t[3]}-${t[4]}`;
158
153
  }
159
- function T(t) {
160
- return t.replace(new RegExp("(?:R\\$|\\p{Sc}|[$€¥£])", "gu"), "").trim();
154
+ //#endregion
155
+ //#region src/utilities/removeCurrencySymbols.ts
156
+ function p(e) {
157
+ return e.replace(/(?:R\$|\p{Sc}|[$€¥£])/gu, "").trim();
161
158
  }
162
- function L(t, r, e) {
163
- var i;
164
- if (!((i = y) != null && i[r]))
165
- throw new Error("Unsupported currency code");
166
- const n = (e == null ? void 0 : e.showPrefix) ?? !0, { countryCurrency: a, countryLanguage: s } = y[r], o = new Intl.NumberFormat(s, {
167
- style: "currency",
168
- currency: a
169
- }).format(t);
170
- return n ? o.replace(/\s/g, " ") : T(o).replace(/\s/g, " ");
159
+ //#endregion
160
+ //#region src/formats/formatToCurrency.ts
161
+ function m(e, n, r) {
162
+ if (!t?.[n]) throw Error("Unsupported currency code");
163
+ let i = r?.showPrefix ?? !0, { countryCurrency: a, countryLanguage: o } = t[n], s = new Intl.NumberFormat(o, {
164
+ style: "currency",
165
+ currency: a
166
+ }).format(e);
167
+ return i ? s.replace(/\s/g, " ") : p(s).replace(/\s/g, " ");
171
168
  }
172
- function R(t, r) {
173
- if (t.length > r) {
174
- let e = t.substring(0, r);
175
- const n = e.lastIndexOf(" ");
176
- return n > 0 && (e = e.substring(0, n)), e = e.replace(/[\s.,!?;:]+$/, ""), e.trim().length === 0 || /^[.,!?;:\s]+$/.test(e) ? "..." : `${e}...`;
177
- }
178
- return t;
169
+ //#endregion
170
+ //#region src/formats/formatToEllipsis.ts
171
+ function h(e, t) {
172
+ if (e.length > t) {
173
+ let n = e.substring(0, t), r = n.lastIndexOf(" ");
174
+ return r > 0 && (n = n.substring(0, r)), n = n.replace(/[\s.,!?;:]+$/, ""), n.trim().length === 0 || /^[.,!?;:\s]+$/.test(n) ? "..." : `${n}...`;
175
+ }
176
+ return e;
179
177
  }
180
- const P = /^\d$/, I = (t) => {
181
- let r = 0;
182
- const e = t.split("").map((n) => P.test(n) ? { character: n, kind: "digit", digit: ++r } : { character: n, kind: "other" });
183
- return { digits: r, children: e, kind: "root" };
184
- }, M = (t, r) => Array.isArray(t) ? t : t >= 0 ? [0, t] : [r + 1 - Math.abs(t), r], O = (t, r) => r >= t[0] && r <= t[1];
185
- function Q(t, r) {
186
- const e = I(t), n = M((r == null ? void 0 : r.range) ?? 3, e.digits);
187
- return e.children.map((s) => s.kind === "digit" && O(n, s.digit) ? (r == null ? void 0 : r.hider) ?? "*" : s.character).join("");
178
+ //#endregion
179
+ //#region src/formats/formatToHiddenDigits.ts
180
+ var g = /^\d$/, _ = (e) => {
181
+ let t = 0, n = e.split("").map((e) => g.test(e) ? {
182
+ character: e,
183
+ kind: "digit",
184
+ digit: ++t
185
+ } : {
186
+ character: e,
187
+ kind: "other"
188
+ });
189
+ return {
190
+ digits: t,
191
+ children: n,
192
+ kind: "root"
193
+ };
194
+ }, v = (e, t) => Array.isArray(e) ? e : e >= 0 ? [0, e] : [t + 1 - Math.abs(e), t], y = (e, t) => t >= e[0] && t <= e[1];
195
+ function b(e, t) {
196
+ let n = _(e), r = v(t?.range ?? 3, n.digits);
197
+ return n.children.map((e) => e.kind === "digit" && y(r, e.digit) ? t?.hider ?? "*" : e.character).join("");
188
198
  }
189
- function k(t) {
190
- try {
191
- const r = D(t), e = r == null ? void 0 : r.country;
192
- if (!e) throw new Error("Invalid phone number");
193
- const n = S.find((s) => s.iso === e);
194
- if (!n) throw new Error("Phone number country not supported");
195
- if (typeof n.mask == "string") return [n.mask, n];
196
- const a = n.mask.find((s) => {
197
- const o = s.replace(/[^_]/g, ""), i = h(r.nationalNumber), c = o.length, u = i.length;
198
- return c === u;
199
- });
200
- if (!a)
201
- throw new Error("No mask found for the given phone number length");
202
- return [a, n];
203
- } catch (r) {
204
- const e = r;
205
- throw new Error(e.message);
206
- }
199
+ //#endregion
200
+ //#region src/utilities/findCountryMask.ts
201
+ function x(t) {
202
+ try {
203
+ let r = n(t), i = r?.country;
204
+ if (!i) throw Error("Invalid phone number");
205
+ let a = e.find((e) => e.iso === i);
206
+ if (!a) throw Error("Phone number country not supported");
207
+ if (typeof a.mask == "string") return [a.mask, a];
208
+ let o = a.mask.find((e) => {
209
+ let t = e.replace(/[^_]/g, ""), n = l(r.nationalNumber);
210
+ return t.length === n.length;
211
+ });
212
+ if (!o) throw Error("No mask found for the given phone number length");
213
+ return [o, a];
214
+ } catch (e) {
215
+ throw Error(e.message);
216
+ }
207
217
  }
208
- function B(t) {
209
- try {
210
- const e = D(t).nationalNumber.toString();
211
- let n = k(t)[0];
212
- for (let a = 0, s = 0; a < n.length && s < e.length; a++)
213
- n[a] === "_" && (n = n.substring(0, a) + e[s] + n.substring(a + 1), s++);
214
- return n;
215
- } catch (r) {
216
- const e = r;
217
- throw new Error(e.message);
218
- }
218
+ //#endregion
219
+ //#region src/formats/formatToPhone.ts
220
+ function S(e) {
221
+ try {
222
+ let t = n(e).nationalNumber.toString(), r = x(e)[0];
223
+ for (let e = 0, n = 0; e < r.length && n < t.length; e++) r[e] === "_" && (r = r.substring(0, e) + t[n] + r.substring(e + 1), n++);
224
+ return r;
225
+ } catch (e) {
226
+ throw Error(e.message);
227
+ }
219
228
  }
220
- function _(t) {
221
- for (var r = 0, e = 0; e < t.length; e++)
222
- r = t.charCodeAt(e) + ((r << 5) - r);
223
- var n = (r & 16711680) >> 16, a = (r & 65280) >> 8, s = r & 255, o = n.toString(16).padStart(2, "0"), i = a.toString(16).padStart(2, "0"), c = s.toString(16).padStart(2, "0");
224
- return "#" + o + i + c;
229
+ //#endregion
230
+ //#region src/generators/generateColorByString.ts
231
+ function C(e) {
232
+ for (var t = 0, n = 0; n < e.length; n++) t = e.charCodeAt(n) + ((t << 5) - t);
233
+ var r = (t & 16711680) >> 16, i = (t & 65280) >> 8, a = t & 255, o = r.toString(16).padStart(2, "0"), s = i.toString(16).padStart(2, "0"), c = a.toString(16).padStart(2, "0");
234
+ return "#" + o + s + c;
225
235
  }
226
- function C(t) {
227
- t = t.replace(/-/g, "");
228
- const r = new Uint8Array(t.length / 2);
229
- for (let e = 0; e < t.length; e += 2)
230
- r[e / 2] = parseInt(t.substring(e, e + 2), 16);
231
- return r;
236
+ //#endregion
237
+ //#region src/generators/generateId.ts
238
+ function w(e) {
239
+ e = e.replace(/-/g, "");
240
+ let t = new Uint8Array(e.length / 2);
241
+ for (let n = 0; n < e.length; n += 2) t[n / 2] = parseInt(e.substring(n, n + 2), 16);
242
+ return t;
232
243
  }
233
- function w() {
234
- const t = $();
235
- return { text: t, binary: C(t) };
244
+ function T() {
245
+ let e = crypto.randomUUID();
246
+ return {
247
+ text: e,
248
+ binary: w(e)
249
+ };
236
250
  }
237
- function b() {
238
- const t = N();
239
- return { text: t, binary: C(t) };
251
+ function E() {
252
+ let e = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16)), t = BigInt(Date.now());
253
+ e[0] = Number(t >> 40n & 255n), e[1] = Number(t >> 32n & 255n), e[2] = Number(t >> 24n & 255n), e[3] = Number(t >> 16n & 255n), e[4] = Number(t >> 8n & 255n), e[5] = Number(t & 255n), e[6] = e[6] & 15 | 112, e[8] = e[8] & 63 | 128;
254
+ let n = [...e].map((e) => e.toString(16).padStart(2, "0")).join("").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
255
+ return {
256
+ text: n,
257
+ binary: w(n)
258
+ };
240
259
  }
241
- function q(t, r) {
242
- if (t === "text" && r === "v4") return w().text;
243
- if (t === "binary" && r === "v4") return w().binary;
244
- if (t === "text" && r === "v7") return b().text;
245
- if (t === "binary" && r === "v7") return b().binary;
246
- throw new Error("Invalid type or format");
260
+ function D(e, t) {
261
+ if (e === "text" && t === "v4") return T().text;
262
+ if (e === "binary" && t === "v4") return T().binary;
263
+ if (e === "text" && t === "v7") return E().text;
264
+ if (e === "binary" && t === "v7") return E().binary;
265
+ throw Error("Invalid type or format");
247
266
  }
248
- function G(t) {
249
- let r = t.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
250
- return r = r.replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").toLowerCase(), r = r.replace(/-{2,}/g, "-"), r = r.replace(/^-+|-+$/g, ""), r;
267
+ //#endregion
268
+ //#region src/generators/generateSlug.ts
269
+ function O(e) {
270
+ let t = e.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
271
+ return t = t.replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").toLowerCase(), t = t.replace(/-{2,}/g, "-"), t = t.replace(/^-+|-+$/g, ""), t;
251
272
  }
252
- function V(t, r = 1e3) {
253
- function e(a) {
254
- return typeof a == "string" && a.length > r ? `To large information: field as ${a.length} characters` : a;
255
- }
256
- function n(a) {
257
- return Array.isArray(a) ? a.map((s) => n(s)) : a !== null && typeof a == "object" ? Object.fromEntries(
258
- Object.entries(a).map(([s, o]) => [
259
- s,
260
- n(o)
261
- ])
262
- ) : e(a);
263
- }
264
- try {
265
- const a = JSON.parse(t), s = n(a);
266
- return JSON.stringify(s);
267
- } catch {
268
- throw new Error("Invalid JSON string");
269
- }
273
+ //#endregion
274
+ //#region src/parsers/parseLargeFields.ts
275
+ function k(e, t = 1e3) {
276
+ function n(e) {
277
+ return typeof e == "string" && e.length > t ? `To large information: field as ${e.length} characters` : e;
278
+ }
279
+ function r(e) {
280
+ return Array.isArray(e) ? e.map((e) => r(e)) : typeof e == "object" && e ? Object.fromEntries(Object.entries(e).map(([e, t]) => [e, r(t)])) : n(e);
281
+ }
282
+ try {
283
+ let t = r(JSON.parse(e));
284
+ return JSON.stringify(t);
285
+ } catch {
286
+ throw Error("Invalid JSON string");
287
+ }
270
288
  }
271
- function K(t, r = ["password", "confirmPassword", "creditCard"]) {
272
- function e(a, s) {
273
- return r.includes(a) ? "****" : s;
274
- }
275
- function n(a) {
276
- return Array.isArray(a) ? a.map((s) => n(s)) : a !== null && typeof a == "object" ? Object.keys(a).reduce((s, o) => {
277
- let i = a[o];
278
- if (typeof i == "string")
279
- try {
280
- const c = JSON.parse(i);
281
- typeof c == "object" && (i = JSON.stringify(n(c)));
282
- } catch {
283
- }
284
- return s[o] = n(e(o, i)), s;
285
- }, {}) : a;
286
- }
287
- try {
288
- const a = JSON.parse(t), s = n(a);
289
- return JSON.stringify(s);
290
- } catch {
291
- return t;
292
- }
289
+ //#endregion
290
+ //#region src/parsers/parseSensitiveData.ts
291
+ function A(e, t = [
292
+ "password",
293
+ "confirmPassword",
294
+ "creditCard"
295
+ ]) {
296
+ function n(e, n) {
297
+ return t.includes(e) ? "****" : n;
298
+ }
299
+ function r(e) {
300
+ return Array.isArray(e) ? e.map((e) => r(e)) : typeof e == "object" && e ? Object.keys(e).reduce((t, i) => {
301
+ let a = e[i];
302
+ if (typeof a == "string") try {
303
+ let e = JSON.parse(a);
304
+ typeof e == "object" && (a = JSON.stringify(r(e)));
305
+ } catch {}
306
+ return t[i] = r(n(i, a)), t;
307
+ }, {}) : e;
308
+ }
309
+ try {
310
+ let t = r(JSON.parse(e));
311
+ return JSON.stringify(t);
312
+ } catch {
313
+ return e;
314
+ }
293
315
  }
294
- function X([t, r = "00:00:00"], e, n = 0) {
295
- const a = new v();
296
- a.validateInputFormat(e);
297
- const s = t.split(/[-/]/).map(Number), o = r.split(".")[0].split(":").map(Number);
298
- let i, c, u;
299
- const [l = 0, g = 0, p = 0] = o;
300
- switch (e) {
301
- case "brazilianDate":
302
- [i, c, u] = s, a.validateDateParts(u, c, i);
303
- break;
304
- case "isoDate":
305
- [c, i, u] = s, a.validateDateParts(u, c, i);
306
- break;
307
- case "timestamp":
308
- [u, c, i] = s, a.validateDateParts(u, c, i);
309
- break;
310
- }
311
- const f = new Date(
312
- Date.UTC(u, c - 1, i, l, g, p)
313
- );
314
- if (isNaN(f.getTime())) throw new Error("Invalid date");
315
- return f.setUTCHours(f.getUTCHours() + n), f;
316
+ //#endregion
317
+ //#region src/parsers/parseToDate.ts
318
+ function j([e, t = "00:00:00"], n, i = 0) {
319
+ let a = new r();
320
+ a.validateInputFormat(n);
321
+ let o = e.split(/[-/]/).map(Number), s = t.split(".")[0].split(":").map(Number), c, l, u, [d = 0, f = 0, p = 0] = s;
322
+ switch (n) {
323
+ case "brazilianDate":
324
+ [c, l, u] = o, a.validateDateParts(u, l, c);
325
+ break;
326
+ case "isoDate":
327
+ [l, c, u] = o, a.validateDateParts(u, l, c);
328
+ break;
329
+ case "timestamp":
330
+ [u, l, c] = o, a.validateDateParts(u, l, c);
331
+ break;
332
+ }
333
+ let m = new Date(Date.UTC(u, l - 1, c, d, f, p));
334
+ if (isNaN(m.getTime())) throw Error("Invalid date");
335
+ return m.setUTCHours(m.getUTCHours() + i), m;
316
336
  }
317
- function Z(t) {
318
- const { cashPrice: r, numberInstallments: e, fees: n = 0.0349 } = t;
319
- if (n === 0 || e === 1)
320
- return {
321
- totalPrice: r,
322
- installmentPrice: r / e
323
- };
324
- if (e <= 0)
325
- throw new Error("Number of installments must be greater than 0");
326
- if (n < 0)
327
- throw new Error("Fees must be greater than or equal to 0");
328
- let a = Math.pow(1 + n, e) * n, s = Math.pow(1 + n, e) - 1;
329
- const o = +(r * (a / s)).toFixed(2);
330
- return {
331
- totalPrice: +(+(o * e).toFixed(2)).toFixed(2),
332
- installmentPrice: +o.toFixed(2)
333
- };
337
+ //#endregion
338
+ //#region src/utilities/calculateCardInstallment.ts
339
+ function M(e) {
340
+ let { cashPrice: t, numberInstallments: n, fees: r = .0349 } = e;
341
+ if (r === 0 || n === 1) return {
342
+ totalPrice: t,
343
+ installmentPrice: t / n
344
+ };
345
+ if (n <= 0) throw Error("Number of installments must be greater than 0");
346
+ if (r < 0) throw Error("Fees must be greater than or equal to 0");
347
+ let i = +(t * ((1 + r) ** +n * r / ((1 + r) ** +n - 1))).toFixed(2);
348
+ return {
349
+ totalPrice: +(+(i * n).toFixed(2)).toFixed(2),
350
+ installmentPrice: +i.toFixed(2)
351
+ };
334
352
  }
335
- function j(t) {
336
- const r = t.startsWith("'") && t.endsWith("'"), e = t.startsWith('"') && t.endsWith('"');
337
- return r || e ? t : `"${t}"`;
353
+ //#endregion
354
+ //#region src/utilities/ensureQuotes.ts
355
+ function N(e) {
356
+ let t = e.startsWith("'") && e.endsWith("'"), n = e.startsWith("\"") && e.endsWith("\"");
357
+ return t || n ? e : `"${e}"`;
338
358
  }
339
- function tt(t) {
340
- return /<\/?[a-z][\s\S]*>/i.test(t);
359
+ //#endregion
360
+ //#region src/utilities/isHtml.ts
361
+ function P(e) {
362
+ return /<\/?[a-z][\s\S]*>/i.test(e);
341
363
  }
342
- function rt(t) {
343
- return t.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, "").replace(/<!--[\s\S]*?-->/g, "").replace(/<\/?[a-z][a-z0-9]*[^>]*>/gi, "");
364
+ //#endregion
365
+ //#region src/utilities/stripHtmlTags.ts
366
+ function F(e) {
367
+ return e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, "").replace(/<!--[\s\S]*?-->/g, "").replace(/<\/?[a-z][a-z0-9]*[^>]*>/gi, "");
344
368
  }
345
- export {
346
- v as ValidateDateService,
347
- Z as calculateCardInstallment,
348
- j as ensureQuotes,
349
- k as findCountryMask,
350
- x as formatDate,
351
- m as formatJsonObject,
352
- U as formatJsonString,
353
- A as formatToCapitalizeFirstWordLetter,
354
- z as formatToCep,
355
- H as formatToCnpj,
356
- W as formatToCpf,
357
- L as formatToCurrency,
358
- R as formatToEllipsis,
359
- Q as formatToHiddenDigits,
360
- B as formatToPhone,
361
- _ as generateColorByString,
362
- q as generateId,
363
- G as generateSlug,
364
- tt as isHtml,
365
- V as parseLargeFields,
366
- K as parseSensitiveData,
367
- X as parseToDate,
368
- T as removeCurrencySymbols,
369
- h as removeNonNumeric,
370
- rt as stripHtmlTags
371
- };
369
+ //#endregion
370
+ export { r as ValidateDateService, M as calculateCardInstallment, N as ensureQuotes, x as findCountryMask, a as formatDate, o as formatJsonObject, s as formatJsonString, c as formatToCapitalizeFirstWordLetter, u as formatToCep, d as formatToCnpj, f as formatToCpf, m as formatToCurrency, h as formatToEllipsis, b as formatToHiddenDigits, S as formatToPhone, C as generateColorByString, D as generateId, O as generateSlug, P as isHtml, k as parseLargeFields, A as parseSensitiveData, j as parseToDate, p as removeCurrencySymbols, l as removeNonNumeric, F as stripHtmlTags };