@arkyn/shared 3.0.1-beta.99 → 3.0.3
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/LICENSE.txt +184 -1
- package/README.md +196 -306
- package/dist/formats/formatDate.d.ts +18 -26
- package/dist/formats/formatDate.d.ts.map +1 -1
- package/dist/formats/formatJsonObject.d.ts +5 -7
- package/dist/formats/formatJsonObject.d.ts.map +1 -1
- package/dist/formats/formatJsonString.d.ts +5 -21
- package/dist/formats/formatJsonString.d.ts.map +1 -1
- package/dist/formats/formatToCapitalizeFirstWordLetter.d.ts +5 -24
- package/dist/formats/formatToCapitalizeFirstWordLetter.d.ts.map +1 -1
- package/dist/formats/formatToCep.d.ts +3 -11
- package/dist/formats/formatToCep.d.ts.map +1 -1
- package/dist/formats/formatToCnpj.d.ts +3 -14
- package/dist/formats/formatToCnpj.d.ts.map +1 -1
- package/dist/formats/formatToCpf.d.ts +4 -13
- package/dist/formats/formatToCpf.d.ts.map +1 -1
- package/dist/formats/formatToCurrency.d.ts +10 -23
- package/dist/formats/formatToCurrency.d.ts.map +1 -1
- package/dist/formats/formatToEllipsis.d.ts +5 -5
- package/dist/formats/formatToEllipsis.d.ts.map +1 -1
- package/dist/formats/formatToHiddenDigits.d.ts +15 -26
- package/dist/formats/formatToHiddenDigits.d.ts.map +1 -1
- package/dist/formats/formatToPhone.d.ts +11 -23
- package/dist/formats/formatToPhone.d.ts.map +1 -1
- package/dist/generators/generateColorByString.d.ts +6 -4
- package/dist/generators/generateColorByString.d.ts.map +1 -1
- package/dist/generators/generateId.d.ts +8 -19
- package/dist/generators/generateId.d.ts.map +1 -1
- package/dist/generators/generateSlug.d.ts +8 -2
- package/dist/generators/generateSlug.d.ts.map +1 -1
- package/dist/index.d.ts +11 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +373 -27
- package/dist/index.js.map +1 -0
- package/dist/modules/formats/formatDate.js +37 -0
- package/dist/modules/formats/formatDate.js.map +1 -0
- package/dist/modules/formats/formatJsonObject.js +25 -0
- package/dist/modules/formats/formatJsonObject.js.map +1 -0
- package/dist/modules/formats/formatJsonString.js +13 -0
- package/dist/modules/formats/formatJsonString.js.map +1 -0
- package/dist/modules/formats/formatToCapitalizeFirstWordLetter.js +8 -0
- package/dist/modules/formats/formatToCapitalizeFirstWordLetter.js.map +1 -0
- package/dist/modules/formats/formatToCep.js +11 -0
- package/dist/modules/formats/formatToCep.js.map +1 -0
- package/dist/modules/formats/formatToCnpj.js +11 -0
- package/dist/modules/formats/formatToCnpj.js.map +1 -0
- package/dist/modules/formats/formatToCpf.js +11 -0
- package/dist/modules/formats/formatToCpf.js.map +1 -0
- package/dist/modules/formats/formatToCurrency.js +15 -0
- package/dist/modules/formats/formatToCurrency.js.map +1 -0
- package/dist/modules/formats/formatToEllipsis.js +12 -0
- package/dist/modules/formats/formatToEllipsis.js.map +1 -0
- package/dist/modules/formats/formatToHiddenDigits.js +24 -0
- package/dist/modules/formats/formatToHiddenDigits.js.map +1 -0
- package/dist/modules/formats/formatToPhone.js +16 -0
- package/dist/modules/formats/formatToPhone.js.map +1 -0
- package/dist/modules/generators/generateColorByString.js +11 -0
- package/dist/modules/generators/generateColorByString.js.map +1 -0
- package/dist/modules/generators/generateId.js +34 -0
- package/dist/modules/generators/generateId.js.map +1 -0
- package/dist/modules/generators/generateSlug.js +9 -0
- package/dist/modules/generators/generateSlug.js.map +1 -0
- package/dist/modules/parsers/parseLargeFields.js +19 -0
- package/dist/modules/parsers/parseLargeFields.js.map +1 -0
- package/dist/modules/parsers/parseSensitiveData.js +30 -0
- package/dist/modules/parsers/parseSensitiveData.js.map +1 -0
- package/dist/modules/parsers/parseToDate.js +25 -0
- package/dist/modules/parsers/parseToDate.js.map +1 -0
- package/dist/modules/services/validateDateService.js +63 -0
- package/dist/modules/services/validateDateService.js.map +1 -0
- package/dist/modules/utilities/calculateCardInstallment.js +19 -0
- package/dist/modules/utilities/calculateCardInstallment.js.map +1 -0
- package/dist/modules/utilities/ensureQuotes.js +9 -0
- package/dist/modules/utilities/ensureQuotes.js.map +1 -0
- package/dist/modules/utilities/findCountryMask.js +25 -0
- package/dist/modules/utilities/findCountryMask.js.map +1 -0
- package/dist/modules/utilities/isHtml.js +8 -0
- package/dist/modules/utilities/isHtml.js.map +1 -0
- package/dist/modules/utilities/removeCurrencySymbols.js +8 -0
- package/dist/modules/utilities/removeCurrencySymbols.js.map +1 -0
- package/dist/modules/utilities/removeNonNumeric.js +8 -0
- package/dist/modules/utilities/removeNonNumeric.js.map +1 -0
- package/dist/modules/utilities/stripHtmlTags.js +8 -0
- package/dist/modules/utilities/stripHtmlTags.js.map +1 -0
- package/dist/{services/truncateLargeFields.d.ts → parsers/parseLargeFields.d.ts} +5 -8
- package/dist/parsers/parseLargeFields.d.ts.map +1 -0
- package/dist/parsers/parseSensitiveData.d.ts +22 -0
- package/dist/parsers/parseSensitiveData.d.ts.map +1 -0
- package/dist/parsers/parseToDate.d.ts +25 -0
- package/dist/parsers/parseToDate.d.ts.map +1 -0
- package/dist/services/validateDateService.d.ts +34 -0
- package/dist/services/validateDateService.d.ts.map +1 -0
- package/dist/utilities/calculateCardInstallment.d.ts +25 -0
- package/dist/utilities/calculateCardInstallment.d.ts.map +1 -0
- package/dist/utilities/ensureQuotes.d.ts +20 -0
- package/dist/utilities/ensureQuotes.d.ts.map +1 -0
- package/dist/utilities/findCountryMask.d.ts +21 -0
- package/dist/utilities/findCountryMask.d.ts.map +1 -0
- package/dist/utilities/isHtml.d.ts +21 -0
- package/dist/utilities/isHtml.d.ts.map +1 -0
- package/dist/{services/removeCurrencySymbols.js → utilities/removeCurrencySymbols.d.ts} +6 -7
- package/dist/utilities/removeCurrencySymbols.d.ts.map +1 -0
- package/dist/utilities/removeNonNumeric.d.ts +15 -0
- package/dist/utilities/removeNonNumeric.d.ts.map +1 -0
- package/dist/utilities/stripHtmlTags.d.ts +18 -0
- package/dist/utilities/stripHtmlTags.d.ts.map +1 -0
- package/package.json +255 -16
- package/dist/bundle.js +0 -2337
- package/dist/bundle.umd.cjs +0 -6
- package/dist/formats/formatDate.js +0 -66
- package/dist/formats/formatJsonObject.js +0 -90
- package/dist/formats/formatJsonString.js +0 -46
- package/dist/formats/formatToCapitalizeFirstWordLetter.js +0 -42
- package/dist/formats/formatToCep.js +0 -34
- package/dist/formats/formatToCnpj.js +0 -35
- package/dist/formats/formatToCpf.js +0 -35
- package/dist/formats/formatToCpfCnpj.d.ts +0 -24
- package/dist/formats/formatToCpfCnpj.d.ts.map +0 -1
- package/dist/formats/formatToCpfCnpj.js +0 -33
- package/dist/formats/formatToCurrency.js +0 -41
- package/dist/formats/formatToDate.d.ts +0 -32
- package/dist/formats/formatToDate.d.ts.map +0 -1
- package/dist/formats/formatToDate.js +0 -50
- package/dist/formats/formatToEllipsis.js +0 -21
- package/dist/formats/formatToHiddenDigits.js +0 -60
- package/dist/formats/formatToPhone.js +0 -131
- package/dist/generators/generateColorByString.js +0 -25
- package/dist/generators/generateId.js +0 -29
- package/dist/generators/generateSlug.js +0 -25
- package/dist/services/calculateCardInstallment.d.ts +0 -40
- package/dist/services/calculateCardInstallment.d.ts.map +0 -1
- package/dist/services/calculateCardInstallment.js +0 -55
- package/dist/services/ensureQuotes.d.ts +0 -14
- package/dist/services/ensureQuotes.d.ts.map +0 -1
- package/dist/services/ensureQuotes.js +0 -19
- package/dist/services/isHtml.d.ts +0 -22
- package/dist/services/isHtml.d.ts.map +0 -1
- package/dist/services/isHtml.js +0 -24
- package/dist/services/maskSensitiveData.d.ts +0 -26
- package/dist/services/maskSensitiveData.d.ts.map +0 -1
- package/dist/services/maskSensitiveData.js +0 -60
- package/dist/services/removeCurrencySymbols.d.ts +0 -21
- package/dist/services/removeCurrencySymbols.d.ts.map +0 -1
- package/dist/services/removeNonNumeric.d.ts +0 -16
- package/dist/services/removeNonNumeric.d.ts.map +0 -1
- package/dist/services/removeNonNumeric.js +0 -16
- package/dist/services/stripHtmlTags.d.ts +0 -16
- package/dist/services/stripHtmlTags.d.ts.map +0 -1
- package/dist/services/stripHtmlTags.js +0 -16
- package/dist/services/truncateLargeFields.d.ts.map +0 -1
- package/dist/services/truncateLargeFields.js +0 -57
package/dist/index.d.ts
CHANGED
|
@@ -5,21 +5,22 @@ export { formatToCapitalizeFirstWordLetter } from "./formats/formatToCapitalizeF
|
|
|
5
5
|
export { formatToCep } from "./formats/formatToCep";
|
|
6
6
|
export { formatToCnpj } from "./formats/formatToCnpj";
|
|
7
7
|
export { formatToCpf } from "./formats/formatToCpf";
|
|
8
|
-
export { formatToCpfCnpj } from "./formats/formatToCpfCnpj";
|
|
9
8
|
export { formatToCurrency } from "./formats/formatToCurrency";
|
|
10
|
-
export { formatToDate } from "./formats/formatToDate";
|
|
11
9
|
export { formatToEllipsis } from "./formats/formatToEllipsis";
|
|
12
10
|
export { formatToHiddenDigits } from "./formats/formatToHiddenDigits";
|
|
13
11
|
export { formatToPhone } from "./formats/formatToPhone";
|
|
14
12
|
export { generateColorByString } from "./generators/generateColorByString";
|
|
15
13
|
export { generateId } from "./generators/generateId";
|
|
16
14
|
export { generateSlug } from "./generators/generateSlug";
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
15
|
+
export { parseLargeFields } from "./parsers/parseLargeFields";
|
|
16
|
+
export { parseSensitiveData } from "./parsers/parseSensitiveData";
|
|
17
|
+
export { parseToDate } from "./parsers/parseToDate";
|
|
18
|
+
export { ValidateDateService } from "./services/validateDateService";
|
|
19
|
+
export { calculateCardInstallment } from "./utilities/calculateCardInstallment";
|
|
20
|
+
export { ensureQuotes } from "./utilities/ensureQuotes";
|
|
21
|
+
export { findCountryMask } from "./utilities/findCountryMask";
|
|
22
|
+
export { isHtml } from "./utilities/isHtml";
|
|
23
|
+
export { removeCurrencySymbols } from "./utilities/removeCurrencySymbols";
|
|
24
|
+
export { removeNonNumeric } from "./utilities/removeNonNumeric";
|
|
25
|
+
export { stripHtmlTags } from "./utilities/stripHtmlTags";
|
|
25
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,iCAAiC,EAAE,MAAM,6CAA6C,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,iCAAiC,EAAE,MAAM,6CAA6C,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,373 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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 (Number.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
|
+
let t = 0;
|
|
233
|
+
for (let n = 0; n < e.length; n++) t = e.charCodeAt(n) + ((t << 5) - t);
|
|
234
|
+
let n = (t & 16711680) >> 16, r = (t & 65280) >> 8, i = t & 255;
|
|
235
|
+
return `#${n.toString(16).padStart(2, "0")}${r.toString(16).padStart(2, "0")}${i.toString(16).padStart(2, "0")}`;
|
|
236
|
+
}
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/generators/generateId.ts
|
|
239
|
+
function w(e) {
|
|
240
|
+
e = e.replace(/-/g, "");
|
|
241
|
+
let t = new Uint8Array(e.length / 2);
|
|
242
|
+
for (let n = 0; n < e.length; n += 2) t[n / 2] = parseInt(e.substring(n, n + 2), 16);
|
|
243
|
+
return t;
|
|
244
|
+
}
|
|
245
|
+
function T() {
|
|
246
|
+
let e = crypto.randomUUID();
|
|
247
|
+
return {
|
|
248
|
+
text: e,
|
|
249
|
+
binary: w(e)
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function E() {
|
|
253
|
+
let e = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16)), t = BigInt(Date.now());
|
|
254
|
+
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;
|
|
255
|
+
let n = [...e].map((e) => e.toString(16).padStart(2, "0")).join("").replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, "$1-$2-$3-$4-$5");
|
|
256
|
+
return {
|
|
257
|
+
text: n,
|
|
258
|
+
binary: w(n)
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function D(e, t) {
|
|
262
|
+
if (e === "text" && t === "v4") return T().text;
|
|
263
|
+
if (e === "binary" && t === "v4") return T().binary;
|
|
264
|
+
if (e === "text" && t === "v7") return E().text;
|
|
265
|
+
if (e === "binary" && t === "v7") return E().binary;
|
|
266
|
+
throw Error("Invalid type or format");
|
|
267
|
+
}
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/generators/generateSlug.ts
|
|
270
|
+
function O(e) {
|
|
271
|
+
let t = e.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
272
|
+
return t = t.replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").toLowerCase(), t = t.replace(/-{2,}/g, "-"), t = t.replace(/^-+|-+$/g, ""), t;
|
|
273
|
+
}
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/parsers/parseLargeFields.ts
|
|
276
|
+
function k(e, t = 1e3) {
|
|
277
|
+
function n(e) {
|
|
278
|
+
return typeof e == "string" && e.length > t ? `To large information: field as ${e.length} characters` : e;
|
|
279
|
+
}
|
|
280
|
+
function r(e) {
|
|
281
|
+
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);
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
let t = r(JSON.parse(e));
|
|
285
|
+
return JSON.stringify(t);
|
|
286
|
+
} catch {
|
|
287
|
+
throw Error("Invalid JSON string");
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
//#endregion
|
|
291
|
+
//#region src/parsers/parseSensitiveData.ts
|
|
292
|
+
function A(e, t = [
|
|
293
|
+
"password",
|
|
294
|
+
"confirmPassword",
|
|
295
|
+
"creditCard"
|
|
296
|
+
]) {
|
|
297
|
+
function n(e, n) {
|
|
298
|
+
return t.includes(e) ? "****" : n;
|
|
299
|
+
}
|
|
300
|
+
function r(e) {
|
|
301
|
+
return Array.isArray(e) ? e.map((e) => r(e)) : typeof e == "object" && e ? Object.keys(e).reduce((t, i) => {
|
|
302
|
+
let a = e[i];
|
|
303
|
+
if (typeof a == "string") try {
|
|
304
|
+
let e = JSON.parse(a);
|
|
305
|
+
typeof e == "object" && (a = JSON.stringify(r(e)));
|
|
306
|
+
} catch {}
|
|
307
|
+
return t[i] = r(n(i, a)), t;
|
|
308
|
+
}, {}) : e;
|
|
309
|
+
}
|
|
310
|
+
try {
|
|
311
|
+
let t = r(JSON.parse(e));
|
|
312
|
+
return JSON.stringify(t);
|
|
313
|
+
} catch {
|
|
314
|
+
return e;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/parsers/parseToDate.ts
|
|
319
|
+
function j([e, t = "00:00:00"], n, i = 0) {
|
|
320
|
+
let a = new r();
|
|
321
|
+
a.validateInputFormat(n);
|
|
322
|
+
let o = e.split(/[-/]/).map(Number), s = t.split(".")[0].split(":").map(Number), c, l, u, [d = 0, f = 0, p = 0] = s;
|
|
323
|
+
switch (n) {
|
|
324
|
+
case "brazilianDate":
|
|
325
|
+
[c, l, u] = o, a.validateDateParts(u, l, c);
|
|
326
|
+
break;
|
|
327
|
+
case "isoDate":
|
|
328
|
+
[l, c, u] = o, a.validateDateParts(u, l, c);
|
|
329
|
+
break;
|
|
330
|
+
case "timestamp":
|
|
331
|
+
[u, l, c] = o, a.validateDateParts(u, l, c);
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
let m = new Date(Date.UTC(u, l - 1, c, d, f, p));
|
|
335
|
+
if (Number.isNaN(m.getTime())) throw Error("Invalid date");
|
|
336
|
+
return m.setUTCHours(m.getUTCHours() + i), m;
|
|
337
|
+
}
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/utilities/calculateCardInstallment.ts
|
|
340
|
+
function M(e) {
|
|
341
|
+
let { cashPrice: t, numberInstallments: n, fees: r = .0349 } = e;
|
|
342
|
+
if (r === 0 || n === 1) return {
|
|
343
|
+
totalPrice: t,
|
|
344
|
+
installmentPrice: t / n
|
|
345
|
+
};
|
|
346
|
+
if (n <= 0) throw Error("Number of installments must be greater than 0");
|
|
347
|
+
if (r < 0) throw Error("Fees must be greater than or equal to 0");
|
|
348
|
+
let i = +(t * ((1 + r) ** n * r / ((1 + r) ** n - 1))).toFixed(2);
|
|
349
|
+
return {
|
|
350
|
+
totalPrice: +(+(i * n).toFixed(2)).toFixed(2),
|
|
351
|
+
installmentPrice: +i.toFixed(2)
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
//#endregion
|
|
355
|
+
//#region src/utilities/ensureQuotes.ts
|
|
356
|
+
function N(e) {
|
|
357
|
+
let t = e.startsWith("'") && e.endsWith("'"), n = e.startsWith("\"") && e.endsWith("\"");
|
|
358
|
+
return t || n ? e : `"${e}"`;
|
|
359
|
+
}
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/utilities/isHtml.ts
|
|
362
|
+
function P(e) {
|
|
363
|
+
return /<\/?[a-z][\s\S]*>/i.test(e);
|
|
364
|
+
}
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region src/utilities/stripHtmlTags.ts
|
|
367
|
+
function F(e) {
|
|
368
|
+
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, "");
|
|
369
|
+
}
|
|
370
|
+
//#endregion
|
|
371
|
+
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 };
|
|
372
|
+
|
|
373
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/services/validateDateService.ts","../src/formats/formatDate.ts","../src/formats/formatJsonObject.ts","../src/formats/formatJsonString.ts","../src/formats/formatToCapitalizeFirstWordLetter.ts","../src/utilities/removeNonNumeric.ts","../src/formats/formatToCep.ts","../src/formats/formatToCnpj.ts","../src/formats/formatToCpf.ts","../src/utilities/removeCurrencySymbols.ts","../src/formats/formatToCurrency.ts","../src/formats/formatToEllipsis.ts","../src/formats/formatToHiddenDigits.ts","../src/utilities/findCountryMask.ts","../src/formats/formatToPhone.ts","../src/generators/generateColorByString.ts","../src/generators/generateId.ts","../src/generators/generateSlug.ts","../src/parsers/parseLargeFields.ts","../src/parsers/parseSensitiveData.ts","../src/parsers/parseToDate.ts","../src/utilities/calculateCardInstallment.ts","../src/utilities/ensureQuotes.ts","../src/utilities/isHtml.ts","../src/utilities/stripHtmlTags.ts"],"sourcesContent":["/**\n * Validates date components and input format strings for date-parsing utilities.\n * Enforces 4-digit years, month/day ranges, month-specific day counts, and leap year rules.\n *\n * @example\n * ```typescript\n * const service = new ValidateDateService();\n * service.validateDateParts(2024, 2, 29); // OK — leap year\n * service.validateDateParts(2023, 2, 29); // throws — not a leap year\n * service.validateInputFormat(\"brazilianDate\"); // OK\n * service.validateInputFormat(\"custom\"); // throws\n * ```\n */\n\nclass ValidateDateService {\n\tprivate isLeapYear(year: number): boolean {\n\t\treturn (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n\t}\n\n\tprivate getDaysInMonth(month: number, year: number): number {\n\t\tconst daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n\t\tif (month === 2 && this.isLeapYear(year)) return 29;\n\t\treturn daysInMonth[month - 1];\n\t}\n\n\tprivate validateDayInMonth(day: number, month: number, year: number): void {\n\t\tconst maxDays = this.getDaysInMonth(month, year);\n\n\t\tif (day > maxDays) {\n\t\t\tconst monthNames = [\n\t\t\t\t\"January\",\n\t\t\t\t\"February\",\n\t\t\t\t\"March\",\n\t\t\t\t\"April\",\n\t\t\t\t\"May\",\n\t\t\t\t\"June\",\n\t\t\t\t\"July\",\n\t\t\t\t\"August\",\n\t\t\t\t\"September\",\n\t\t\t\t\"October\",\n\t\t\t\t\"November\",\n\t\t\t\t\"December\",\n\t\t\t];\n\n\t\t\tconst errorMessage = `Day ${day} is not valid for ${monthNames[month - 1]}`;\n\t\t\tconst leapYearMessage = `Day ${day} is not valid for February ${year} (non-leap year)`;\n\n\t\t\tif (month === 2 && day === 29) throw new Error(leapYearMessage);\n\t\t\tthrow new Error(errorMessage);\n\t\t}\n\t}\n\n\t/**\n\t * Throws if year, month, or day are out of valid range or inconsistent with the calendar.\n\t *\n\t * @param year - 4-digit year (1000–9999).\n\t * @param month - Month number (1–12).\n\t * @param day - Day number (1–31, validated against the specific month).\n\t */\n\tvalidateDateParts(year: number, month: number, day: number): void {\n\t\tconst messageErrors = {\n\t\t\tyear: \"Year should be four digits\",\n\t\t\tmonth: \"Month should be between 1 and 12\",\n\t\t\tday: \"Day should be between 1 and 31\",\n\t\t};\n\n\t\tif (`${year}`.length !== 4) throw new Error(messageErrors.year);\n\t\tif (month < 1 || month > 12) throw new Error(messageErrors.month);\n\t\tif (day < 1 || day > 31) throw new Error(messageErrors.day);\n\n\t\tthis.validateDayInMonth(day, month, year);\n\t}\n\n\t/**\n\t * Throws if `format` is not one of `\"brazilianDate\"`, `\"isoDate\"`, or `\"timestamp\"`.\n\t *\n\t * @param format - The format string to check.\n\t */\n\tvalidateInputFormat(format: string): void {\n\t\tconst validFormats = [\"brazilianDate\", \"isoDate\", \"timestamp\"];\n\t\tif (!validFormats.includes(format)) {\n\t\t\tthrow new Error(`Invalid input format: ${format}`);\n\t\t}\n\t}\n}\n\nexport { ValidateDateService };\n","import { ValidateDateService } from \"../services/validateDateService\";\n\nfunction formatDateString(date: Date, format: string): string {\n\tconst pad = (num: number) => num.toString().padStart(2, \"0\");\n\n\tconst replacements: Record<string, string> = {\n\t\tYYYY: date.getUTCFullYear().toString(),\n\t\tYY: date.getUTCFullYear().toString().slice(-2),\n\t\tMM: pad(date.getUTCMonth() + 1),\n\t\tDD: pad(date.getUTCDate()),\n\t\thh: pad(date.getUTCHours()),\n\t\tmm: pad(date.getUTCMinutes()),\n\t\tss: pad(date.getUTCSeconds()),\n\t};\n\n\treturn format.replace(\n\t\t/YYYY|YY|MM|DD|hh|mm|ss/g,\n\t\t(match) => replacements[match],\n\t);\n}\n\n/**\n * Formats a date (and optional time) string into a custom output format.\n * All calculations are in UTC+0; use the `timezone` parameter to shift the result.\n *\n * @param date - Date string in the format determined by `inputFormat`.\n * @param time - Optional time string `\"HH:mm:ss\"` (defaults to `\"00:00:00\"`).\n * @param inputFormat - Parsing format:\n * - `\"brazilianDate\"`: DD/MM/YYYY\n * - `\"isoDate\"`: MM-DD-YYYY\n * - `\"timestamp\"`: YYYY-MM-DD\n * @param outputFormat - Output template using `YYYY`, `MM`, `DD`, `hh`, `mm`, `ss` placeholders.\n * @param timezone - UTC offset in hours (e.g. `-3` for UTC-3). Defaults to `0`.\n * @returns The formatted date string.\n *\n * @example\n * ```typescript\n * formatDate([\"25/12/2023\", \"15:30:00\"], \"brazilianDate\", \"YYYY-MM-DD hh:mm\");\n * // \"2023-12-25 15:30\"\n *\n * formatDate([\"2023-12-25\", \"15:30:00\"], \"timestamp\", \"DD/MM/YYYY hh:mm\", -3);\n * // \"2023-12-25 12:30\"\n * ```\n */\n\nfunction formatDate(\n\t[date, time = \"00:00:00\"]: string[],\n\tinputFormat: \"brazilianDate\" | \"isoDate\" | \"timestamp\",\n\toutputFormat: string,\n\ttimezone: number = 0,\n): string {\n\tconst validateDateService = new ValidateDateService();\n\tvalidateDateService.validateInputFormat(inputFormat);\n\n\tconst dateParts = date.split(/[-/]/).map(Number);\n\tconst timeParts = time.split(\".\")[0].split(\":\").map(Number);\n\n\tlet day: number, month: number, year: number;\n\tconst [hours = 0, minutes = 0, seconds = 0] = timeParts;\n\n\tswitch (inputFormat) {\n\t\tcase \"brazilianDate\":\n\t\t\t[day, month, year] = dateParts;\n\t\t\tvalidateDateService.validateDateParts(year, month, day);\n\t\t\tbreak;\n\t\tcase \"isoDate\":\n\t\t\t[month, day, year] = dateParts;\n\t\t\tvalidateDateService.validateDateParts(year, month, day);\n\t\t\tbreak;\n\t\tcase \"timestamp\":\n\t\t\t[year, month, day] = dateParts;\n\t\t\tvalidateDateService.validateDateParts(year, month, day);\n\t\t\tbreak;\n\t}\n\n\tconst formattedDate = new Date(\n\t\tDate.UTC(year, month - 1, day, hours, minutes, seconds),\n\t);\n\n\tif (Number.isNaN(formattedDate.getTime())) throw new Error(\"Invalid date\");\n\n\tformattedDate.setUTCHours(formattedDate.getUTCHours() + timezone);\n\n\treturn formatDateString(formattedDate, outputFormat);\n}\n\nexport { formatDate };\n","/**\n * Formats a JSON object into a human-readable string with proper indentation.\n *\n * - If the input is an object, it will be formatted with keys and values properly indented.\n * - If the input is an array, each element will be formatted and indented on a new line.\n * - If the input is a string that can be parsed as JSON, it will attempt to parse and format it.\n * - Primitive values (e.g., numbers, booleans, null) will be converted to their string representation.\n *\n * @param json - The value to format: object, array, string, or primitive.\n * @param indentLevel - Current indentation depth (used recursively; pass `0` at the top level).\n * @returns A pretty-printed string representation of the value.\n *\n * @example\n * ```typescript\n * const obj = { name: \"John\", age: 30, hobbies: [\"reading\", \"gaming\"] };\n * const formatted = formatJsonObject(obj, 0);\n * console.log(formatted);\n * // Output:\n * // {\n * // \"name\": \"John\",\n * // \"age\": 30,\n * // \"hobbies\": [\n * // \"reading\",\n * // \"gaming\"\n * // ]\n * // }\n * ```\n */\n\n// biome-ignore lint/suspicious/noExplicitAny: intentional\nconst formatJsonObject = (json: any, indentLevel: number): string => {\n\tconst indent = \" \".repeat(indentLevel);\n\tlet formattedString = \"\";\n\n\tif (typeof json === \"object\" && json !== null) {\n\t\tif (Array.isArray(json)) {\n\t\t\tif (json.length === 0) {\n\t\t\t\t// Caso especial para arrays vazios\n\t\t\t\tformattedString += \"[]\";\n\t\t\t} else {\n\t\t\t\tformattedString += \"[\\n\";\n\t\t\t\tjson.forEach((item, index) => {\n\t\t\t\t\tformattedString += `${indent} ${formatJsonObject(item, indentLevel + 1)}`;\n\t\t\t\t\tif (index < json.length - 1) {\n\t\t\t\t\t\tformattedString += \",\";\n\t\t\t\t\t}\n\t\t\t\t\tformattedString += \"\\n\";\n\t\t\t\t});\n\t\t\t\tformattedString += `${indent}]`;\n\t\t\t}\n\t\t} else {\n\t\t\tconst keys = Object.keys(json);\n\t\t\tif (keys.length === 0) {\n\t\t\t\t// Caso especial para objetos vazios\n\t\t\t\tformattedString += \"{}\";\n\t\t\t} else {\n\t\t\t\tformattedString += \"{\\n\";\n\t\t\t\tkeys.forEach((key, index) => {\n\t\t\t\t\tformattedString +=\n\t\t\t\t\t\tindent +\n\t\t\t\t\t\t' \"' +\n\t\t\t\t\t\tkey +\n\t\t\t\t\t\t'\": ' +\n\t\t\t\t\t\tformatJsonObject(json[key], indentLevel + 1);\n\t\t\t\t\tif (index < keys.length - 1) {\n\t\t\t\t\t\tformattedString += \",\";\n\t\t\t\t\t}\n\t\t\t\t\tformattedString += \"\\n\";\n\t\t\t\t});\n\t\t\t\tformattedString += `${indent}}`;\n\t\t\t}\n\t\t}\n\t} else if (typeof json === \"string\") {\n\t\ttry {\n\t\t\tconst parsedObj = JSON.parse(json);\n\t\t\tformattedString += formatJsonObject(parsedObj, indentLevel);\n\t\t} catch {\n\t\t\tformattedString += `\"${json}\"`;\n\t\t}\n\t} else {\n\t\tformattedString += json;\n\t}\n\n\treturn formattedString;\n};\n\nexport { formatJsonObject };\n","import { formatJsonObject } from \"./formatJsonObject\";\n\ntype FormatJsonStringFunction = (jsonString: string) => string;\n\n/**\n * Parses a JSON string and returns a human-readable pretty-printed representation.\n * Throws if the input is not valid JSON.\n *\n * @param jsonString - A valid JSON string to format.\n * @returns A pretty-printed string representation.\n *\n * @example\n * ```typescript\n * formatJsonString('{\"name\":\"John\",\"hobbies\":[\"reading\",\"gaming\"]}');\n * // {\n * // \"name\": \"John\",\n * // \"hobbies\": [\n * // \"reading\",\n * // \"gaming\"\n * // ]\n * // }\n * ```\n */\n\nconst formatJsonString: FormatJsonStringFunction = (jsonString) => {\n\ttry {\n\t\tconst jsonObject = JSON.parse(jsonString);\n\t\treturn formatJsonObject(jsonObject, 0);\n\t} catch (error) {\n\t\tthrow new Error(`Invalid JSON string \\n ${error}`);\n\t}\n};\n\nexport { formatJsonString };\n","/**\n * Capitalizes the first letter of each word and lowercases the rest.\n * Words are separated by spaces.\n *\n * @param sentence - The string to format.\n * @returns The sentence with every word title-cased.\n *\n * @example\n * ```typescript\n * formatToCapitalizeFirstWordLetter(\"hello world\"); // \"Hello World\"\n * formatToCapitalizeFirstWordLetter(\"HELLO WORLD\"); // \"Hello World\"\n * ```\n */\n\nfunction formatToCapitalizeFirstWordLetter(sentence: string) {\n\tconst words = sentence.split(\" \");\n\n\tconst capitalizedWords = words.map((word) => {\n\t\tconst firstLetter = word.charAt(0).toUpperCase();\n\t\tconst restOfWord = word.slice(1).toLowerCase();\n\t\treturn firstLetter + restOfWord;\n\t});\n\n\treturn capitalizedWords.join(\" \");\n}\n\nexport { formatToCapitalizeFirstWordLetter };\n","/**\n * Removes all non-numeric characters from a given string.\n *\n * @param rawString - The input string to strip non-numeric characters from.\n * @returns A new string containing only the numeric characters from the input.\n *\n * @example\n * ```typescript\n * const result = removeNonNumeric(\"abc123def456\");\n * console.log(result); // Output: \"123456\"\n * ```\n */\n\nfunction removeNonNumeric(rawString: string): string {\n\treturn rawString.replace(/[^0-9]/g, \"\");\n}\n\nexport { removeNonNumeric };\n","import { removeNonNumeric } from \"../utilities/removeNonNumeric\";\n\n/**\n * Formats a given string into a Brazilian postal code (CEP) format.\n *\n * The function removes all non-numeric characters from the input string\n * and attempts to format it as a CEP in the pattern `XXXXX-XXX`.\n * If the input does not match the expected format, an error is thrown.\n *\n * @param value - Input string with 8 numeric digits (special characters are stripped).\n * @returns The formatted CEP string in the pattern `XXXXX-XXX`.\n *\n * @throws {Error} If the input does not match the expected CEP format.\n *\n * @example\n * ```typescript\n * const formattedCep = formatToCep(\"12345678\");\n * console.log(formattedCep); // Output: \"12345-678\"\n * ```\n */\n\nfunction formatToCep(value: string): string {\n\tconst cleaned = removeNonNumeric(value);\n\tconst match = cleaned.match(/^(\\d{5})(\\d{3})$/);\n\n\tconst errorMessage = `CEP must be contain 8 numeric digits: ${value}`;\n\tif (!match) throw new Error(errorMessage);\n\n\treturn `${match[1]}-${match[2]}`;\n}\n\nexport { formatToCep };\n","import { removeNonNumeric } from \"../utilities/removeNonNumeric\";\n\n/**\n * Formats a given string or number into a CNPJ (Cadastro Nacional da Pessoa Jurídica) format.\n *\n * The CNPJ format is: `XX.XXX.XXX/XXXX-XX`, where `X` represents a digit.\n *\n * @param value - Input string with 14 numeric digits (special characters are stripped).\n * @returns The formatted CNPJ string in the pattern `XX.XXX.XXX/XXXX-XX`.\n *\n * @throws {Error} Throws an error if the input does not contain exactly 14 numeric digits.\n *\n * @example\n * ```typescript\n * const formattedCnpj = formatToCnpj(\"12345678000195\");\n * console.log(formattedCnpj); // Output: \"12.345.678/0001-95\"\n * ```\n */\n\nfunction formatToCnpj(value: string): string {\n\tconst cleaned = removeNonNumeric(value);\n\tconst match = cleaned.match(/^(\\d{2})(\\d{3})(\\d{3})(\\d{4})(\\d{2})$/);\n\n\tconst errorMessage = `CNPJ must be contain 14 numeric digits: ${value}`;\n\tif (!match) throw new Error(errorMessage);\n\n\treturn `${match[1]}.${match[2]}.${match[3]}/${match[4]}-${match[5]}`;\n}\n\nexport { formatToCnpj };\n","import { removeNonNumeric } from \"../utilities/removeNonNumeric\";\n\n/**\n * Formats a given string into a CPF (Cadastro de Pessoas Físicas) format.\n *\n * A CPF is a Brazilian individual taxpayer registry identification format.\n * This function ensures the input is cleaned of non-numeric characters and\n * then formats it into the standard CPF format: `XXX.XXX.XXX-XX`.\n *\n * @param value - Input string with 11 numeric digits (special characters are stripped).\n * @returns The formatted CPF string in the pattern `XXX.XXX.XXX-XX`.\n *\n * @throws {Error} If the input string does not match the expected CPF format.\n *\n * @example\n * ```typescript\n * const formattedCpf = formatToCpf(\"12345678909\");\n * console.log(formattedCpf); // Output: \"123.456.789-09\"\n * ```\n */\n\nfunction formatToCpf(value: string): string {\n\tconst cleaned = removeNonNumeric(value);\n\tconst match = cleaned.match(/^(\\d{3})(\\d{3})(\\d{3})(\\d{2})$/);\n\n\tconst errorMessage = `CPF must be contain 11 numeric digits: ${value}`;\n\tif (!match) throw new Error(errorMessage);\n\n\treturn `${match[1]}.${match[2]}.${match[3]}-${match[4]}`;\n}\n\nexport { formatToCpf };\n","/**\n * Removes currency symbols from a given formatted string.\n *\n * This function takes a string that may contain currency symbols\n * and removes them using a regular expression. The resulting string\n * is also trimmed of any leading or trailing whitespace.\n *\n * @param rawString - The formatted string that may contain currency symbols.\n * @returns The string with all currency symbols removed and trimmed of whitespace.\n *\n * @example\n * ```typescript\n * removeCurrencySymbols(\"R$13,45\"); // \"13,45\"\n * removeCurrencySymbols(\"$123.45\"); // \"123.45\"\n * removeCurrencySymbols(\"€99.99\"); // \"99.99\"\n * removeCurrencySymbols(\"¥1,000\"); // \"1,000\"\n * removeCurrencySymbols(\"123.45\"); // \"123.45\" (no symbols to remove)\n * ```\n */\n\nfunction removeCurrencySymbols(rawString: string): string {\n\treturn rawString.replace(/(?:R\\$|\\p{Sc}|[$€¥£])/gu, \"\").trim();\n}\n\nexport { removeCurrencySymbols };\n","import { countryCurrencies } from \"@arkyn/templates\";\nimport { removeCurrencySymbols } from \"../utilities/removeCurrencySymbols\";\n\ntype Currencies = keyof typeof countryCurrencies;\n\n/**\n * Formats a number into a locale-aware currency string using `Intl.NumberFormat`.\n *\n * @param value - The numeric value to format.\n * @param currency - A currency code from `@arkyn/templates` (e.g. `\"BRL\"`, `\"USD\"`).\n * @param config.showPrefix - Whether to include the currency symbol. Defaults to `true`.\n * @returns The formatted currency string.\n *\n * @example\n * ```typescript\n * formatToCurrency(1234.56, \"BRL\"); // \"R$ 1.234,56\"\n * formatToCurrency(1234.56, \"USD\", { showPrefix: false }); // \"1,234.56\"\n * ```\n */\nfunction formatToCurrency(\n\tvalue: number,\n\tcurrency: Currencies,\n\tconfig?: { showPrefix?: boolean },\n): string {\n\tif (!countryCurrencies?.[currency]) {\n\t\tthrow new Error(\"Unsupported currency code\");\n\t}\n\n\tconst showPrefix = config?.showPrefix ?? true;\n\n\tconst { countryCurrency, countryLanguage } = countryCurrencies[currency];\n\n\tconst format = new Intl.NumberFormat(countryLanguage, {\n\t\tstyle: \"currency\",\n\t\tcurrency: countryCurrency,\n\t}).format(value);\n\n\treturn showPrefix\n\t\t? format.replace(/\\s/g, \" \")\n\t\t: removeCurrencySymbols(format).replace(/\\s/g, \" \");\n}\n\nexport { formatToCurrency };\n","/**\n * Truncates a given text to a specified maximum length and appends an ellipsis (\"...\")\n * if the text exceeds the maximum length.\n *\n * @param text - The input string to be truncated.\n * @param maxLength - Maximum allowed length before truncation.\n * @returns The truncated string with `\"...\"` appended, or the original string if it fits.\n * @example\n * ```typescript\n * const result = formatToEllipsis(\"Hello, world!\", 5);\n * console.log(result); // Output: \"Hello...\"\n * ```\n */\n\nfunction formatToEllipsis(text: string, maxLength: number): string {\n\tif (text.length > maxLength) {\n\t\tlet trimmedText = text.substring(0, maxLength);\n\n\t\t// Find the last space to avoid breaking words\n\t\tconst lastSpaceIndex = trimmedText.lastIndexOf(\" \");\n\t\tif (lastSpaceIndex > 0) {\n\t\t\ttrimmedText = trimmedText.substring(0, lastSpaceIndex);\n\t\t}\n\n\t\t// Remove trailing punctuation\n\t\ttrimmedText = trimmedText.replace(/[\\s.,!?;:]+$/, \"\");\n\n\t\t// If after removing punctuation the text is empty or only contains punctuation/spaces, return only \"...\"\n\t\tif (trimmedText.trim().length === 0 || /^[.,!?;:\\s]+$/.test(trimmedText)) {\n\t\t\treturn \"...\";\n\t\t}\n\n\t\treturn `${trimmedText}...`;\n\t}\n\n\treturn text;\n}\n\nexport { formatToEllipsis };\n","const DIGIT = /^\\d$/;\n\ntype DigitCharacterNode = {\n\tkind: \"digit\";\n\tdigit: number;\n\tcharacter: string;\n};\n\ntype OtherCharacterNode = {\n\tkind: \"other\";\n\tcharacter: string;\n};\n\ntype RootCharacterNode = {\n\tkind: \"root\";\n\tdigits: number;\n\tchildren: (DigitCharacterNode | OtherCharacterNode)[];\n};\n\nconst parseToCharacters = (value: string): RootCharacterNode => {\n\tlet digits = 0;\n\n\tconst children = value\n\t\t.split(\"\")\n\t\t.map((character: string): DigitCharacterNode | OtherCharacterNode => {\n\t\t\tif (DIGIT.test(character))\n\t\t\t\treturn { character, kind: \"digit\", digit: ++digits };\n\t\t\treturn { character, kind: \"other\" };\n\t\t});\n\n\treturn { digits, children, kind: \"root\" };\n};\n\nconst normalizeRange = (\n\trange: number | [number, number],\n\tlimit: number,\n): [number, number] => {\n\tif (Array.isArray(range)) return range;\n\tif (range >= 0) return [0, range];\n\treturn [limit + 1 - Math.abs(range), limit];\n};\n\nconst within = (range: [number, number], value: number): boolean =>\n\tvalue >= range[0] && value <= range[1];\n\n/**\n * Replaces specific digits in a string with a masking character, leaving non-digit characters unchanged.\n *\n * @param value - The input string to mask.\n * @param options.range - Which digits to hide:\n * - Positive number `n` — hides the first `n` digits.\n * - Negative number `-n` — hides the last `n` digits.\n * - Tuple `[start, end]` — hides digits from position `start` to `end` (inclusive, 1-indexed).\n * - Defaults to `3`.\n * @param options.hider - The masking character. Defaults to `\"*\"`.\n * @returns The string with the specified digit positions replaced.\n *\n * @example\n * ```typescript\n * formatToHiddenDigits(\"123-456-7890\", { range: 3 }); // \"***-456-7890\"\n * formatToHiddenDigits(\"123-456-7890\", { range: [4, 6], hider: \"#\" }); // \"123-###-7890\"\n * ```\n */\n\nfunction formatToHiddenDigits(\n\tvalue: string,\n\toptions?: { range?: number | [number, number]; hider?: string },\n): string {\n\tconst characters = parseToCharacters(value);\n\tconst range = normalizeRange(options?.range ?? 3, characters.digits);\n\n\tconst mappedCharacters = characters.children.map((node) => {\n\t\tif (node.kind === \"digit\" && within(range, node.digit))\n\t\t\treturn options?.hider ?? \"*\";\n\t\treturn node.character;\n\t});\n\n\treturn mappedCharacters.join(\"\");\n}\n\nexport { formatToHiddenDigits };\n","import { type CountryType, countries } from \"@arkyn/templates\";\nimport { parsePhoneNumberWithError } from \"libphonenumber-js\";\nimport { removeNonNumeric } from \"./removeNonNumeric\";\n\n/**\n * Resolves the matching phone mask and country metadata for a given phone number.\n * Masks use `\"_\"` as digit placeholders. For countries with multiple mask lengths\n * (e.g. Brazil with and without the ninth digit), the mask matching the number's\n * digit count is returned.\n *\n * @param phoneNumber - Phone number in E.164 format (e.g. `\"+5511999999999\"`).\n * @returns A tuple of `[maskString, CountryType]`.\n * @throws If the number is invalid or no mask is found for the parsed country.\n *\n * @example\n * ```typescript\n * const [mask, country] = findCountryMask(\"+5511999999999\");\n * // mask: \"(__) _____-____\"\n * // country.name: \"Brazil\"\n * ```\n */\n\nfunction findCountryMask(phoneNumber: string): [string, CountryType] {\n\ttry {\n\t\tconst parsedPhone = parsePhoneNumberWithError(phoneNumber);\n\n\t\tconst countryCode = parsedPhone?.country;\n\t\tif (!countryCode) throw new Error(\"Invalid phone number\");\n\n\t\tconst country = countries.find((c) => c.iso === countryCode);\n\t\tif (!country) throw new Error(\"Phone number country not supported\");\n\n\t\tif (typeof country.mask === \"string\") return [country.mask, country];\n\n\t\tconst maskForLength = country.mask.find((mask) => {\n\t\t\tconst maskDigits = mask.replace(/[^_]/g, \"\");\n\t\t\tconst phoneDigits = removeNonNumeric(parsedPhone.nationalNumber);\n\n\t\t\tconst maskDigitsCount = maskDigits.length;\n\t\t\tconst phoneDigitsCount = phoneDigits.length;\n\n\t\t\treturn maskDigitsCount === phoneDigitsCount;\n\t\t});\n\n\t\tif (!maskForLength) {\n\t\t\tthrow new Error(\"No mask found for the given phone number length\");\n\t\t}\n\n\t\treturn [maskForLength, country];\n\t} catch (rawError) {\n\t\tconst error = rawError as Error;\n\t\tthrow new Error(error.message);\n\t}\n}\n\nexport { findCountryMask };\n","import { parsePhoneNumberWithError } from \"libphonenumber-js\";\nimport { findCountryMask } from \"../utilities/findCountryMask\";\n\n/**\n * Formats a phone number string according to the country mask defined in `@arkyn/templates`.\n *\n * The function parses the input using libphonenumber-js to determine the country and\n * national number, then applies the corresponding country's mask (underscore `_` used\n * as digit placeholder) replacing placeholders with actual digits.\n *\n * @param phoneNumber - The input phone number in E.164 format (e.g. `\"+5534920524282\"`).\n * @returns The phone number formatted according to the country's mask.\n *\n * @throws {Error} If the phone number is invalid or if no country mask is found for the parsed country.\n *\n * @example\n * ```typescript\n * console.log(formatToPhone(\"+5534920524282\")); // Output: \"(34) 92052-4282\" (Brazilian format)\n * console.log(formatToPhone(\"+553420524282\")); // Output: \"(34) 2052-4282\" (Brazilian format with optional ninth digit)\n * console.log(formatToPhone(\"+12125550199\")); // Output: \"(212) 555-0199\" (American Samoa format)\n * ```\n */\n\nfunction formatToPhone(phoneNumber: string): string {\n\ttry {\n\t\tconst parsedPhone = parsePhoneNumberWithError(phoneNumber);\n\t\tconst phoneNumberDigits = parsedPhone.nationalNumber.toString();\n\n\t\tlet formattedNumber = findCountryMask(phoneNumber)[0];\n\n\t\tfor (\n\t\t\tlet i = 0, j = 0;\n\t\t\ti < formattedNumber.length && j < phoneNumberDigits.length;\n\t\t\ti++\n\t\t) {\n\t\t\tif (formattedNumber[i] === \"_\") {\n\t\t\t\tformattedNumber =\n\t\t\t\t\tformattedNumber.substring(0, i) +\n\t\t\t\t\tphoneNumberDigits[j] +\n\t\t\t\t\tformattedNumber.substring(i + 1);\n\t\t\t\tj++;\n\t\t\t}\n\t\t}\n\n\t\treturn formattedNumber;\n\t} catch (rawError) {\n\t\tconst error = rawError as Error;\n\t\tthrow new Error(error.message);\n\t}\n}\n\nexport { formatToPhone };\n","/**\n * Generates a hexadecimal color code based on the input string.\n * The function creates a hash from the string and uses it to calculate\n * RGB values, which are then converted to a hexadecimal color code.\n *\n * @param rawString - The input string used to generate the color.\n * @returns A hexadecimal color code (e.g., `\"#a1b2c3\"`) derived from the input string.\n *\n * @example\n * ```typescript\n * const color = generateColorByString(\"example\");\n * console.log(color); // Outputs a consistent hex color like \"#5e8f9a\"\n * ```\n */\n\nfunction generateColorByString(rawString: string): string {\n\tlet hash = 0;\n\n\tfor (let i = 0; i < rawString.length; i++) {\n\t\thash = rawString.charCodeAt(i) + ((hash << 5) - hash);\n\t}\n\n\tconst red = (hash & 0xff0000) >> 16;\n\tconst green = (hash & 0x00ff00) >> 8;\n\tconst blue = hash & 0x0000ff;\n\n\tconst redHex = red.toString(16).padStart(2, \"0\");\n\tconst greenHex = green.toString(16).padStart(2, \"0\");\n\tconst blueHex = blue.toString(16).padStart(2, \"0\");\n\n\treturn `#${redHex}${greenHex}${blueHex}`;\n}\n\nexport { generateColorByString };\n","function hexToBin(hex: string) {\n\thex = hex.replace(/-/g, \"\");\n\tconst buffer = new Uint8Array(hex.length / 2);\n\n\tfor (let i = 0; i < hex.length; i += 2) {\n\t\tbuffer[i / 2] = parseInt(hex.substring(i, i + 2), 16);\n\t}\n\n\treturn buffer;\n}\n\nfunction uuidV4() {\n\tconst uuid = crypto.randomUUID();\n\treturn { text: uuid, binary: hexToBin(uuid) };\n}\n\nfunction uuidV7() {\n\tconst bytes = crypto.getRandomValues(new Uint8Array(16));\n\n\tconst ts = BigInt(Date.now());\n\n\tbytes[0] = Number((ts >> 40n) & 0xffn);\n\tbytes[1] = Number((ts >> 32n) & 0xffn);\n\tbytes[2] = Number((ts >> 24n) & 0xffn);\n\tbytes[3] = Number((ts >> 16n) & 0xffn);\n\tbytes[4] = Number((ts >> 8n) & 0xffn);\n\tbytes[5] = Number(ts & 0xffn);\n\n\t// versão 7\n\tbytes[6] = (bytes[6] & 0x0f) | 0x70;\n\n\t// variante RFC 4122\n\tbytes[8] = (bytes[8] & 0x3f) | 0x80;\n\n\tconst uuid = [...bytes]\n\t\t.map((b) => b.toString(16).padStart(2, \"0\"))\n\t\t.join(\"\")\n\t\t.replace(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/, \"$1-$2-$3-$4-$5\");\n\n\treturn {\n\t\ttext: uuid,\n\t\tbinary: hexToBin(uuid),\n\t};\n}\n\n/**\n * Generates a UUID in the specified version and output type.\n *\n * @param type - Output representation: `\"text\"` (string) or `\"binary\"` (`Uint8Array`).\n * @param format - UUID version: `\"v4\"` (random) or `\"v7\"` (time-ordered).\n * @returns The UUID as a string or `Uint8Array` depending on `type`.\n *\n * @example\n * ```typescript\n * generateId(\"text\", \"v4\"); // \"550e8400-e29b-41d4-a716-446655440000\"\n * generateId(\"binary\", \"v7\"); // Uint8Array([...])\n * ```\n */\nfunction generateId(type: \"text\", format: \"v4\" | \"v7\"): string;\nfunction generateId(type: \"binary\", format: \"v4\" | \"v7\"): Uint8Array;\nfunction generateId(\n\ttype: \"text\" | \"binary\",\n\tformat: \"v4\" | \"v7\",\n): string | Uint8Array {\n\tif (type === \"text\" && format === \"v4\") return uuidV4().text;\n\tif (type === \"binary\" && format === \"v4\") return uuidV4().binary;\n\tif (type === \"text\" && format === \"v7\") return uuidV7().text;\n\tif (type === \"binary\" && format === \"v7\") return uuidV7().binary;\n\tthrow new Error(\"Invalid type or format\");\n}\n\nexport { generateId };\n","/**\n * Generates a URL-friendly slug from a given string.\n *\n * The function performs the following transformations:\n * - Normalizes the string to remove diacritical marks (e.g., accents).\n * - Removes non-alphanumeric characters except for spaces and hyphens.\n * - Replaces spaces with hyphens.\n * - Converts the string to lowercase.\n * - Collapses multiple consecutive hyphens into a single hyphen.\n * - Trims leading and trailing hyphens.\n *\n * @param rawString - The input string to be converted into a slug.\n * @returns A URL-friendly slug derived from the input string.\n *\n * @example\n * ```typescript\n * const slug = generateSlug(\"Hello, World! This is a Test.\");\n * console.log(slug); // Outputs: \"hello-world-this-is-a-test\"\n * ```\n */\n\nfunction generateSlug(rawString: string): string {\n\tlet slug = rawString.normalize(\"NFD\").replace(/[\\u0300-\\u036f]/g, \"\");\n\n\tslug = slug\n\t\t.replace(/[^\\w\\s-]/g, \"\")\n\t\t.replace(/\\s+/g, \"-\")\n\t\t.toLowerCase();\n\n\tslug = slug.replace(/-{2,}/g, \"-\");\n\n\tslug = slug.replace(/^-+|-+$/g, \"\");\n\n\treturn slug;\n}\n\nexport { generateSlug };\n","/**\n * Truncates large string fields in a JSON string to a specified maximum length.\n *\n * This function parses a JSON string, traverses its structure recursively, and truncates\n * any string fields that exceed the specified maximum length. If a string field is truncated,\n * it is replaced with a message indicating the original length of the field.\n *\n * @param jsonString - The JSON string to process.\n * @param maxLength - The maximum allowed length for string fields. Defaults to 1000.\n * @returns A JSON string with large string fields truncated.\n *\n * @throws {Error} Throws an error if the input is not a valid JSON string.\n *\n * @example\n * ```typescript\n * const json = JSON.stringify({\n * name: \"John\",\n * description: \"A very long description that exceeds the maximum length...\",\n * nested: { details: \"Another long string that needs truncation.\" }\n * });\n *\n * const result = parseLargeFields(json, 50);\n * console.log(result);\n * // Output: '{\"name\":\"John\",\"description\":\"To large information: field as 57 characters\",\"nested\":{\"details\":\"To large information: field as 43 characters\"}}'\n * ```\n */\n\nfunction parseLargeFields(\n\tjsonString: string,\n\tmaxLength: number = 1000,\n): string {\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tfunction truncateValue(value: any): any {\n\t\tif (typeof value === \"string\" && value.length > maxLength) {\n\t\t\treturn `To large information: field as ${value.length} characters`;\n\t\t}\n\t\treturn value;\n\t}\n\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tfunction recursiveTruncate(obj: any): any {\n\t\tif (Array.isArray(obj)) {\n\t\t\treturn obj.map((item) => recursiveTruncate(item));\n\t\t} else if (obj !== null && typeof obj === \"object\") {\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries(obj).map(([key, value]) => [\n\t\t\t\t\tkey,\n\t\t\t\t\trecursiveTruncate(value),\n\t\t\t\t]),\n\t\t\t);\n\t\t}\n\t\treturn truncateValue(obj);\n\t}\n\n\ttry {\n\t\tconst parsedJson = JSON.parse(jsonString);\n\t\tconst truncatedJson = recursiveTruncate(parsedJson);\n\t\treturn JSON.stringify(truncatedJson);\n\t} catch (_error) {\n\t\tthrow new Error(\"Invalid JSON string\");\n\t}\n}\n\nexport { parseLargeFields };\n","/**\n * Masks sensitive data in a JSON string by replacing the values of specified keys with \"****\".\n *\n * @param jsonString - The JSON string to be processed.\n * @param sensitiveKeys - Keys whose values will be replaced with `\"****\"`. Defaults to `[\"password\", \"confirmPassword\", \"creditCard\"]`.\n * @returns A JSON string with sensitive values masked. Returns the original string if it is not valid JSON.\n *\n * @example\n * ```typescript\n * const jsonString = JSON.stringify({\n * username: \"user123\",\n * password: \"secret\",\n * profile: { creditCard: \"1234-5678-9012-3456\" },\n * });\n *\n * const result = parseSensitiveData(jsonString, [\"password\", \"creditCard\"]);\n * console.log(result); // Output: '{\"username\":\"user123\",\"password\":\"****\",\"profile\":{\"creditCard\":\"****\"}}'\n * ```\n */\n\nfunction parseSensitiveData(\n\tjsonString: string,\n\tsensitiveKeys: string[] = [\"password\", \"confirmPassword\", \"creditCard\"],\n): string {\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tfunction maskValue(key: string, value: any): any {\n\t\tif (sensitiveKeys.includes(key)) return \"****\";\n\t\treturn value;\n\t}\n\n\t// biome-ignore lint/suspicious/noExplicitAny: intentional\n\tfunction recursiveMask(obj: any): any {\n\t\tif (Array.isArray(obj)) {\n\t\t\treturn obj.map((item) => recursiveMask(item));\n\t\t} else if (obj !== null && typeof obj === \"object\") {\n\t\t\treturn Object.keys(obj).reduce(\n\t\t\t\t(acc, key) => {\n\t\t\t\t\tlet value = obj[key];\n\t\t\t\t\tif (typeof value === \"string\") {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst parsedValue = JSON.parse(value);\n\t\t\t\t\t\t\tif (typeof parsedValue === \"object\") {\n\t\t\t\t\t\t\t\tvalue = JSON.stringify(recursiveMask(parsedValue));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (_e) {}\n\t\t\t\t\t}\n\t\t\t\t\tacc[key] = recursiveMask(maskValue(key, value));\n\t\t\t\t\treturn acc;\n\t\t\t\t},\n\t\t\t\t{} as Record<string, unknown>,\n\t\t\t);\n\t\t}\n\t\treturn obj;\n\t}\n\n\ttry {\n\t\tconst jsonObject = JSON.parse(jsonString);\n\t\tconst maskedObject = recursiveMask(jsonObject);\n\t\treturn JSON.stringify(maskedObject);\n\t} catch (_error) {\n\t\treturn jsonString;\n\t}\n}\n\nexport { parseSensitiveData };\n","import { ValidateDateService } from \"../services/validateDateService\";\n\n/**\n * Parses a date (and optional time) string into a JavaScript `Date` object.\n * All calculations are in UTC+0; use `timezone` to shift the result.\n *\n * @param date - Date string in the format determined by `inputFormat`.\n * @param time - Optional time string `\"HH:mm:ss\"` (defaults to `\"00:00:00\"`).\n * @param inputFormat - Parsing format:\n * - `\"brazilianDate\"`: DD/MM/YYYY\n * - `\"isoDate\"`: MM-DD-YYYY\n * - `\"timestamp\"`: YYYY-MM-DD\n * @param timezone - UTC offset in hours (e.g. `-3` for UTC-3). Defaults to `0`.\n * @returns A `Date` object representing the parsed date and time.\n *\n * @example\n * ```typescript\n * parseToDate([\"25/12/2023\", \"15:30:00\"], \"brazilianDate\", -3);\n * // Date: 2023-12-25T12:30:00.000Z\n *\n * parseToDate([\"2023-12-25\"], \"timestamp\");\n * // Date: 2023-12-25T00:00:00.000Z\n * ```\n */\n\nfunction parseToDate(\n\t[date, time = \"00:00:00\"]: string[],\n\tinputFormat: \"brazilianDate\" | \"isoDate\" | \"timestamp\",\n\ttimezone: number = 0,\n): Date {\n\tconst validateDateService = new ValidateDateService();\n\tvalidateDateService.validateInputFormat(inputFormat);\n\n\tconst dateParts = date.split(/[-/]/).map(Number);\n\tconst timeParts = time.split(\".\")[0].split(\":\").map(Number);\n\n\tlet day: number, month: number, year: number;\n\tconst [hours = 0, minutes = 0, seconds = 0] = timeParts;\n\n\tswitch (inputFormat) {\n\t\tcase \"brazilianDate\":\n\t\t\t[day, month, year] = dateParts;\n\t\t\tvalidateDateService.validateDateParts(year, month, day);\n\t\t\tbreak;\n\t\tcase \"isoDate\":\n\t\t\t[month, day, year] = dateParts;\n\t\t\tvalidateDateService.validateDateParts(year, month, day);\n\t\t\tbreak;\n\t\tcase \"timestamp\":\n\t\t\t[year, month, day] = dateParts;\n\t\t\tvalidateDateService.validateDateParts(year, month, day);\n\t\t\tbreak;\n\t}\n\n\tconst formattedDate = new Date(\n\t\tDate.UTC(year, month - 1, day, hours, minutes, seconds),\n\t);\n\n\tif (Number.isNaN(formattedDate.getTime())) throw new Error(\"Invalid date\");\n\n\tformattedDate.setUTCHours(formattedDate.getUTCHours() + timezone);\n\n\treturn formattedDate;\n}\n\nexport { parseToDate };\n","/**\n * Calculates the per-installment and total price for a card payment plan with compound interest.\n * No interest is applied when `fees` is `0` or `numberInstallments` is `1`.\n *\n * @param props.cashPrice - The base price of the item.\n * @param props.numberInstallments - Number of installments (must be > 0).\n * @param props.fees - Monthly interest rate (defaults to `0.0349`).\n * @returns `{ totalPrice, installmentPrice }` — both rounded to 2 decimal places.\n *\n * @example\n * ```typescript\n * calculateCardInstallment({ cashPrice: 1000, numberInstallments: 12, fees: 0.02 });\n * // { totalPrice: 1124.62, installmentPrice: 93.72 }\n * ```\n */\n\nfunction calculateCardInstallment(props: {\n\tcashPrice: number;\n\tnumberInstallments: number;\n\tfees?: number;\n}): { totalPrice: number; installmentPrice: number } {\n\tconst { cashPrice, numberInstallments, fees = 0.0349 } = props;\n\n\tif (fees === 0 || numberInstallments === 1) {\n\t\treturn {\n\t\t\ttotalPrice: cashPrice,\n\t\t\tinstallmentPrice: cashPrice / numberInstallments,\n\t\t};\n\t}\n\n\tif (numberInstallments <= 0) {\n\t\tthrow new Error(\"Number of installments must be greater than 0\");\n\t}\n\n\tif (fees < 0) {\n\t\tthrow new Error(\"Fees must be greater than or equal to 0\");\n\t}\n\n\tconst numerator = (1 + fees) ** numberInstallments * fees;\n\tconst denominator = (1 + fees) ** numberInstallments - 1;\n\n\tconst installmentPrice = +(cashPrice * (numerator / denominator)).toFixed(2);\n\tconst totalPrice = +(installmentPrice * numberInstallments).toFixed(2);\n\n\treturn {\n\t\ttotalPrice: +totalPrice.toFixed(2),\n\t\tinstallmentPrice: +installmentPrice.toFixed(2),\n\t};\n}\n\nexport { calculateCardInstallment };\n","/**\n * Ensures that a given rawValue string is enclosed in quotes.\n *\n * This function checks if the input string is already enclosed in either single\n * quotes (`'`) or double quotes (`\"`). If the string is already quoted, it is\n * returned as-is. Otherwise, the function wraps the string in double quotes.\n *\n * @param rawValue - The string to be checked and potentially quoted.\n * @returns The original string if already quoted, otherwise the string wrapped in double quotes.\n *\n * @example\n * ```typescript\n * ensureQuotes('example'); // Returns: '\"example\"'\n * ensureQuotes('\"already quoted\"'); // Returns: '\"already quoted\"'\n * ensureQuotes(\"'single quoted'\"); // Returns: \"'single quoted'\"\n * ```\n */\n\nfunction ensureQuotes(rawValue: string): string {\n\tconst hasSingleQuotes = rawValue.startsWith(\"'\") && rawValue.endsWith(\"'\");\n\tconst hasDoubleQuotes = rawValue.startsWith('\"') && rawValue.endsWith('\"');\n\n\tif (hasSingleQuotes || hasDoubleQuotes) {\n\t\treturn rawValue;\n\t}\n\n\treturn `\"${rawValue}\"`;\n}\n\nexport { ensureQuotes };\n","/**\n * Check if a string contains HTML markup.\n *\n * This function uses a regular expression to detect the presence of HTML tags\n * in a string. The check is case-insensitive and detects both opening\n * and closing tags.\n *\n * @param rawString - The string to check.\n * @returns `true` if the string contains HTML markup, `false` otherwise.\n *\n * @example\n * ```typescript\n * isHtml('<p>Hello world</p>'); // true\n * isHtml('<div>Content</div>'); // true\n * isHtml('Plain text'); // false\n * isHtml(''); // false\n * ```\n */\n\nfunction isHtml(rawString: string): boolean {\n\tconst htmlRegex = /<\\/?[a-z][\\s\\S]*>/i;\n\treturn htmlRegex.test(rawString);\n}\n\nexport { isHtml };\n","/**\n * Strips HTML tags from a string.\n *\n * This function removes all HTML tags from the provided string by replacing any content\n * that matches the HTML tag pattern with an empty string.\n *\n * @param rawHtml - The HTML string to strip tags from.\n * @returns The plain text with all HTML tags (including `<script>`, `<style>`, and comments) removed.\n *\n * @example\n * ```typescript\n * const strippedHtml = stripHtmlTags(\"<p>Hello <strong>World</strong></p>\");\n * console.log(strippedHtml); // \"Hello World\"\n * ```\n */\n\nfunction stripHtmlTags(rawHtml: string): string {\n\treturn rawHtml\n\t\t.replace(/<script\\b[^<]*(?:(?!<\\/script>)<[^<]*)*<\\/script>/gi, \"\")\n\t\t.replace(/<style\\b[^<]*(?:(?!<\\/style>)<[^<]*)*<\\/style>/gi, \"\")\n\t\t.replace(/<!--[\\s\\S]*?-->/g, \"\")\n\t\t.replace(/<\\/?[a-z][a-z0-9]*[^>]*>/gi, \"\");\n}\n\nexport { stripHtmlTags };\n"],"mappings":";;;AAcA,IAAM,IAAN,MAA0B;CACzB,WAAmB,GAAuB;EACzC,OAAQ,IAAO,KAAM,KAAK,IAAO,OAAQ,KAAM,IAAO,OAAQ;CAC/D;CAEA,eAAuB,GAAe,GAAsB;EAG3D,OADI,MAAU,KAAK,KAAK,WAAW,CAAI,IAAU,KAC1C;GAFc;GAAI;GAAI;GAAI;GAAI;GAAI;GAAI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O,GACV,MAAU,MAAM,yCAAyC;CAM1D,IAAM,IAAmB,EAAE,MAHR,IAAI,MAAS,IAAqB,MAChC,IAAI,MAAS,IAAqB,IAAA,CAEW,QAAQ,CAAC;CAG3E,OAAO;EACN,YAAY,EAAC,EAHO,IAAmB,EAAA,CAAoB,QAAQ,CAAC,EAAA,CAG5C,QAAQ,CAAC;EACjC,kBAAkB,CAAC,EAAiB,QAAQ,CAAC;CAC9C;AACD;;;AC9BA,SAAS,EAAa,GAA0B;CAC/C,IAAM,IAAkB,EAAS,WAAW,GAAG,KAAK,EAAS,SAAS,GAAG,GACnE,IAAkB,EAAS,WAAW,IAAG,KAAK,EAAS,SAAS,IAAG;CAMzE,OAJI,KAAmB,IACf,IAGD,IAAI,EAAS;AACrB;;;ACRA,SAAS,EAAO,GAA4B;CAE3C,OAAO,qBAAU,KAAK,CAAS;AAChC;;;ACNA,SAAS,EAAc,GAAyB;CAC/C,OAAO,EACL,QAAQ,uDAAuD,EAAE,CAAC,CAClE,QAAQ,oDAAoD,EAAE,CAAC,CAC/D,QAAQ,oBAAoB,EAAE,CAAC,CAC/B,QAAQ,8BAA8B,EAAE;AAC3C"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 (Number.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 };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=formatDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatDate.js","names":[],"sources":["../../../src/formats/formatDate.ts"],"sourcesContent":["import { ValidateDateService } from \"../services/validateDateService\";\n\nfunction formatDateString(date: Date, format: string): string {\n\tconst pad = (num: number) => num.toString().padStart(2, \"0\");\n\n\tconst replacements: Record<string, string> = {\n\t\tYYYY: date.getUTCFullYear().toString(),\n\t\tYY: date.getUTCFullYear().toString().slice(-2),\n\t\tMM: pad(date.getUTCMonth() + 1),\n\t\tDD: pad(date.getUTCDate()),\n\t\thh: pad(date.getUTCHours()),\n\t\tmm: pad(date.getUTCMinutes()),\n\t\tss: pad(date.getUTCSeconds()),\n\t};\n\n\treturn format.replace(\n\t\t/YYYY|YY|MM|DD|hh|mm|ss/g,\n\t\t(match) => replacements[match],\n\t);\n}\n\n/**\n * Formats a date (and optional time) string into a custom output format.\n * All calculations are in UTC+0; use the `timezone` parameter to shift the result.\n *\n * @param date - Date string in the format determined by `inputFormat`.\n * @param time - Optional time string `\"HH:mm:ss\"` (defaults to `\"00:00:00\"`).\n * @param inputFormat - Parsing format:\n * - `\"brazilianDate\"`: DD/MM/YYYY\n * - `\"isoDate\"`: MM-DD-YYYY\n * - `\"timestamp\"`: YYYY-MM-DD\n * @param outputFormat - Output template using `YYYY`, `MM`, `DD`, `hh`, `mm`, `ss` placeholders.\n * @param timezone - UTC offset in hours (e.g. `-3` for UTC-3). Defaults to `0`.\n * @returns The formatted date string.\n *\n * @example\n * ```typescript\n * formatDate([\"25/12/2023\", \"15:30:00\"], \"brazilianDate\", \"YYYY-MM-DD hh:mm\");\n * // \"2023-12-25 15:30\"\n *\n * formatDate([\"2023-12-25\", \"15:30:00\"], \"timestamp\", \"DD/MM/YYYY hh:mm\", -3);\n * // \"2023-12-25 12:30\"\n * ```\n */\n\nfunction formatDate(\n\t[date, time = \"00:00:00\"]: string[],\n\tinputFormat: \"brazilianDate\" | \"isoDate\" | \"timestamp\",\n\toutputFormat: string,\n\ttimezone: number = 0,\n): string {\n\tconst validateDateService = new ValidateDateService();\n\tvalidateDateService.validateInputFormat(inputFormat);\n\n\tconst dateParts = date.split(/[-/]/).map(Number);\n\tconst timeParts = time.split(\".\")[0].split(\":\").map(Number);\n\n\tlet day: number, month: number, year: number;\n\tconst [hours = 0, minutes = 0, seconds = 0] = timeParts;\n\n\tswitch (inputFormat) {\n\t\tcase \"brazilianDate\":\n\t\t\t[day, month, year] = dateParts;\n\t\t\tvalidateDateService.validateDateParts(year, month, day);\n\t\t\tbreak;\n\t\tcase \"isoDate\":\n\t\t\t[month, day, year] = dateParts;\n\t\t\tvalidateDateService.validateDateParts(year, month, day);\n\t\t\tbreak;\n\t\tcase \"timestamp\":\n\t\t\t[year, month, day] = dateParts;\n\t\t\tvalidateDateService.validateDateParts(year, month, day);\n\t\t\tbreak;\n\t}\n\n\tconst formattedDate = new Date(\n\t\tDate.UTC(year, month - 1, day, hours, minutes, seconds),\n\t);\n\n\tif (Number.isNaN(formattedDate.getTime())) throw new Error(\"Invalid date\");\n\n\tformattedDate.setUTCHours(formattedDate.getUTCHours() + timezone);\n\n\treturn formatDateString(formattedDate, outputFormat);\n}\n\nexport { formatDate };\n"],"mappings":";;AAEA,SAAS,EAAiB,GAAY,GAAwB;CAC7D,IAAM,KAAO,MAAgB,EAAI,SAAS,CAAC,CAAC,SAAS,GAAG,GAAG,GAErD,IAAuC;EAC5C,MAAM,EAAK,eAAe,CAAC,CAAC,SAAS;EACrC,IAAI,EAAK,eAAe,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE;EAC7C,IAAI,EAAI,EAAK,YAAY,IAAI,CAAC;EAC9B,IAAI,EAAI,EAAK,WAAW,CAAC;EACzB,IAAI,EAAI,EAAK,YAAY,CAAC;EAC1B,IAAI,EAAI,EAAK,cAAc,CAAC;EAC5B,IAAI,EAAI,EAAK,cAAc,CAAC;CAC7B;CAEA,OAAO,EAAO,QACb,4BACC,MAAU,EAAa,EACzB;AACD;AA0BA,SAAS,EACR,CAAC,GAAM,IAAO,aACd,GACA,GACA,IAAmB,GACV;CACT,IAAM,IAAsB,IAAI,EAAoB;CACpD,EAAoB,oBAAoB,CAAW;CAEnD,IAAM,IAAY,EAAK,MAAM,MAAM,CAAC,CAAC,IAAI,MAAM,GACzC,IAAY,EAAK,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM,GAEtD,GAAa,GAAe,GAC1B,CAAC,IAAQ,GAAG,IAAU,GAAG,IAAU,KAAK;CAE9C,QAAQ,GAAR;EACC,KAAK;GAEJ,AADA,CAAC,GAAK,GAAO,KAAQ,GACrB,EAAoB,kBAAkB,GAAM,GAAO,CAAG;GACtD;EACD,KAAK;GAEJ,AADA,CAAC,GAAO,GAAK,KAAQ,GACrB,EAAoB,kBAAkB,GAAM,GAAO,CAAG;GACtD;EACD,KAAK;GAEJ,AADA,CAAC,GAAM,GAAO,KAAO,GACrB,EAAoB,kBAAkB,GAAM,GAAO,CAAG;GACtD;CACF;CAEA,IAAM,IAAgB,IAAI,KACzB,KAAK,IAAI,GAAM,IAAQ,GAAG,GAAK,GAAO,GAAS,CAAO,CACvD;CAEA,IAAI,OAAO,MAAM,EAAc,QAAQ,CAAC,GAAG,MAAU,MAAM,cAAc;CAIzE,OAFA,EAAc,YAAY,EAAc,YAAY,IAAI,CAAQ,GAEzD,EAAiB,GAAe,CAAY;AACpD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=formatJsonObject.js.map
|