@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.
Files changed (29) hide show
  1. package/dist/generators/generateId.d.ts.map +1 -1
  2. package/dist/index.js +343 -344
  3. package/dist/modules/formats/formatDate.js +33 -40
  4. package/dist/modules/formats/formatJsonObject.js +22 -31
  5. package/dist/modules/formats/formatJsonString.js +10 -12
  6. package/dist/modules/formats/formatToCapitalizeFirstWordLetter.js +5 -8
  7. package/dist/modules/formats/formatToCep.js +8 -8
  8. package/dist/modules/formats/formatToCnpj.js +8 -8
  9. package/dist/modules/formats/formatToCpf.js +8 -8
  10. package/dist/modules/formats/formatToCurrency.js +12 -14
  11. package/dist/modules/formats/formatToEllipsis.js +9 -10
  12. package/dist/modules/formats/formatToHiddenDigits.js +21 -11
  13. package/dist/modules/formats/formatToPhone.js +13 -16
  14. package/dist/modules/generators/generateColorByString.js +7 -8
  15. package/dist/modules/generators/generateId.js +28 -22
  16. package/dist/modules/generators/generateSlug.js +6 -6
  17. package/dist/modules/index.js +26 -52
  18. package/dist/modules/parsers/parseLargeFields.js +16 -21
  19. package/dist/modules/parsers/parseSensitiveData.js +27 -25
  20. package/dist/modules/parsers/parseToDate.js +22 -26
  21. package/dist/modules/services/validateDateService.js +60 -58
  22. package/dist/modules/utilities/calculateCardInstallment.js +16 -20
  23. package/dist/modules/utilities/ensureQuotes.js +6 -6
  24. package/dist/modules/utilities/findCountryMask.js +22 -24
  25. package/dist/modules/utilities/isHtml.js +5 -5
  26. package/dist/modules/utilities/removeCurrencySymbols.js +5 -5
  27. package/dist/modules/utilities/removeNonNumeric.js +5 -5
  28. package/dist/modules/utilities/stripHtmlTags.js +5 -5
  29. package/package.json +16 -12
