@arkyn/shared 3.0.1-beta.166 → 3.0.1-beta.170
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.
- package/package.json +5 -4
- package/dist/formats/formatDate.d.ts +0 -26
- package/dist/formats/formatDate.d.ts.map +0 -1
- package/dist/formats/formatJsonObject.d.ts +0 -31
- package/dist/formats/formatJsonObject.d.ts.map +0 -1
- package/dist/formats/formatJsonString.d.ts +0 -23
- package/dist/formats/formatJsonString.d.ts.map +0 -1
- package/dist/formats/formatToCapitalizeFirstWordLetter.d.ts +0 -16
- package/dist/formats/formatToCapitalizeFirstWordLetter.d.ts.map +0 -1
- package/dist/formats/formatToCep.d.ts +0 -21
- package/dist/formats/formatToCep.d.ts.map +0 -1
- package/dist/formats/formatToCnpj.d.ts +0 -19
- package/dist/formats/formatToCnpj.d.ts.map +0 -1
- package/dist/formats/formatToCpf.d.ts +0 -21
- package/dist/formats/formatToCpf.d.ts.map +0 -1
- package/dist/formats/formatToCurrency.d.ts +0 -21
- package/dist/formats/formatToCurrency.d.ts.map +0 -1
- package/dist/formats/formatToEllipsis.d.ts +0 -16
- package/dist/formats/formatToEllipsis.d.ts.map +0 -1
- package/dist/formats/formatToHiddenDigits.d.ts +0 -24
- package/dist/formats/formatToHiddenDigits.d.ts.map +0 -1
- package/dist/formats/formatToPhone.d.ts +0 -22
- package/dist/formats/formatToPhone.d.ts.map +0 -1
- package/dist/generators/generateColorByString.d.ts +0 -17
- package/dist/generators/generateColorByString.d.ts.map +0 -1
- package/dist/generators/generateId.d.ts +0 -17
- package/dist/generators/generateId.d.ts.map +0 -1
- package/dist/generators/generateSlug.d.ts +0 -23
- package/dist/generators/generateSlug.d.ts.map +0 -1
- package/dist/index.d.ts +0 -26
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -370
- package/dist/modules/formats/formatDate.js +0 -35
- package/dist/modules/formats/formatJsonObject.js +0 -23
- package/dist/modules/formats/formatJsonString.js +0 -11
- package/dist/modules/formats/formatToCapitalizeFirstWordLetter.js +0 -6
- package/dist/modules/formats/formatToCep.js +0 -9
- package/dist/modules/formats/formatToCnpj.js +0 -9
- package/dist/modules/formats/formatToCpf.js +0 -9
- package/dist/modules/formats/formatToCurrency.js +0 -13
- package/dist/modules/formats/formatToEllipsis.js +0 -10
- package/dist/modules/formats/formatToHiddenDigits.js +0 -22
- package/dist/modules/formats/formatToPhone.js +0 -14
- package/dist/modules/generators/generateColorByString.js +0 -8
- package/dist/modules/generators/generateId.js +0 -32
- package/dist/modules/generators/generateSlug.js +0 -7
- package/dist/modules/index.js +0 -26
- package/dist/modules/parsers/parseLargeFields.js +0 -17
- package/dist/modules/parsers/parseSensitiveData.js +0 -28
- package/dist/modules/parsers/parseToDate.js +0 -23
- package/dist/modules/services/validateDateService.js +0 -61
- package/dist/modules/utilities/calculateCardInstallment.js +0 -17
- package/dist/modules/utilities/ensureQuotes.js +0 -7
- package/dist/modules/utilities/findCountryMask.js +0 -23
- package/dist/modules/utilities/isHtml.js +0 -6
- package/dist/modules/utilities/removeCurrencySymbols.js +0 -6
- package/dist/modules/utilities/removeNonNumeric.js +0 -6
- package/dist/modules/utilities/stripHtmlTags.js +0 -6
- package/dist/parsers/parseLargeFields.d.ts +0 -29
- package/dist/parsers/parseLargeFields.d.ts.map +0 -1
- package/dist/parsers/parseSensitiveData.d.ts +0 -22
- package/dist/parsers/parseSensitiveData.d.ts.map +0 -1
- package/dist/parsers/parseToDate.d.ts +0 -25
- package/dist/parsers/parseToDate.d.ts.map +0 -1
- package/dist/services/validateDateService.d.ts +0 -34
- package/dist/services/validateDateService.d.ts.map +0 -1
- package/dist/utilities/calculateCardInstallment.d.ts +0 -25
- package/dist/utilities/calculateCardInstallment.d.ts.map +0 -1
- package/dist/utilities/ensureQuotes.d.ts +0 -20
- package/dist/utilities/ensureQuotes.d.ts.map +0 -1
- package/dist/utilities/findCountryMask.d.ts +0 -21
- package/dist/utilities/findCountryMask.d.ts.map +0 -1
- package/dist/utilities/isHtml.d.ts +0 -21
- package/dist/utilities/isHtml.d.ts.map +0 -1
- package/dist/utilities/removeCurrencySymbols.d.ts +0 -22
- package/dist/utilities/removeCurrencySymbols.d.ts.map +0 -1
- package/dist/utilities/removeNonNumeric.d.ts +0 -15
- package/dist/utilities/removeNonNumeric.d.ts.map +0 -1
- package/dist/utilities/stripHtmlTags.d.ts +0 -18
- package/dist/utilities/stripHtmlTags.d.ts.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,370 +0,0 @@
|
|
|
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]);
|
|
75
|
-
}
|
|
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);
|
|
94
|
-
}
|
|
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
|
-
}
|
|
122
|
-
};
|
|
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(" ");
|
|
127
|
-
}
|
|
128
|
-
//#endregion
|
|
129
|
-
//#region src/utilities/removeNonNumeric.ts
|
|
130
|
-
function l(e) {
|
|
131
|
-
return e.replace(/[^0-9]/g, "");
|
|
132
|
-
}
|
|
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]}`;
|
|
139
|
-
}
|
|
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]}`;
|
|
146
|
-
}
|
|
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]}`;
|
|
153
|
-
}
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/utilities/removeCurrencySymbols.ts
|
|
156
|
-
function p(e) {
|
|
157
|
-
return e.replace(/(?:R\$|\p{Sc}|[$€¥£])/gu, "").trim();
|
|
158
|
-
}
|
|
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, " ");
|
|
168
|
-
}
|
|
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;
|
|
177
|
-
}
|
|
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("");
|
|
198
|
-
}
|
|
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
|
-
}
|
|
217
|
-
}
|
|
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
|
-
}
|
|
228
|
-
}
|
|
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;
|
|
235
|
-
}
|
|
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;
|
|
243
|
-
}
|
|
244
|
-
function T() {
|
|
245
|
-
let e = crypto.randomUUID();
|
|
246
|
-
return {
|
|
247
|
-
text: e,
|
|
248
|
-
binary: w(e)
|
|
249
|
-
};
|
|
250
|
-
}
|
|
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
|
-
};
|
|
259
|
-
}
|
|
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");
|
|
266
|
-
}
|
|
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;
|
|
272
|
-
}
|
|
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
|
-
}
|
|
288
|
-
}
|
|
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
|
-
}
|
|
315
|
-
}
|
|
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;
|
|
336
|
-
}
|
|
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
|
-
};
|
|
352
|
-
}
|
|
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}"`;
|
|
358
|
-
}
|
|
359
|
-
//#endregion
|
|
360
|
-
//#region src/utilities/isHtml.ts
|
|
361
|
-
function P(e) {
|
|
362
|
-
return /<\/?[a-z][\s\S]*>/i.test(e);
|
|
363
|
-
}
|
|
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, "");
|
|
368
|
-
}
|
|
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 };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ValidateDateService as e } from "../services/validateDateService.js";
|
|
2
|
-
//#region src/formats/formatDate.ts
|
|
3
|
-
function t(e, t) {
|
|
4
|
-
let n = (e) => e.toString().padStart(2, "0"), r = {
|
|
5
|
-
YYYY: e.getUTCFullYear().toString(),
|
|
6
|
-
YY: e.getUTCFullYear().toString().slice(-2),
|
|
7
|
-
MM: n(e.getUTCMonth() + 1),
|
|
8
|
-
DD: n(e.getUTCDate()),
|
|
9
|
-
hh: n(e.getUTCHours()),
|
|
10
|
-
mm: n(e.getUTCMinutes()),
|
|
11
|
-
ss: n(e.getUTCSeconds())
|
|
12
|
-
};
|
|
13
|
-
return t.replace(/YYYY|YY|MM|DD|hh|mm|ss/g, (e) => r[e]);
|
|
14
|
-
}
|
|
15
|
-
function n([n, r = "00:00:00"], i, a, o = 0) {
|
|
16
|
-
let s = new e();
|
|
17
|
-
s.validateInputFormat(i);
|
|
18
|
-
let c = n.split(/[-/]/).map(Number), l = r.split(".")[0].split(":").map(Number), u, d, f, [p = 0, m = 0, h = 0] = l;
|
|
19
|
-
switch (i) {
|
|
20
|
-
case "brazilianDate":
|
|
21
|
-
[u, d, f] = c, s.validateDateParts(f, d, u);
|
|
22
|
-
break;
|
|
23
|
-
case "isoDate":
|
|
24
|
-
[d, u, f] = c, s.validateDateParts(f, d, u);
|
|
25
|
-
break;
|
|
26
|
-
case "timestamp":
|
|
27
|
-
[f, d, u] = c, s.validateDateParts(f, d, u);
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
let g = new Date(Date.UTC(f, d - 1, u, p, m, h));
|
|
31
|
-
if (isNaN(g.getTime())) throw Error("Invalid date");
|
|
32
|
-
return g.setUTCHours(g.getUTCHours() + o), t(g, a);
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
export { n as formatDate };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
//#region src/formats/formatJsonObject.ts
|
|
2
|
-
var e = (t, n) => {
|
|
3
|
-
let r = " ".repeat(n), i = "";
|
|
4
|
-
if (typeof t == "object" && t) if (Array.isArray(t)) t.length === 0 ? i += "[]" : (i += "[\n", t.forEach((a, o) => {
|
|
5
|
-
i += r + " " + e(a, n + 1), o < t.length - 1 && (i += ","), i += "\n";
|
|
6
|
-
}), i += r + "]");
|
|
7
|
-
else {
|
|
8
|
-
let a = Object.keys(t);
|
|
9
|
-
a.length === 0 ? i += "{}" : (i += "{\n", a.forEach((o, s) => {
|
|
10
|
-
i += r + " \"" + o + "\": " + e(t[o], n + 1), s < a.length - 1 && (i += ","), i += "\n";
|
|
11
|
-
}), i += r + "}");
|
|
12
|
-
}
|
|
13
|
-
else if (typeof t == "string") try {
|
|
14
|
-
let r = JSON.parse(t);
|
|
15
|
-
i += e(r, n);
|
|
16
|
-
} catch {
|
|
17
|
-
i += "\"" + t + "\"";
|
|
18
|
-
}
|
|
19
|
-
else i += t;
|
|
20
|
-
return i;
|
|
21
|
-
};
|
|
22
|
-
//#endregion
|
|
23
|
-
export { e as formatJsonObject };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { formatJsonObject as e } from "./formatJsonObject.js";
|
|
2
|
-
//#region src/formats/formatJsonString.ts
|
|
3
|
-
var t = (t) => {
|
|
4
|
-
try {
|
|
5
|
-
return e(JSON.parse(t), 0);
|
|
6
|
-
} catch (e) {
|
|
7
|
-
throw Error(`Invalid JSON string \n ${e}`);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
//#endregion
|
|
11
|
-
export { t as formatJsonString };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { removeNonNumeric as e } from "../utilities/removeNonNumeric.js";
|
|
2
|
-
//#region src/formats/formatToCep.ts
|
|
3
|
-
function t(t) {
|
|
4
|
-
let n = e(t).match(/^(\d{5})(\d{3})$/), r = `CEP must be contain 8 numeric digits: ${t}`;
|
|
5
|
-
if (!n) throw Error(r);
|
|
6
|
-
return `${n[1]}-${n[2]}`;
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { t as formatToCep };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { removeNonNumeric as e } from "../utilities/removeNonNumeric.js";
|
|
2
|
-
//#region src/formats/formatToCnpj.ts
|
|
3
|
-
function t(t) {
|
|
4
|
-
let n = e(t).match(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})$/), r = `CNPJ must be contain 14 numeric digits: ${t}`;
|
|
5
|
-
if (!n) throw Error(r);
|
|
6
|
-
return `${n[1]}.${n[2]}.${n[3]}/${n[4]}-${n[5]}`;
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { t as formatToCnpj };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { removeNonNumeric as e } from "../utilities/removeNonNumeric.js";
|
|
2
|
-
//#region src/formats/formatToCpf.ts
|
|
3
|
-
function t(t) {
|
|
4
|
-
let n = e(t).match(/^(\d{3})(\d{3})(\d{3})(\d{2})$/), r = `CPF must be contain 11 numeric digits: ${t}`;
|
|
5
|
-
if (!n) throw Error(r);
|
|
6
|
-
return `${n[1]}.${n[2]}.${n[3]}-${n[4]}`;
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { t as formatToCpf };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { removeCurrencySymbols as e } from "../utilities/removeCurrencySymbols.js";
|
|
2
|
-
import { countryCurrencies as t } from "@arkyn/templates";
|
|
3
|
-
//#region src/formats/formatToCurrency.ts
|
|
4
|
-
function n(n, r, i) {
|
|
5
|
-
if (!t?.[r]) throw Error("Unsupported currency code");
|
|
6
|
-
let a = i?.showPrefix ?? !0, { countryCurrency: o, countryLanguage: s } = t[r], c = new Intl.NumberFormat(s, {
|
|
7
|
-
style: "currency",
|
|
8
|
-
currency: o
|
|
9
|
-
}).format(n);
|
|
10
|
-
return a ? c.replace(/\s/g, " ") : e(c).replace(/\s/g, " ");
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { n as formatToCurrency };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
//#region src/formats/formatToEllipsis.ts
|
|
2
|
-
function e(e, t) {
|
|
3
|
-
if (e.length > t) {
|
|
4
|
-
let n = e.substring(0, t), r = n.lastIndexOf(" ");
|
|
5
|
-
return r > 0 && (n = n.substring(0, r)), n = n.replace(/[\s.,!?;:]+$/, ""), n.trim().length === 0 || /^[.,!?;:\s]+$/.test(n) ? "..." : `${n}...`;
|
|
6
|
-
}
|
|
7
|
-
return e;
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
10
|
-
export { e as formatToEllipsis };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//#region src/formats/formatToHiddenDigits.ts
|
|
2
|
-
var e = /^\d$/, t = (t) => {
|
|
3
|
-
let n = 0, r = t.split("").map((t) => e.test(t) ? {
|
|
4
|
-
character: t,
|
|
5
|
-
kind: "digit",
|
|
6
|
-
digit: ++n
|
|
7
|
-
} : {
|
|
8
|
-
character: t,
|
|
9
|
-
kind: "other"
|
|
10
|
-
});
|
|
11
|
-
return {
|
|
12
|
-
digits: n,
|
|
13
|
-
children: r,
|
|
14
|
-
kind: "root"
|
|
15
|
-
};
|
|
16
|
-
}, n = (e, t) => Array.isArray(e) ? e : e >= 0 ? [0, e] : [t + 1 - Math.abs(e), t], r = (e, t) => t >= e[0] && t <= e[1];
|
|
17
|
-
function i(e, i) {
|
|
18
|
-
let a = t(e), o = n(i?.range ?? 3, a.digits);
|
|
19
|
-
return a.children.map((e) => e.kind === "digit" && r(o, e.digit) ? i?.hider ?? "*" : e.character).join("");
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
export { i as formatToHiddenDigits };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { findCountryMask as e } from "../utilities/findCountryMask.js";
|
|
2
|
-
import { parsePhoneNumberWithError as t } from "libphonenumber-js";
|
|
3
|
-
//#region src/formats/formatToPhone.ts
|
|
4
|
-
function n(n) {
|
|
5
|
-
try {
|
|
6
|
-
let r = t(n).nationalNumber.toString(), i = e(n)[0];
|
|
7
|
-
for (let e = 0, t = 0; e < i.length && t < r.length; e++) i[e] === "_" && (i = i.substring(0, e) + r[t] + i.substring(e + 1), t++);
|
|
8
|
-
return i;
|
|
9
|
-
} catch (e) {
|
|
10
|
-
throw Error(e.message);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
export { n as formatToPhone };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
//#region src/generators/generateColorByString.ts
|
|
2
|
-
function e(e) {
|
|
3
|
-
for (var t = 0, n = 0; n < e.length; n++) t = e.charCodeAt(n) + ((t << 5) - t);
|
|
4
|
-
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");
|
|
5
|
-
return "#" + o + s + c;
|
|
6
|
-
}
|
|
7
|
-
//#endregion
|
|
8
|
-
export { e as generateColorByString };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
//#region src/generators/generateId.ts
|
|
2
|
-
function e(e) {
|
|
3
|
-
e = e.replace(/-/g, "");
|
|
4
|
-
let t = new Uint8Array(e.length / 2);
|
|
5
|
-
for (let n = 0; n < e.length; n += 2) t[n / 2] = parseInt(e.substring(n, n + 2), 16);
|
|
6
|
-
return t;
|
|
7
|
-
}
|
|
8
|
-
function t() {
|
|
9
|
-
let t = crypto.randomUUID();
|
|
10
|
-
return {
|
|
11
|
-
text: t,
|
|
12
|
-
binary: e(t)
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function n() {
|
|
16
|
-
let t = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16)), n = BigInt(Date.now());
|
|
17
|
-
t[0] = Number(n >> 40n & 255n), t[1] = Number(n >> 32n & 255n), t[2] = Number(n >> 24n & 255n), t[3] = Number(n >> 16n & 255n), t[4] = Number(n >> 8n & 255n), t[5] = Number(n & 255n), t[6] = t[6] & 15 | 112, t[8] = t[8] & 63 | 128;
|
|
18
|
-
let r = [...t].map((e) => e.toString(16).padStart(2, "0")).join("").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
|
|
19
|
-
return {
|
|
20
|
-
text: r,
|
|
21
|
-
binary: e(r)
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function r(e, r) {
|
|
25
|
-
if (e === "text" && r === "v4") return t().text;
|
|
26
|
-
if (e === "binary" && r === "v4") return t().binary;
|
|
27
|
-
if (e === "text" && r === "v7") return n().text;
|
|
28
|
-
if (e === "binary" && r === "v7") return n().binary;
|
|
29
|
-
throw Error("Invalid type or format");
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
32
|
-
export { r as generateId };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
//#region src/generators/generateSlug.ts
|
|
2
|
-
function e(e) {
|
|
3
|
-
let t = e.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
4
|
-
return t = t.replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").toLowerCase(), t = t.replace(/-{2,}/g, "-"), t = t.replace(/^-+|-+$/g, ""), t;
|
|
5
|
-
}
|
|
6
|
-
//#endregion
|
|
7
|
-
export { e as generateSlug };
|
package/dist/modules/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ValidateDateService as e } from "./services/validateDateService.js";
|
|
2
|
-
import { formatDate as t } from "./formats/formatDate.js";
|
|
3
|
-
import { formatJsonObject as n } from "./formats/formatJsonObject.js";
|
|
4
|
-
import { formatJsonString as r } from "./formats/formatJsonString.js";
|
|
5
|
-
import { formatToCapitalizeFirstWordLetter as i } from "./formats/formatToCapitalizeFirstWordLetter.js";
|
|
6
|
-
import { removeNonNumeric as a } from "./utilities/removeNonNumeric.js";
|
|
7
|
-
import { formatToCep as o } from "./formats/formatToCep.js";
|
|
8
|
-
import { formatToCnpj as s } from "./formats/formatToCnpj.js";
|
|
9
|
-
import { formatToCpf as c } from "./formats/formatToCpf.js";
|
|
10
|
-
import { removeCurrencySymbols as l } from "./utilities/removeCurrencySymbols.js";
|
|
11
|
-
import { formatToCurrency as u } from "./formats/formatToCurrency.js";
|
|
12
|
-
import { formatToEllipsis as d } from "./formats/formatToEllipsis.js";
|
|
13
|
-
import { formatToHiddenDigits as f } from "./formats/formatToHiddenDigits.js";
|
|
14
|
-
import { findCountryMask as p } from "./utilities/findCountryMask.js";
|
|
15
|
-
import { formatToPhone as m } from "./formats/formatToPhone.js";
|
|
16
|
-
import { generateColorByString as h } from "./generators/generateColorByString.js";
|
|
17
|
-
import { generateId as g } from "./generators/generateId.js";
|
|
18
|
-
import { generateSlug as _ } from "./generators/generateSlug.js";
|
|
19
|
-
import { parseLargeFields as v } from "./parsers/parseLargeFields.js";
|
|
20
|
-
import { parseSensitiveData as y } from "./parsers/parseSensitiveData.js";
|
|
21
|
-
import { parseToDate as b } from "./parsers/parseToDate.js";
|
|
22
|
-
import { calculateCardInstallment as x } from "./utilities/calculateCardInstallment.js";
|
|
23
|
-
import { ensureQuotes as S } from "./utilities/ensureQuotes.js";
|
|
24
|
-
import { isHtml as C } from "./utilities/isHtml.js";
|
|
25
|
-
import { stripHtmlTags as w } from "./utilities/stripHtmlTags.js";
|
|
26
|
-
export { e as ValidateDateService, x as calculateCardInstallment, S as ensureQuotes, p as findCountryMask, t as formatDate, n as formatJsonObject, r as formatJsonString, i as formatToCapitalizeFirstWordLetter, o as formatToCep, s as formatToCnpj, c as formatToCpf, u as formatToCurrency, d as formatToEllipsis, f as formatToHiddenDigits, m as formatToPhone, h as generateColorByString, g as generateId, _ as generateSlug, C as isHtml, v as parseLargeFields, y as parseSensitiveData, b as parseToDate, l as removeCurrencySymbols, a as removeNonNumeric, w as stripHtmlTags };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
//#region src/parsers/parseLargeFields.ts
|
|
2
|
-
function e(e, t = 1e3) {
|
|
3
|
-
function n(e) {
|
|
4
|
-
return typeof e == "string" && e.length > t ? `To large information: field as ${e.length} characters` : e;
|
|
5
|
-
}
|
|
6
|
-
function r(e) {
|
|
7
|
-
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);
|
|
8
|
-
}
|
|
9
|
-
try {
|
|
10
|
-
let t = r(JSON.parse(e));
|
|
11
|
-
return JSON.stringify(t);
|
|
12
|
-
} catch {
|
|
13
|
-
throw Error("Invalid JSON string");
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
17
|
-
export { e as parseLargeFields };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
//#region src/parsers/parseSensitiveData.ts
|
|
2
|
-
function e(e, t = [
|
|
3
|
-
"password",
|
|
4
|
-
"confirmPassword",
|
|
5
|
-
"creditCard"
|
|
6
|
-
]) {
|
|
7
|
-
function n(e, n) {
|
|
8
|
-
return t.includes(e) ? "****" : n;
|
|
9
|
-
}
|
|
10
|
-
function r(e) {
|
|
11
|
-
return Array.isArray(e) ? e.map((e) => r(e)) : typeof e == "object" && e ? Object.keys(e).reduce((t, i) => {
|
|
12
|
-
let a = e[i];
|
|
13
|
-
if (typeof a == "string") try {
|
|
14
|
-
let e = JSON.parse(a);
|
|
15
|
-
typeof e == "object" && (a = JSON.stringify(r(e)));
|
|
16
|
-
} catch {}
|
|
17
|
-
return t[i] = r(n(i, a)), t;
|
|
18
|
-
}, {}) : e;
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
let t = r(JSON.parse(e));
|
|
22
|
-
return JSON.stringify(t);
|
|
23
|
-
} catch {
|
|
24
|
-
return e;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
//#endregion
|
|
28
|
-
export { e as parseSensitiveData };
|