@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.
- package/dist/ascii/index.js +24 -39
- package/dist/base64/index.js +90 -118
- package/dist/convertcase/index.js +29 -44
- package/dist/index.js +14 -141
- package/dist/markdown/index.js +29 -31
- package/dist/pluralizer/index.js +30 -93
- package/dist/random/index.js +30 -42
- package/dist/replacer/index.js +39 -60
- package/dist/str.js +692 -1006
- package/dist/stringable/index.js +462 -1329
- package/dist/transliterate/index.js +5 -6
- package/dist/trimmer/index.js +83 -88
- package/dist/ulid/index.js +42 -52
- package/dist/uuid/index.js +33 -43
- package/package.json +35 -22
package/dist/pluralizer/index.js
CHANGED
|
@@ -1,104 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
57
|
-
|
|
10
|
+
function s(e, t = 2) {
|
|
11
|
+
return o(e, t);
|
|
58
12
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
61
|
-
|
|
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
|
|
64
|
-
|
|
17
|
+
function l(e, t) {
|
|
18
|
+
return c(e, t, !0);
|
|
65
19
|
}
|
|
66
|
-
function
|
|
67
|
-
|
|
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
|
|
73
|
-
|
|
74
|
-
return s(n, e);
|
|
23
|
+
function d(e) {
|
|
24
|
+
return h(g().singular(e), e);
|
|
75
25
|
}
|
|
76
|
-
function
|
|
77
|
-
|
|
26
|
+
function f(e) {
|
|
27
|
+
return a.uncountable.includes(e.toLowerCase());
|
|
78
28
|
}
|
|
79
|
-
function
|
|
80
|
-
|
|
29
|
+
function p(e = "") {
|
|
30
|
+
return g().isPlural(e);
|
|
81
31
|
}
|
|
82
|
-
function
|
|
83
|
-
|
|
32
|
+
function m(e = "") {
|
|
33
|
+
return g().isSingular(e);
|
|
84
34
|
}
|
|
85
|
-
function
|
|
86
|
-
|
|
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
|
|
89
|
-
|
|
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 };
|
package/dist/random/index.js
CHANGED
|
@@ -1,45 +1,33 @@
|
|
|
1
|
-
import { bytesToBase64 as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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 };
|
package/dist/replacer/index.js
CHANGED
|
@@ -1,66 +1,45 @@
|
|
|
1
|
-
import { isArray as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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 };
|