@arkyn/shared 3.0.1-beta.160 → 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
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
import { ValidateDateService as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
);
|
|
22
|
-
if (isNaN(s.getTime())) throw new Error("Invalid date");
|
|
23
|
-
return s.setUTCHours(s.getUTCHours() + m), s;
|
|
1
|
+
import { ValidateDateService as e } from "../services/validateDateService.js";
|
|
2
|
+
//#region src/parsers/parseToDate.ts
|
|
3
|
+
function t([t, n = "00:00:00"], r, i = 0) {
|
|
4
|
+
let a = new e();
|
|
5
|
+
a.validateInputFormat(r);
|
|
6
|
+
let o = t.split(/[-/]/).map(Number), s = n.split(".")[0].split(":").map(Number), c, l, u, [d = 0, f = 0, p = 0] = s;
|
|
7
|
+
switch (r) {
|
|
8
|
+
case "brazilianDate":
|
|
9
|
+
[c, l, u] = o, a.validateDateParts(u, l, c);
|
|
10
|
+
break;
|
|
11
|
+
case "isoDate":
|
|
12
|
+
[l, c, u] = o, a.validateDateParts(u, l, c);
|
|
13
|
+
break;
|
|
14
|
+
case "timestamp":
|
|
15
|
+
[u, l, c] = o, a.validateDateParts(u, l, c);
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
let m = new Date(Date.UTC(u, l - 1, c, d, f, p));
|
|
19
|
+
if (isNaN(m.getTime())) throw Error("Invalid date");
|
|
20
|
+
return m.setUTCHours(m.getUTCHours() + i), m;
|
|
24
21
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { t as parseToDate };
|
|
@@ -1,59 +1,61 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
//#region src/services/validateDateService.ts
|
|
2
|
+
var e = class {
|
|
3
|
+
isLeapYear(e) {
|
|
4
|
+
return e % 4 == 0 && e % 100 != 0 || e % 400 == 0;
|
|
5
|
+
}
|
|
6
|
+
getDaysInMonth(e, t) {
|
|
7
|
+
return e === 2 && this.isLeapYear(t) ? 29 : [
|
|
8
|
+
31,
|
|
9
|
+
28,
|
|
10
|
+
31,
|
|
11
|
+
30,
|
|
12
|
+
31,
|
|
13
|
+
30,
|
|
14
|
+
31,
|
|
15
|
+
31,
|
|
16
|
+
30,
|
|
17
|
+
31,
|
|
18
|
+
30,
|
|
19
|
+
31
|
|
20
|
+
][e - 1];
|
|
21
|
+
}
|
|
22
|
+
validateDayInMonth(e, t, n) {
|
|
23
|
+
if (e > this.getDaysInMonth(t, n)) {
|
|
24
|
+
let r = `Day ${e} is not valid for ${[
|
|
25
|
+
"January",
|
|
26
|
+
"February",
|
|
27
|
+
"March",
|
|
28
|
+
"April",
|
|
29
|
+
"May",
|
|
30
|
+
"June",
|
|
31
|
+
"July",
|
|
32
|
+
"August",
|
|
33
|
+
"September",
|
|
34
|
+
"October",
|
|
35
|
+
"November",
|
|
36
|
+
"December"
|
|
37
|
+
][t - 1]}`, i = `Day ${e} is not valid for February ${n} (non-leap year)`;
|
|
38
|
+
throw Error(t === 2 && e === 29 ? i : r);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
validateDateParts(e, t, n) {
|
|
42
|
+
let r = {
|
|
43
|
+
year: "Year should be four digits",
|
|
44
|
+
month: "Month should be between 1 and 12",
|
|
45
|
+
day: "Day should be between 1 and 31"
|
|
46
|
+
};
|
|
47
|
+
if (`${e}`.length !== 4) throw Error(r.year);
|
|
48
|
+
if (t < 1 || t > 12) throw Error(r.month);
|
|
49
|
+
if (n < 1 || n > 31) throw Error(r.day);
|
|
50
|
+
this.validateDayInMonth(n, t, e);
|
|
51
|
+
}
|
|
52
|
+
validateInputFormat(e) {
|
|
53
|
+
if (![
|
|
54
|
+
"brazilianDate",
|
|
55
|
+
"isoDate",
|
|
56
|
+
"timestamp"
|
|
57
|
+
].includes(e)) throw Error(`Invalid input format: ${e}`);
|
|
58
|
+
}
|
|
59
59
|
};
|
|
60
|
+
//#endregion
|
|
61
|
+
export { e as ValidateDateService };
|
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
totalPrice: +(+(n * t).toFixed(2)).toFixed(2),
|
|
16
|
-
installmentPrice: +n.toFixed(2)
|
|
17
|
-
};
|
|
1
|
+
//#region src/utilities/calculateCardInstallment.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let { cashPrice: t, numberInstallments: n, fees: r = .0349 } = e;
|
|
4
|
+
if (r === 0 || n === 1) return {
|
|
5
|
+
totalPrice: t,
|
|
6
|
+
installmentPrice: t / n
|
|
7
|
+
};
|
|
8
|
+
if (n <= 0) throw Error("Number of installments must be greater than 0");
|
|
9
|
+
if (r < 0) throw Error("Fees must be greater than or equal to 0");
|
|
10
|
+
let i = +(t * ((1 + r) ** +n * r / ((1 + r) ** +n - 1))).toFixed(2);
|
|
11
|
+
return {
|
|
12
|
+
totalPrice: +(+(i * n).toFixed(2)).toFixed(2),
|
|
13
|
+
installmentPrice: +i.toFixed(2)
|
|
14
|
+
};
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { e as calculateCardInstallment };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/utilities/ensureQuotes.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = e.startsWith("'") && e.endsWith("'"), n = e.startsWith("\"") && e.endsWith("\"");
|
|
4
|
+
return t || n ? e : `"${e}"`;
|
|
4
5
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
6
|
+
//#endregion
|
|
7
|
+
export { e as ensureQuotes };
|
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
1
|
+
import { removeNonNumeric as e } from "./removeNonNumeric.js";
|
|
2
|
+
import { countries as t } from "@arkyn/templates";
|
|
3
|
+
import { parsePhoneNumberWithError as n } from "libphonenumber-js";
|
|
4
|
+
//#region src/utilities/findCountryMask.ts
|
|
5
|
+
function r(r) {
|
|
6
|
+
try {
|
|
7
|
+
let i = n(r), a = i?.country;
|
|
8
|
+
if (!a) throw Error("Invalid phone number");
|
|
9
|
+
let o = t.find((e) => e.iso === a);
|
|
10
|
+
if (!o) throw Error("Phone number country not supported");
|
|
11
|
+
if (typeof o.mask == "string") return [o.mask, o];
|
|
12
|
+
let s = o.mask.find((t) => {
|
|
13
|
+
let n = t.replace(/[^_]/g, ""), r = e(i.nationalNumber);
|
|
14
|
+
return n.length === r.length;
|
|
15
|
+
});
|
|
16
|
+
if (!s) throw Error("No mask found for the given phone number length");
|
|
17
|
+
return [s, o];
|
|
18
|
+
} catch (e) {
|
|
19
|
+
throw Error(e.message);
|
|
20
|
+
}
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { r as findCountryMask };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/utilities/removeCurrencySymbols.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return e.replace(/(?:R\$|\p{Sc}|[$€¥£])/gu, "").trim();
|
|
3
4
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
5
|
+
//#endregion
|
|
6
|
+
export { e as removeCurrencySymbols };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/utilities/stripHtmlTags.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
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, "");
|
|
3
4
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
5
|
+
//#endregion
|
|
6
|
+
export { e as stripHtmlTags };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkyn/shared",
|
|
3
|
-
"version": "3.0.1-beta.
|
|
3
|
+
"version": "3.0.1-beta.166",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -27,23 +27,27 @@
|
|
|
27
27
|
},
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"scripts": {
|
|
30
|
-
"
|
|
30
|
+
"audit": "bun audit --workspace packages/shared",
|
|
31
31
|
"build": "bunx vite build && bunx tsc --project tsconfig.json --emitDeclarationOnly && bun ./generate-exports.ts",
|
|
32
|
+
"publish:beta": "bun publish --tag beta",
|
|
33
|
+
"release:beta": "bun ./generate-version.ts beta",
|
|
34
|
+
"release:patch": "bun ./generate-version.ts patch",
|
|
35
|
+
"release:minor": "bun ./generate-version.ts minor",
|
|
36
|
+
"release:major": "bun ./generate-version.ts major",
|
|
37
|
+
"test": "bunx vitest --config vitest.config.ts --run",
|
|
38
|
+
"test:watch": "bunx vitest --config vitest.config.ts --watch",
|
|
32
39
|
"typecheck": "bunx tsc --project tsconfig.json --noEmit"
|
|
33
40
|
},
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"libphonenumber-js": "^1.12.41",
|
|
36
|
-
"uuid": "^10.0.0"
|
|
37
|
-
},
|
|
41
|
+
"dependencies": {},
|
|
38
42
|
"peerDependencies": {
|
|
39
|
-
"
|
|
43
|
+
"libphonenumber-js": ">=1.13.7"
|
|
40
44
|
},
|
|
41
45
|
"devDependencies": {
|
|
42
|
-
"@types/
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
46
|
+
"@types/bun": "^1.3.14",
|
|
47
|
+
"@types/node": "^26.0.1",
|
|
48
|
+
"libphonenumber-js": "^1.13.7",
|
|
49
|
+
"vite": "^8.1.0",
|
|
50
|
+
"vitest": "^4.1.9"
|
|
47
51
|
},
|
|
48
52
|
"exports": {
|
|
49
53
|
".": {
|