@arkyn/shared 3.0.1-beta.154 → 3.0.1-beta.156

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 (55) hide show
  1. package/dist/index.js +371 -30
  2. package/dist/modules/formats/formatDate.js +42 -0
  3. package/dist/modules/formats/formatJsonObject.js +32 -0
  4. package/dist/modules/formats/formatJsonString.js +13 -0
  5. package/dist/modules/formats/formatToCapitalizeFirstWordLetter.js +9 -0
  6. package/dist/modules/formats/formatToCep.js +9 -0
  7. package/dist/modules/formats/formatToCnpj.js +9 -0
  8. package/dist/modules/formats/formatToCpf.js +9 -0
  9. package/dist/modules/formats/formatToCurrency.js +15 -0
  10. package/dist/modules/formats/formatToEllipsis.js +11 -0
  11. package/dist/modules/formats/formatToHiddenDigits.js +12 -0
  12. package/dist/modules/formats/formatToPhone.js +17 -0
  13. package/dist/modules/generators/generateColorByString.js +9 -0
  14. package/dist/modules/generators/generateId.js +26 -0
  15. package/dist/modules/generators/generateSlug.js +7 -0
  16. package/dist/modules/index.js +52 -0
  17. package/dist/modules/parsers/parseLargeFields.js +22 -0
  18. package/dist/modules/parsers/parseSensitiveData.js +26 -0
  19. package/dist/modules/parsers/parseToDate.js +27 -0
  20. package/dist/modules/services/validateDateService.js +59 -0
  21. package/dist/modules/utilities/calculateCardInstallment.js +21 -0
  22. package/dist/modules/utilities/ensureQuotes.js +7 -0
  23. package/dist/modules/utilities/findCountryMask.js +25 -0
  24. package/dist/modules/utilities/isHtml.js +6 -0
  25. package/dist/modules/utilities/removeCurrencySymbols.js +6 -0
  26. package/dist/modules/utilities/removeNonNumeric.js +6 -0
  27. package/dist/modules/utilities/stripHtmlTags.js +6 -0
  28. package/package.json +100 -74
  29. package/dist/bundle.js +0 -3719
  30. package/dist/bundle.umd.cjs +0 -10
  31. package/dist/formats/formatDate.js +0 -65
  32. package/dist/formats/formatJsonObject.js +0 -89
  33. package/dist/formats/formatJsonString.js +0 -30
  34. package/dist/formats/formatToCapitalizeFirstWordLetter.js +0 -23
  35. package/dist/formats/formatToCep.js +0 -28
  36. package/dist/formats/formatToCnpj.js +0 -26
  37. package/dist/formats/formatToCpf.js +0 -28
  38. package/dist/formats/formatToCurrency.js +0 -31
  39. package/dist/formats/formatToEllipsis.js +0 -32
  40. package/dist/formats/formatToHiddenDigits.js +0 -49
  41. package/dist/formats/formatToPhone.js +0 -43
  42. package/dist/generators/generateColorByString.js +0 -28
  43. package/dist/generators/generateId.js +0 -29
  44. package/dist/generators/generateSlug.js +0 -31
  45. package/dist/parsers/parseLargeFields.js +0 -55
  46. package/dist/parsers/parseSensitiveData.js +0 -57
  47. package/dist/parsers/parseToDate.js +0 -51
  48. package/dist/services/validateDateService.js +0 -81
  49. package/dist/utilities/calculateCardInstallment.js +0 -39
  50. package/dist/utilities/ensureQuotes.js +0 -26
  51. package/dist/utilities/findCountryMask.js +0 -49
  52. package/dist/utilities/isHtml.js +0 -23
  53. package/dist/utilities/removeCurrencySymbols.js +0 -23
  54. package/dist/utilities/removeNonNumeric.js +0 -16
  55. package/dist/utilities/stripHtmlTags.js +0 -23
