@tolki/str 1.7.0 → 1.7.1

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.
@@ -1,104 +1,41 @@
1
- import { format as l } from "@tolki/num";
2
- import { isUndefined as f, isNumber as c } from "@tolki/utils";
3
- import p from "pluralize";
4
- let i;
5
- const u = {
6
- uncountable: [
7
- "audio",
8
- "bison",
9
- "cattle",
10
- "chassis",
11
- "compensation",
12
- "coreopsis",
13
- "data",
14
- "deer",
15
- "education",
16
- "emoji",
17
- "equipment",
18
- "evidence",
19
- "feedback",
20
- "firmware",
21
- "fish",
22
- "furniture",
23
- "gold",
24
- "hardware",
25
- "information",
26
- "jedi",
27
- "kin",
28
- "knowledge",
29
- "love",
30
- "metadata",
31
- "money",
32
- "moose",
33
- "news",
34
- "nutrition",
35
- "offspring",
36
- "plankton",
37
- "pokemon",
38
- "police",
39
- "rain",
40
- "recommended",
41
- "related",
42
- "rice",
43
- "series",
44
- "sheep",
45
- "software",
46
- "species",
47
- "swine",
48
- "traffic",
49
- "wheat"
50
- ]
51
- };
52
- function d(e, n = 2) {
53
- const t = e.split(/(?=[A-Z])/), r = String(t.pop());
54
- return t.join("") + a(r, n);
1
+ import { isNumber as e, isUndefined as t } from "@tolki/utils";
2
+ import { format as n } from "@tolki/num";
3
+ import r from "pluralize";
4
+ // src/pluralizer/index.ts
5
+ var i, a = { uncountable: /* @__PURE__ */ "audio.bison.cattle.chassis.compensation.coreopsis.data.deer.education.emoji.equipment.evidence.feedback.firmware.fish.furniture.gold.hardware.information.jedi.kin.knowledge.love.metadata.money.moose.news.nutrition.offspring.plankton.pokemon.police.rain.recommended.related.rice.series.sheep.software.species.swine.traffic.wheat".split(".") };
6
+ function o(e, t = 2) {
7
+ let n = e.split(/(?=[A-Z])/), r = String(n.pop());
8
+ return n.join("") + c(r, t);
55
9
  }
56
- function C(e, n = 2) {
57
- return d(e, n);
10
+ function s(e, t = 2) {
11
+ return o(e, t);
58
12
  }
59
- function a(e, n = 2, t = !1) {
60
- const r = c(n) ? n : n.length;
61
- return (t ? l(r) + " " : "") + m(e, r);
13
+ function c(t, r = 2, i = !1) {
14
+ let a = e(r) ? r : r.length;
15
+ return (i ? n(a) + " " : "") + u(t, a);
62
16
  }
63
- function U(e, n) {
64
- return a(e, n, !0);
17
+ function l(e, t) {
18
+ return c(e, t, !0);
65
19
  }
66
- function m(e, n) {
67
- if (Math.abs(n) === 1 || g(e))
68
- return e;
69
- const t = o().plural(e);
70
- return s(t, e);
20
+ function u(e, t) {
21
+ return Math.abs(t) === 1 || f(e) ? e : h(g().plural(e), e);
71
22
  }
72
- function k(e) {
73
- const n = o().singular(e);
74
- return s(n, e);
23
+ function d(e) {
24
+ return h(g().singular(e), e);
75
25
  }
76
- function g(e) {
77
- return u.uncountable.includes(e.toLowerCase());
26
+ function f(e) {
27
+ return a.uncountable.includes(e.toLowerCase());
78
28
  }
79
- function S(e = "") {
80
- return o().isPlural(e);
29
+ function p(e = "") {
30
+ return g().isPlural(e);
81
31
  }
82
- function j(e = "") {
83
- return o().isSingular(e);
32
+ function m(e = "") {
33
+ return g().isSingular(e);
84
34
  }
85
- function s(e, n) {
86
- return n.toLowerCase() === n ? e.toLowerCase() : n.toUpperCase() === n ? e.toUpperCase() : n[0] && n[0].toUpperCase() + n.slice(1) === n ? (e[0] ?? "").toUpperCase() + e.slice(1) : e;
35
+ function h(e, t) {
36
+ return t.toLowerCase() === t ? e.toLowerCase() : t.toUpperCase() === t ? e.toUpperCase() : t[0] && t[0].toUpperCase() + t.slice(1) === t ? (e[0] ?? "").toUpperCase() + e.slice(1) : e;
87
37
  }
88
- function o() {
89
- return f(i) && (i = p, u.uncountable.forEach(
90
- (e) => i.addUncountableRule(e)
91
- )), i;
38
+ function g() {
39
+ return t(i) && (i = r, a.uncountable.forEach((e) => i.addUncountableRule(e))), i;
92
40
  }
93
- export {
94
- U as counted,
95
- o as inflector,
96
- S as isPlural,
97
- j as isSingular,
98
- s as matchCase,
99
- a as plural,
100
- C as pluralPascal,
101
- d as pluralStudly,
102
- k as singular,
103
- g as uncountable
104
- };
41
+ export { l as counted, g as inflector, p as isPlural, m as isSingular, h as matchCase, c as plural, s as pluralPascal, o as pluralStudly, d as singular, f as uncountable };
@@ -1,45 +1,33 @@
1
- import { bytesToBase64 as c } from "../base64/index.js";
2
- function f(e = 16) {
3
- if (!Number.isFinite(e) || e <= 0)
4
- return "";
5
- let t = "";
6
- for (; t.length < e; ) {
7
- const o = e - t.length, r = Math.ceil(o / 3) * 3, i = u(r), a = c(i).replace(/[/+=]/g, "");
8
- t += a.slice(0, o);
9
- }
10
- return t;
1
+ import { bytesToBase64 as e } from "../base64/index.js";
2
+ // src/random/index.ts
3
+ function t(t = 16) {
4
+ if (!Number.isFinite(t) || t <= 0) return "";
5
+ let n = "";
6
+ for (; n.length < t;) {
7
+ let i = t - n.length, a = r(Math.ceil(i / 3) * 3), o = e(a).replace(/[/+=]/g, "");
8
+ n += o.slice(0, i);
9
+ }
10
+ return n;
11
11
  }
12
- function l(e, t) {
13
- if (!Number.isInteger(e) || !Number.isInteger(t))
14
- throw new TypeError("randomInt bounds must be safe integers");
15
- if (e > t)
16
- throw new RangeError("randomInt min must be <= max");
17
- if (e === t)
18
- return e;
19
- if (Math.abs(e) > Number.MAX_SAFE_INTEGER || Math.abs(t) > Number.MAX_SAFE_INTEGER)
20
- throw new RangeError("Bounds exceed MAX_SAFE_INTEGER");
21
- const o = t - e, r = Math.floor(Math.log2(o)) + 1, i = Math.ceil(r / 8);
22
- for (; ; ) {
23
- const a = u(i);
24
- let n = 0;
25
- for (let s = 0; s < i; s++)
26
- n = n << 8 | a[s];
27
- if (r % 8 !== 0) {
28
- const s = 8 - r % 8;
29
- n = n >> s & (1 << r) - 1;
30
- }
31
- if (n <= o)
32
- return e + n;
33
- }
12
+ function n(e, t) {
13
+ if (!Number.isInteger(e) || !Number.isInteger(t)) throw TypeError("randomInt bounds must be safe integers");
14
+ if (e > t) throw RangeError("randomInt min must be <= max");
15
+ if (e === t) return e;
16
+ if (Math.abs(e) > 2 ** 53 - 1 || Math.abs(t) > 2 ** 53 - 1) throw RangeError("Bounds exceed MAX_SAFE_INTEGER");
17
+ let n = t - e, i = Math.floor(Math.log2(n)) + 1, a = Math.ceil(i / 8);
18
+ for (;;) {
19
+ let t = r(a), o = 0;
20
+ for (let e = 0; e < a; e++) o = o << 8 | t[e];
21
+ if (i % 8 != 0) {
22
+ let e = 8 - i % 8;
23
+ o = o >> e & (1 << i) - 1;
24
+ }
25
+ if (o <= n) return e + o;
26
+ }
34
27
  }
35
- function u(e) {
36
- if (e <= 0)
37
- return new Uint8Array();
38
- if (typeof globalThis.crypto?.getRandomValues == "function")
39
- return globalThis.crypto.getRandomValues(new Uint8Array(e));
40
- throw new Error("Secure randomness not available in this environment");
28
+ function r(e) {
29
+ if (e <= 0) return /* @__PURE__ */ new Uint8Array();
30
+ if (typeof globalThis.crypto?.getRandomValues == "function") return globalThis.crypto.getRandomValues(new Uint8Array(e));
31
+ throw Error("Secure randomness not available in this environment");
41
32
  }
42
- export {
43
- l as randomInt,
44
- f as randomString
45
- };
33
+ export { n as randomInt, t as randomString };
@@ -1,66 +1,45 @@
1
- import { isArray as a, isObject as j, isString as h } from "@tolki/utils";
2
- function d(e, s, r = null) {
3
- const t = Array.from(e), n = t.length, { start: c, end: u } = m(n, s, r);
4
- return c >= n || u <= c ? "" : t.slice(c, u).join("");
1
+ import { isArray as e, isObject as t, isString as n } from "@tolki/utils";
2
+ // src/replacer/index.ts
3
+ function r(e, t, n = null) {
4
+ let r = Array.from(e), i = r.length, { start: a, end: o } = s(i, t, n);
5
+ return a >= i || o <= a ? "" : r.slice(a, o).join("");
5
6
  }
6
- function y(e, s, r = 0, t = null) {
7
- if (s === "")
8
- return 0;
9
- const n = Array.from(e), c = n.length, { start: u, end: o } = m(c, r, t);
10
- if (u >= c || o <= u)
11
- return 0;
12
- const i = n.slice(u, o).join("");
13
- return p(i, s);
7
+ function i(e, t, n = 0, r = null) {
8
+ if (t === "") return 0;
9
+ let i = Array.from(e), a = i.length, { start: o, end: l } = s(a, n, r);
10
+ return o >= a || l <= o ? 0 : c(i.slice(o, l).join(""), t);
14
11
  }
15
- function S(e, s, r = 0, t = null) {
16
- const n = a(s) ? s : j(s) ? Object.values(s) : null;
17
- if (h(e)) {
18
- if (a(r) || a(t))
19
- throw new TypeError(
20
- "substrReplace(): offset and length must be numbers when the subject is a string"
21
- );
22
- const i = String(n === null ? s : n[0] ?? "");
23
- return f(e, i, r, t);
24
- }
25
- const c = a(r) ? r : null, u = a(t) ? t : null, o = (i, l) => f(
26
- i,
27
- String(n === null ? s : n[l] ?? ""),
28
- c === null ? r : c[l] ?? 0,
29
- u === null ? t : u[l] ?? null
30
- );
31
- return a(e) ? e.map((i, l) => o(i, l)) : Object.fromEntries(
32
- Object.entries(e).map(([i, l], b) => [
33
- i,
34
- o(l, b)
35
- ])
36
- );
12
+ function a(r, i, a = 0, s = null) {
13
+ let c = e(i) ? i : t(i) ? Object.values(i) : null;
14
+ if (n(r)) {
15
+ if (e(a) || e(s)) throw TypeError("substrReplace(): offset and length must be numbers when the subject is a string");
16
+ return o(r, String(c === null ? i : c[0] ?? ""), a, s);
17
+ }
18
+ let l = e(a) ? a : null, u = e(s) ? s : null, d = (e, t) => o(e, String(c === null ? i : c[t] ?? ""), l === null ? a : l[t] ?? 0, u === null ? s : u[t] ?? null);
19
+ return e(r) ? r.map((e, t) => d(e, t)) : Object.fromEntries(Object.entries(r).map(([e, t], n) => [e, d(t, n)]));
37
20
  }
38
- function f(e, s, r, t) {
39
- const n = Array.from(e), c = n.length;
40
- let u = r >= 0 ? r : c + r;
41
- u < 0 && (u = 0), u > c && (u = c);
42
- const o = n.slice(0, u).join(""), i = n.slice(u);
43
- let l;
44
- return t === null ? l = "" : l = i.slice(t).join(""), o + s + l;
21
+ function o(e, t, n, r) {
22
+ let i = Array.from(e), a = i.length, o = n >= 0 ? n : a + n;
23
+ o < 0 && (o = 0), o > a && (o = a);
24
+ let s = i.slice(0, o).join(""), c = i.slice(o), l;
25
+ return l = r === null ? "" : c.slice(r).join(""), s + t + l;
45
26
  }
46
- function m(e, s, r) {
47
- let t = s >= 0 ? s : e + s;
48
- t < 0 && (t = 0), t > e && (t = e);
49
- let n;
50
- return r == null ? n = e : r < 0 ? n = e + r : n = t + r, n = Math.max(0, Math.min(n, e)), { start: t, end: n };
27
+ function s(e, t, n) {
28
+ let r = t >= 0 ? t : e + t;
29
+ r < 0 && (r = 0), r > e && (r = e);
30
+ let i;
31
+ return i = n == null ? e : n < 0 ? e + n : r + n, i = Math.max(0, Math.min(i, e)), {
32
+ start: r,
33
+ end: i
34
+ };
51
35
  }
52
- function p(e, s) {
53
- let r = 0, t = 0;
54
- for (; ; ) {
55
- const n = e.indexOf(s, t);
56
- if (n === -1)
57
- break;
58
- r++, t = n + s.length;
59
- }
60
- return r;
36
+ function c(e, t) {
37
+ let n = 0, r = 0;
38
+ for (;;) {
39
+ let i = e.indexOf(t, r);
40
+ if (i === -1) break;
41
+ n++, r = i + t.length;
42
+ }
43
+ return n;
61
44
  }
62
- export {
63
- d as substr,
64
- y as substrCount,
65
- S as substrReplace
66
- };
45
+ export { r as substr, i as substrCount, a as substrReplace };