@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.
- package/dist/generators/generateId.d.ts.map +1 -1
- package/dist/index.js +343 -344
- package/dist/modules/formats/formatDate.js +33 -40
- package/dist/modules/formats/formatJsonObject.js +22 -31
- package/dist/modules/formats/formatJsonString.js +10 -12
- package/dist/modules/formats/formatToCapitalizeFirstWordLetter.js +5 -8
- package/dist/modules/formats/formatToCep.js +8 -8
- package/dist/modules/formats/formatToCnpj.js +8 -8
- package/dist/modules/formats/formatToCpf.js +8 -8
- package/dist/modules/formats/formatToCurrency.js +12 -14
- package/dist/modules/formats/formatToEllipsis.js +9 -10
- package/dist/modules/formats/formatToHiddenDigits.js +21 -11
- package/dist/modules/formats/formatToPhone.js +13 -16
- package/dist/modules/generators/generateColorByString.js +7 -8
- package/dist/modules/generators/generateId.js +28 -22
- package/dist/modules/generators/generateSlug.js +6 -6
- package/dist/modules/index.js +26 -52
- package/dist/modules/parsers/parseLargeFields.js +16 -21
- package/dist/modules/parsers/parseSensitiveData.js +27 -25
- package/dist/modules/parsers/parseToDate.js +22 -26
- package/dist/modules/services/validateDateService.js +60 -58
- package/dist/modules/utilities/calculateCardInstallment.js +16 -20
- package/dist/modules/utilities/ensureQuotes.js +6 -6
- package/dist/modules/utilities/findCountryMask.js +22 -24
- package/dist/modules/utilities/isHtml.js +5 -5
- package/dist/modules/utilities/removeCurrencySymbols.js +5 -5
- package/dist/modules/utilities/removeNonNumeric.js +5 -5
- package/dist/modules/utilities/stripHtmlTags.js +5 -5
- package/package.json +16 -12
package/dist/index.js
CHANGED
|
@@ -1,371 +1,370 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { parsePhoneNumberWithError as
|
|
3
|
-
|
|
4
|
-
class
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
142
|
-
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/utilities/removeNonNumeric.ts
|
|
130
|
+
function l(e) {
|
|
131
|
+
return e.replace(/[^0-9]/g, "");
|
|
143
132
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
160
|
-
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/utilities/removeCurrencySymbols.ts
|
|
156
|
+
function p(e) {
|
|
157
|
+
return e.replace(/(?:R\$|\p{Sc}|[$€¥£])/gu, "").trim();
|
|
161
158
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
|
234
|
-
|
|
235
|
-
|
|
244
|
+
function T() {
|
|
245
|
+
let e = crypto.randomUUID();
|
|
246
|
+
return {
|
|
247
|
+
text: e,
|
|
248
|
+
binary: w(e)
|
|
249
|
+
};
|
|
236
250
|
}
|
|
237
|
-
function
|
|
238
|
-
|
|
239
|
-
|
|
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
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
-
|
|
340
|
-
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/utilities/isHtml.ts
|
|
361
|
+
function P(e) {
|
|
362
|
+
return /<\/?[a-z][\s\S]*>/i.test(e);
|
|
341
363
|
}
|
|
342
|
-
|
|
343
|
-
|
|
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
|
-
|
|
346
|
-
|
|
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 };
|