package/dist/index.js CHANGED
@@ -1,30 +1,371 @@
1
- // formats
2
- export { formatDate } from "./formats/formatDate";
3
- export { formatJsonObject } from "./formats/formatJsonObject";
4
- export { formatJsonString } from "./formats/formatJsonString";
5
- export { formatToCapitalizeFirstWordLetter } from "./formats/formatToCapitalizeFirstWordLetter";
6
- export { formatToCep } from "./formats/formatToCep";
7
- export { formatToCnpj } from "./formats/formatToCnpj";
8
- export { formatToCpf } from "./formats/formatToCpf";
9
- export { formatToCurrency } from "./formats/formatToCurrency";
10
- export { formatToEllipsis } from "./formats/formatToEllipsis";
11
- export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
12
- export { formatToPhone } from "./formats/formatToPhone";
13
- // generators
14
- export { generateColorByString } from "./generators/generateColorByString";
15
- export { generateId } from "./generators/generateId";
16
- export { generateSlug } from "./generators/generateSlug";
17
- // parsers
18
- export { parseLargeFields } from "./parsers/parseLargeFields";
19
- export { parseSensitiveData } from "./parsers/parseSensitiveData";
20
- export { parseToDate } from "./parsers/parseToDate";
21
- // services
22
- export { ValidateDateService } from "./services/validateDateService";
23
- // utilities
24
- export { calculateCardInstallment } from "./utilities/calculateCardInstallment";
25
- export { ensureQuotes } from "./utilities/ensureQuotes";
26
- export { findCountryMask } from "./utilities/findCountryMask";
27
- export { isHtml } from "./utilities/isHtml";
28
- export { removeCurrencySymbols } from "./utilities/removeCurrencySymbols";
29
- export { removeNonNumeric } from "./utilities/removeNonNumeric";
30
- export { stripHtmlTags } from "./utilities/stripHtmlTags";
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
+ );
74
+ }
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);
97
+ }
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
+ }
134
+ };
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(" ");
140
+ }
141
+ function h(t) {
142
+ return t.replace(/[^0-9]/g, "");
143
+ }
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]}`;
148
+ }
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]}`;
153
+ }
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]}`;
158
+ }
159
+ function T(t) {
160
+ return t.replace(new RegExp("(?:R\\$|\\p{Sc}|[$€¥£])", "gu"), "").trim();
161
+ }
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, " ");
171
+ }
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;
179
+ }
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("");
188
+ }
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
+ }
207
+ }
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
+ }
219
+ }
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;
225
+ }
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;
232
+ }
233
+ function w() {
234
+ const t = $();
235
+ return { text: t, binary: C(t) };
236
+ }
237
+ function b() {
238
+ const t = N();
239
+ return { text: t, binary: C(t) };
240
+ }
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");
247
+ }
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;
251
+ }
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
+ }
270
+ }
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
+ }
293
+ }
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
+ }
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
+ };
334
+ }
335
+ function j(t) {
336
+ const r = t.startsWith("'") && t.endsWith("'"), e = t.startsWith('"') && t.endsWith('"');
337
+ return r || e ? t : `"${t}"`;
338
+ }
339
+ function tt(t) {
340
+ return /<\/?[a-z][\s\S]*>/i.test(t);
341
+ }
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, "");
344
+ }
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
+ };
@@ -0,0 +1,42 @@
1
+ import { ValidateDateService as p } from "../services/validateDateService.js";
2
+ function T(t, c) {
3
+ const e = (i) => i.toString().padStart(2, "0"), m = {
4
+ YYYY: t.getUTCFullYear().toString(),
5
+ YY: t.getUTCFullYear().toString().slice(-2),
6
+ MM: e(t.getUTCMonth() + 1),
7
+ DD: e(t.getUTCDate()),
8
+ hh: e(t.getUTCHours()),
9
+ mm: e(t.getUTCMinutes()),
10
+ ss: e(t.getUTCSeconds())
11
+ };
12
+ return c.replace(
13
+ /YYYY|YY|MM|DD|hh|mm|ss/g,
14
+ (i) => m[i]
15
+ );
16
+ }
17
+ function U([t, c = "00:00:00"], e, m, i = 0) {
18
+ const n = new p();
19
+ n.validateInputFormat(e);
20
+ const l = t.split(/[-/]/).map(Number), D = c.split(".")[0].split(":").map(Number);
21
+ let a, r, s;
22
+ const [g = 0, u = 0, Y = 0] = D;
23
+ switch (e) {
24
+ case "brazilianDate":
25
+ [a, r, s] = l, n.validateDateParts(s, r, a);
26
+ break;
27
+ case "isoDate":
28
+ [r, a, s] = l, n.validateDateParts(s, r, a);
29
+ break;
30
+ case "timestamp":
31
+ [s, r, a] = l, n.validateDateParts(s, r, a);
32
+ break;
33
+ }
34
+ const o = new Date(
35
+ Date.UTC(s, r - 1, a, g, u, Y)
36
+ );
37
+ if (isNaN(o.getTime())) throw new Error("Invalid date");
38
+ return o.setUTCHours(o.getUTCHours() + i), T(o, m);
39
+ }
40
+ export {
41
+ U as formatDate
42
+ };
@@ -0,0 +1,32 @@
1
+ const l = (e, f) => {
2
+ const c = " ".repeat(f);
3
+ let t = "";
4
+ if (typeof e == "object" && e !== null)
5
+ if (Array.isArray(e))
6
+ e.length === 0 ? t += "[]" : (t += `[
7
+ `, e.forEach((r, a) => {
8
+ t += c + " " + l(r, f + 1), a < e.length - 1 && (t += ","), t += `
9
+ `;
10
+ }), t += c + "]");
11
+ else {
12
+ const r = Object.keys(e);
13
+ r.length === 0 ? t += "{}" : (t += `{
14
+ `, r.forEach((a, i) => {
15
+ t += c + ' "' + a + '": ' + l(e[a], f + 1), i < r.length - 1 && (t += ","), t += `
16
+ `;
17
+ }), t += c + "}");
18
+ }
19
+ else if (typeof e == "string")
20
+ try {
21
+ const r = JSON.parse(e);
22
+ t += l(r, f);
23
+ } catch {
24
+ t += '"' + e + '"';
25
+ }
26
+ else
27
+ t += e;
28
+ return t;
29
+ };
30
+ export {
31
+ l as formatJsonObject
32
+ };
@@ -0,0 +1,13 @@
1
+ import { formatJsonObject as o } from "./formatJsonObject.js";
2
+ const e = (t) => {
3
+ try {
4
+ const r = JSON.parse(t);
5
+ return o(r, 0);
6
+ } catch (r) {
7
+ throw new Error(`Invalid JSON string
8
+ ${r}`);
9
+ }
10
+ };
11
+ export {
12
+ e as formatJsonString
13
+ };
@@ -0,0 +1,9 @@
1
+ function a(r) {
2
+ return r.split(" ").map((t) => {
3
+ const o = t.charAt(0).toUpperCase(), e = t.slice(1).toLowerCase();
4
+ return o + e;
5
+ }).join(" ");
6
+ }
7
+ export {
8
+ a as formatToCapitalizeFirstWordLetter
9
+ };
@@ -0,0 +1,9 @@
1
+ import { removeNonNumeric as t } from "../utilities/removeNonNumeric.js";
2
+ function m(e) {
3
+ const r = t(e).match(/^(\d{5})(\d{3})$/), o = `CEP must be contain 8 numeric digits: ${e}`;
4
+ if (!r) throw new Error(o);
5
+ return `${r[1]}-${r[2]}`;
6
+ }
7
+ export {
8
+ m as formatToCep
9
+ };
@@ -0,0 +1,9 @@
1
+ import { removeNonNumeric as n } from "../utilities/removeNonNumeric.js";
2
+ function m(o) {
3
+ const r = n(o).match(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/), e = `CNPJ must be contain 14 numeric digits: ${o}`;
4
+ if (!r) throw new Error(e);
5
+ return `${r[1]}.${r[2]}.${r[3]}/${r[4]}-${r[5]}`;
6
+ }
7
+ export {
8
+ m as formatToCnpj
9
+ };
@@ -0,0 +1,9 @@
1
+ import { removeNonNumeric as t } from "../utilities/removeNonNumeric.js";
2
+ function m(o) {
3
+ const r = t(o).match(/^(\d{3})(\d{3})(\d{3})(\d{2})$/), e = `CPF must be contain 11 numeric digits: ${o}`;
4
+ if (!r) throw new Error(e);
5
+ return `${r[1]}.${r[2]}.${r[3]}-${r[4]}`;
6
+ }
7
+ export {
8
+ m as formatToCpf
9
+ };
@@ -0,0 +1,15 @@
1
+ import { countryCurrencies as n } from "@arkyn/templates";
2
+ import { removeCurrencySymbols as y } from "../utilities/removeCurrencySymbols.js";
3
+ function f(u, e, r) {
4
+ var t;
5
+ if (!((t = n) != null && t[e]))
6
+ throw new Error("Unsupported currency code");
7
+ const c = (r == null ? void 0 : r.showPrefix) ?? !0, { countryCurrency: m, countryLanguage: s } = n[e], o = new Intl.NumberFormat(s, {
8
+ style: "currency",
9
+ currency: m
10
+ }).format(u);
11
+ return c ? o.replace(/\s/g, " ") : y(o).replace(/\s/g, " ");
12
+ }
13
+ export {
14
+ f as formatToCurrency
15
+ };
@@ -0,0 +1,11 @@
1
+ function n(r, e) {
2
+ if (r.length > e) {
3
+ let t = r.substring(0, e);
4
+ const s = t.lastIndexOf(" ");
5
+ return s > 0 && (t = t.substring(0, s)), t = t.replace(/[\s.,!?;:]+$/, ""), t.trim().length === 0 || /^[.,!?;:\s]+$/.test(t) ? "..." : `${t}...`;
6
+ }
7
+ return r;
8
+ }
9
+ export {
10
+ n as formatToEllipsis
11
+ };
@@ -0,0 +1,12 @@
1
+ const n = /^\d$/, a = (t) => {
2
+ let r = 0;
3
+ const e = t.split("").map((i) => n.test(i) ? { character: i, kind: "digit", digit: ++r } : { character: i, kind: "other" });
4
+ return { digits: r, children: e, kind: "root" };
5
+ }, c = (t, r) => Array.isArray(t) ? t : t >= 0 ? [0, t] : [r + 1 - Math.abs(t), r], s = (t, r) => r >= t[0] && r <= t[1];
6
+ function u(t, r) {
7
+ const e = a(t), i = c((r == null ? void 0 : r.range) ?? 3, e.digits);
8
+ return e.children.map((d) => d.kind === "digit" && s(i, d.digit) ? (r == null ? void 0 : r.hider) ?? "*" : d.character).join("");
9
+ }
10
+ export {
11
+ u as formatToHiddenDigits
12
+ };
@@ -0,0 +1,17 @@
1
+ import { parsePhoneNumberWithError as i } from "libphonenumber-js";
2
+ import { findCountryMask as a } from "../utilities/findCountryMask.js";
3
+ function f(n) {
4
+ try {
5
+ const o = i(n).nationalNumber.toString();
6
+ let r = a(n)[0];
7
+ for (let t = 0, e = 0; t < r.length && e < o.length; t++)
8
+ r[t] === "_" && (r = r.substring(0, t) + o[e] + r.substring(t + 1), e++);
9
+ return r;
10
+ } catch (s) {
11
+ const o = s;
12
+ throw new Error(o.message);
13
+ }
14
+ }
15
+ export {
16
+ f as formatToPhone
17
+ };
@@ -0,0 +1,9 @@
1
+ function S(t) {
2
+ for (var r = 0, e = 0; e < t.length; e++)
3
+ r = t.charCodeAt(e) + ((r << 5) - r);
4
+ var a = (r & 16711680) >> 16, n = (r & 65280) >> 8, o = r & 255, v = a.toString(16).padStart(2, "0"), g = n.toString(16).padStart(2, "0"), d = o.toString(16).padStart(2, "0");
5
+ return "#" + v + g + d;
6
+ }
7
+ export {
8
+ S as generateColorByString
9
+ };
@@ -0,0 +1,26 @@
1
+ import { v4 as o, v7 as f } from "uuid";
2
+ function u(n) {
3
+ n = n.replace(/-/g, "");
4
+ const r = new Uint8Array(n.length / 2);
5
+ for (let t = 0; t < n.length; t += 2)
6
+ r[t / 2] = parseInt(n.substring(t, t + 2), 16);
7
+ return r;
8
+ }
9
+ function i() {
10
+ const n = o();
11
+ return { text: n, binary: u(n) };
12
+ }
13
+ function e() {
14
+ const n = f();
15
+ return { text: n, binary: u(n) };
16
+ }
17
+ function b(n, r) {
18
+ if (n === "text" && r === "v4") return i().text;
19
+ if (n === "binary" && r === "v4") return i().binary;
20
+ if (n === "text" && r === "v7") return e().text;
21
+ if (n === "binary" && r === "v7") return e().binary;
22
+ throw new Error("Invalid type or format");
23
+ }
24
+ export {
25
+ b as generateId
26
+ };
@@ -0,0 +1,7 @@
1
+ function l(r) {
2
+ let e = r.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
3
+ return e = e.replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").toLowerCase(), e = e.replace(/-{2,}/g, "-"), e = e.replace(/^-+|-+$/g, ""), e;
4
+ }
5
+ export {
6
+ l as generateSlug
7
+ };