@@ -1,27 +1,23 @@
1
- import { ValidateDateService as u } from "../services/validateDateService.js";
2
- function b([n, c = "00:00:00"], o, m = 0) {
3
- const r = new u();
4
- r.validateInputFormat(o);
5
- const i = n.split(/[-/]/).map(Number), d = c.split(".")[0].split(":").map(Number);
6
- let t, e, a;
7
- const [l = 0, D = 0, p = 0] = d;
8
- switch (o) {
9
- case "brazilianDate":
10
- [t, e, a] = i, r.validateDateParts(a, e, t);
11
- break;
12
- case "isoDate":
13
- [e, t, a] = i, r.validateDateParts(a, e, t);
14
- break;
15
- case "timestamp":
16
- [a, e, t] = i, r.validateDateParts(a, e, t);
17
- break;
18
- }
19
- const s = new Date(
20
- Date.UTC(a, e - 1, t, l, D, p)
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
- export {
26
- b as parseToDate
27
- };
22
+ //#endregion
23
+ export { t as parseToDate };
@@ -1,59 +1,61 @@
1
- class l {
2
- isLeapYear(e) {
3
- return e % 4 === 0 && e % 100 !== 0 || e % 400 === 0;
4
- }
5
- getDaysInMonth(e, r) {
6
- const a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
7
- return e === 2 && this.isLeapYear(r) ? 29 : a[e - 1];
8
- }
9
- validateDayInMonth(e, r, a) {
10
- const t = this.getDaysInMonth(r, a);
11
- if (e > t) {
12
- const n = `Day ${e} is not valid for ${[
13
- "January",
14
- "February",
15
- "March",
16
- "April",
17
- "May",
18
- "June",
19
- "July",
20
- "August",
21
- "September",
22
- "October",
23
- "November",
24
- "December"
25
- ][r - 1]}`, o = `Day ${e} is not valid for February ${a} (non-leap year)`;
26
- throw r === 2 && e === 29 ? new Error(o) : new Error(n);
27
- }
28
- }
29
- /**
30
- * Throws if year, month, or day are out of valid range or inconsistent with the calendar.
31
- *
32
- * @param year - 4-digit year (1000–9999).
33
- * @param month - Month number (1–12).
34
- * @param day - Day number (1–31, validated against the specific month).
35
- */
36
- validateDateParts(e, r, a) {
37
- const t = {
38
- year: "Year should be four digits",
39
- month: "Month should be between 1 and 12",
40
- day: "Day should be between 1 and 31"
41
- };
42
- if (`${e}`.length !== 4) throw new Error(t.year);
43
- if (r < 1 || r > 12) throw new Error(t.month);
44
- if (a < 1 || a > 31) throw new Error(t.day);
45
- this.validateDayInMonth(a, r, e);
46
- }
47
- /**
48
- * Throws if `format` is not one of `"brazilianDate"`, `"isoDate"`, or `"timestamp"`.
49
- *
50
- * @param format - The format string to check.
51
- */
52
- validateInputFormat(e) {
53
- if (!["brazilianDate", "isoDate", "timestamp"].includes(e))
54
- throw new Error(`Invalid input format: ${e}`);
55
- }
56
- }
57
- export {
58
- l as ValidateDateService
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
- function s(o) {
2
- const { cashPrice: r, numberInstallments: t, fees: e = 0.0349 } = o;
3
- if (e === 0 || t === 1)
4
- return {
5
- totalPrice: r,
6
- installmentPrice: r / t
7
- };
8
- if (t <= 0)
9
- throw new Error("Number of installments must be greater than 0");
10
- if (e < 0)
11
- throw new Error("Fees must be greater than or equal to 0");
12
- let a = Math.pow(1 + e, t) * e, i = Math.pow(1 + e, t) - 1;
13
- const n = +(r * (a / i)).toFixed(2);
14
- return {
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
- export {
20
- s as calculateCardInstallment
21
- };
16
+ //#endregion
17
+ export { e as calculateCardInstallment };
@@ -1,7 +1,7 @@
1
- function o(t) {
2
- const s = t.startsWith("'") && t.endsWith("'"), n = t.startsWith('"') && t.endsWith('"');
3
- return s || n ? t : `"${t}"`;
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
- export {
6
- o as ensureQuotes
7
- };
6
+ //#endregion
7
+ export { e as ensureQuotes };
@@ -1,25 +1,23 @@
1
- import { countries as h } from "@arkyn/templates";
2
- import { parsePhoneNumberWithError as a } from "libphonenumber-js";
3
- import { removeNonNumeric as f } from "./removeNonNumeric.js";
4
- function k(i) {
5
- try {
6
- const r = a(i), n = r == null ? void 0 : r.country;
7
- if (!n) throw new Error("Invalid phone number");
8
- const o = h.find((t) => t.iso === n);
9
- if (!o) throw new Error("Phone number country not supported");
10
- if (typeof o.mask == "string") return [o.mask, o];
11
- const e = o.mask.find((t) => {
12
- const s = t.replace(/[^_]/g, ""), m = f(r.nationalNumber), u = s.length, c = m.length;
13
- return u === c;
14
- });
15
- if (!e)
16
- throw new Error("No mask found for the given phone number length");
17
- return [e, o];
18
- } catch (r) {
19
- const n = r;
20
- throw new Error(n.message);
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
- export {
24
- k as findCountryMask
25
- };
22
+ //#endregion
23
+ export { r as findCountryMask };
@@ -1,6 +1,6 @@
1
- function n(t) {
2
- return /<\/?[a-z][\s\S]*>/i.test(t);
1
+ //#region src/utilities/isHtml.ts
2
+ function e(e) {
3
+ return /<\/?[a-z][\s\S]*>/i.test(e);
3
4
  }
4
- export {
5
- n as isHtml
6
- };
5
+ //#endregion
6
+ export { e as isHtml };
@@ -1,6 +1,6 @@
1
- function e(r) {
2
- return r.replace(new RegExp("(?:R\\$|\\p{Sc}|[$€¥£])", "gu"), "").trim();
1
+ //#region src/utilities/removeCurrencySymbols.ts
2
+ function e(e) {
3
+ return e.replace(/(?:R\$|\p{Sc}|[$€¥£])/gu, "").trim();
3
4
  }
4
- export {
5
- e as removeCurrencySymbols
6
- };
5
+ //#endregion
6
+ export { e as removeCurrencySymbols };
@@ -1,6 +1,6 @@
1
- function r(e) {
2
- return e.replace(/[^0-9]/g, "");
1
+ //#region src/utilities/removeNonNumeric.ts
2
+ function e(e) {
3
+ return e.replace(/[^0-9]/g, "");
3
4
  }
4
- export {
5
- r as removeNonNumeric
6
- };
5
+ //#endregion
6
+ export { e as removeNonNumeric };
@@ -1,6 +1,6 @@
1
- function r(e) {
2
- 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, "");
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
- export {
5
- r as stripHtmlTags
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.160",
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
- "test": "vitest --config vitest.config.ts",
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
- "@arkyn/templates": ">=3.0.1-beta.145"
43
+ "libphonenumber-js": ">=1.13.7"
40
44
  },
41
45
  "devDependencies": {
42
- "@types/uuid": "^10.0.0",
43
- "bun-types": "latest",
44
- "vitest": "^3.2.4",
45
- "typescript": "^5.9.3",
46
- "vite": "^5.4.21"
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
  ".": {