@tolki/utils 1.6.1 → 1.6.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/dist/cast.js +99 -130
- package/dist/equality.js +156 -211
- package/dist/exceptions.js +22 -53
- package/dist/guards.js +104 -151
- package/dist/index.js +11 -102
- package/dist/keys.js +97 -130
- package/dist/range.js +61 -98
- package/dist/reflect.js +15 -20
- package/dist/sorting.js +24 -28
- package/dist/string.d.ts +19 -0
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +26 -20
- package/dist/utils.js +10 -102
- package/package.json +4 -3
package/dist/keys.js
CHANGED
|
@@ -1,138 +1,105 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { phpDebugType as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function B(e) {
|
|
8
|
-
return e === "__proto__" || e === "constructor" || e === "prototype";
|
|
9
|
-
}
|
|
10
|
-
function C(e) {
|
|
11
|
-
return p(e) ? !0 : y(e) ? e >= -c && e < c : !1;
|
|
1
|
+
import { isArray as e, isBoolean as t, isEnumCase as n, isFunction as r, isInteger as i, isMap as a, isNull as o, isNumber as s, isObject as c, isPrototypeObject as l, isString as u, isSymbol as d, isTruthyObject as f, isUndefined as p } from "./guards.js";
|
|
2
|
+
import { phpDebugType as m } from "./reflect.js";
|
|
3
|
+
// src/keys.ts
|
|
4
|
+
var h = 2 ** 63;
|
|
5
|
+
function g(e) {
|
|
6
|
+
return !isNaN(Number(e)) && !isNaN(parseFloat(String(e))) ? Number(e) : e;
|
|
12
7
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
8
|
+
function _(e) {
|
|
9
|
+
return e === "__proto__" || e === "constructor" || e === "prototype";
|
|
10
|
+
}
|
|
11
|
+
function v(e) {
|
|
12
|
+
return u(e) ? !0 : i(e) ? e >= -h && e < h : !1;
|
|
13
|
+
}
|
|
14
|
+
function y(e) {
|
|
15
|
+
return /^(0|[1-9]\d*)$/.test(e);
|
|
16
|
+
}
|
|
17
|
+
function b(e) {
|
|
18
|
+
if (u(e)) {
|
|
19
|
+
if (/^(0|-?[1-9]\d*)$/.test(e)) {
|
|
20
|
+
let t = Number(e);
|
|
21
|
+
if (Number.isSafeInteger(t)) return t;
|
|
22
|
+
}
|
|
23
|
+
return e;
|
|
24
|
+
}
|
|
25
|
+
if (o(e) || p(e)) return "";
|
|
26
|
+
if (t(e)) return +!!e;
|
|
27
|
+
if (s(e) || Number.isNaN(e)) {
|
|
28
|
+
let t = Number.isFinite(e) ? BigInt.asIntN(64, BigInt(Math.trunc(e))) : 0n;
|
|
29
|
+
return Number.isSafeInteger(Number(t)) ? Number(t) : String(t);
|
|
30
|
+
}
|
|
31
|
+
return String(e);
|
|
32
|
+
}
|
|
33
|
+
function x(e, t = {}) {
|
|
34
|
+
let { enumCases: r = !1, stringables: i = !1 } = t, a = e;
|
|
35
|
+
if (r && n(a) && (a = a.value), i && w(a) && (a = String(a.toString())), S(a)) throw (t.invalid ?? T)(m(a));
|
|
36
|
+
return b(a);
|
|
37
|
+
}
|
|
38
|
+
function S(t) {
|
|
39
|
+
return e(t) || c(t) || r(t);
|
|
40
|
+
}
|
|
41
|
+
function C() {
|
|
42
|
+
return /* @__PURE__ */ TypeError("array_key_exists(): Argument #1 ($key) must be a valid array offset type");
|
|
41
43
|
}
|
|
42
44
|
function w(e) {
|
|
43
|
-
|
|
45
|
+
return c(e) && !(e instanceof Date) && r(e.toString) && e.toString !== Object.prototype.toString;
|
|
46
|
+
}
|
|
47
|
+
function T(e) {
|
|
48
|
+
return /* @__PURE__ */ TypeError(`Cannot access offset of type ${e} on array`);
|
|
49
|
+
}
|
|
50
|
+
function E(e) {
|
|
51
|
+
if (!a(e)) return Object.entries(e);
|
|
52
|
+
let t = /* @__PURE__ */ new Map();
|
|
53
|
+
for (let [n, r] of e) {
|
|
54
|
+
let e = M(n) ? String(b(n)) : void 0;
|
|
55
|
+
t.set(e ?? n, [e ?? String(n), r]);
|
|
56
|
+
}
|
|
57
|
+
return [...t.values()];
|
|
58
|
+
}
|
|
59
|
+
function D(e, t) {
|
|
60
|
+
let n = { found: !1 };
|
|
61
|
+
for (let [r, i] of e) j(r, t) && (n = {
|
|
62
|
+
found: !0,
|
|
63
|
+
value: i
|
|
64
|
+
});
|
|
65
|
+
return n;
|
|
66
|
+
}
|
|
67
|
+
function O(e, t, n) {
|
|
68
|
+
let r = !1;
|
|
69
|
+
for (let i of [...e.keys()]) j(i, t) && (r ? e.delete(i) : (e.set(i, n), r = !0));
|
|
70
|
+
r || e.set(b(t), n);
|
|
71
|
+
}
|
|
72
|
+
function k(e, t) {
|
|
73
|
+
for (let n of [...e.keys()]) j(n, t) && e.delete(n);
|
|
44
74
|
}
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
75
|
+
function A(e) {
|
|
76
|
+
let t;
|
|
77
|
+
for (let [n] of E(e)) {
|
|
78
|
+
let e = b(n);
|
|
79
|
+
s(e) && (t === void 0 || e > t) && (t = e);
|
|
80
|
+
}
|
|
81
|
+
return t === void 0 ? 0 : t + 1;
|
|
49
82
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
83
|
+
function j(e, t) {
|
|
84
|
+
return M(e) && String(b(e)) === String(b(t));
|
|
52
85
|
}
|
|
53
|
-
function
|
|
54
|
-
|
|
86
|
+
function M(e) {
|
|
87
|
+
return !f(e) && !r(e) && !d(e);
|
|
55
88
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const t = /* @__PURE__ */ new Map();
|
|
60
|
-
for (const [r, n] of e) {
|
|
61
|
-
const i = g(r) ? String(o(r)) : void 0;
|
|
62
|
-
t.set(i ?? r, [i ?? String(r), n]);
|
|
63
|
-
}
|
|
64
|
-
return [...t.values()];
|
|
65
|
-
}
|
|
66
|
-
function F(e, t) {
|
|
67
|
-
let r = { found: !1 };
|
|
68
|
-
for (const [n, i] of e)
|
|
69
|
-
u(n, t) && (r = { found: !0, value: i });
|
|
70
|
-
return r;
|
|
71
|
-
}
|
|
72
|
-
function U(e, t, r) {
|
|
73
|
-
let n = !1;
|
|
74
|
-
for (const i of [...e.keys()])
|
|
75
|
-
u(i, t) && (n ? e.delete(i) : (e.set(i, r), n = !0));
|
|
76
|
-
n || e.set(o(t), r);
|
|
77
|
-
}
|
|
78
|
-
function H(e, t) {
|
|
79
|
-
for (const r of [...e.keys()])
|
|
80
|
-
u(r, t) && e.delete(r);
|
|
81
|
-
}
|
|
82
|
-
function L(e) {
|
|
83
|
-
let t;
|
|
84
|
-
for (const [r] of _(e)) {
|
|
85
|
-
const n = o(r);
|
|
86
|
-
f(n) && (t === void 0 || n > t) && (t = n);
|
|
87
|
-
}
|
|
88
|
-
return t === void 0 ? 0 : t + 1;
|
|
89
|
-
}
|
|
90
|
-
function u(e, t) {
|
|
91
|
-
return g(e) && String(o(e)) === String(o(t));
|
|
89
|
+
function N(e) {
|
|
90
|
+
let t = 0;
|
|
91
|
+
return e.map(([e, n]) => y(e) ? [String(t++), n] : [e, n]);
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
function z(e, t, r) {
|
|
107
|
-
if (!b(e)) {
|
|
108
|
-
if (Object.getOwnPropertyDescriptor(e, t)?.configurable === !1) {
|
|
109
|
-
Object.defineProperty(e, t, { value: r });
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
Object.defineProperty(e, t, {
|
|
113
|
-
value: r,
|
|
114
|
-
enumerable: !0,
|
|
115
|
-
writable: !0,
|
|
116
|
-
configurable: !0
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
export {
|
|
121
|
-
$ as arrayKeyExistsError,
|
|
122
|
-
z as defineKey,
|
|
123
|
-
H as deleteMapKey,
|
|
124
|
-
A as entriesKeyValue,
|
|
125
|
-
x as hasOwnToString,
|
|
126
|
-
w as isIllegalOffset,
|
|
127
|
-
P as isIntegerLikeKey,
|
|
128
|
-
C as isPhpArrayKey,
|
|
129
|
-
B as isUnsafeKey,
|
|
130
|
-
_ as keyedEntries,
|
|
131
|
-
L as nextIntegerKey,
|
|
132
|
-
o as phpArrayKey,
|
|
133
|
-
D as phpComputedKey,
|
|
134
|
-
F as readMapKey,
|
|
135
|
-
V as reindexIntegerKeys,
|
|
136
|
-
q as renumberPhpIntegerKeys,
|
|
137
|
-
U as writeMapKey
|
|
138
|
-
};
|
|
93
|
+
function P(e) {
|
|
94
|
+
let t = 0;
|
|
95
|
+
return e.map(([e, n]) => s(b(e)) ? [String(t++), n] : [e, n]);
|
|
96
|
+
}
|
|
97
|
+
function F(e, t, n) {
|
|
98
|
+
l(e) || (Object.getOwnPropertyDescriptor(e, t)?.configurable === !1 ? Object.defineProperty(e, t, { value: n }) : Object.defineProperty(e, t, {
|
|
99
|
+
value: n,
|
|
100
|
+
enumerable: !0,
|
|
101
|
+
writable: !0,
|
|
102
|
+
configurable: !0
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
export { C as arrayKeyExistsError, F as defineKey, k as deleteMapKey, g as entriesKeyValue, w as hasOwnToString, S as isIllegalOffset, y as isIntegerLikeKey, v as isPhpArrayKey, _ as isUnsafeKey, E as keyedEntries, A as nextIntegerKey, b as phpArrayKey, x as phpComputedKey, D as readMapKey, N as reindexIntegerKeys, P as renumberPhpIntegerKeys, O as writeMapKey };
|
package/dist/range.js
CHANGED
|
@@ -1,106 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { isFiniteNumber as e, isInteger as t, isNull as n, isPhpInt as r, isUndefined as i } from "./guards.js";
|
|
2
|
+
import { phpIntArgument as a } from "./cast.js";
|
|
3
|
+
// src/range.ts
|
|
4
|
+
var o = 2 ** 30;
|
|
5
|
+
function s(e, t, r) {
|
|
6
|
+
let i = t < 0 ? Math.max(e + t, 0) : t;
|
|
7
|
+
return {
|
|
8
|
+
start: i,
|
|
9
|
+
end: n(r) ? void 0 : r >= 0 ? i + r : Math.max(i, e + r)
|
|
10
|
+
};
|
|
7
11
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
start: a,
|
|
21
|
-
count: i < 0 ? Math.max(e + i - a, 0) : i
|
|
22
|
-
};
|
|
12
|
+
function c(e, t, r) {
|
|
13
|
+
let o = a(t, "array_splice(): Argument #2 ($offset) must be of type int, float given"), s = o < 0 ? Math.max(e + o, 0) : Math.min(o, e);
|
|
14
|
+
if (n(r) || i(r)) return {
|
|
15
|
+
start: s,
|
|
16
|
+
count: e - s
|
|
17
|
+
};
|
|
18
|
+
let c = a(r, "array_splice(): Argument #3 ($length) must be of type ?int, float given");
|
|
19
|
+
return {
|
|
20
|
+
start: s,
|
|
21
|
+
count: c < 0 ? Math.max(e + c - s, 0) : c
|
|
22
|
+
};
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"range(): Argument #3 ($step) must be less than the range spanned by argument #1 ($start) and argument #2 ($end)"
|
|
29
|
-
);
|
|
30
|
-
return Math.floor(t);
|
|
24
|
+
function l(e, n) {
|
|
25
|
+
let r = Number.isNaN(e) ? n : Math.min(e, n);
|
|
26
|
+
if (!t(r) && r < 2) throw Error("range(): Argument #3 ($step) must be less than the range spanned by argument #1 ($start) and argument #2 ($end)");
|
|
27
|
+
return Math.floor(r);
|
|
31
28
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
);
|
|
37
|
-
if (Math.abs(n) > s)
|
|
38
|
-
throw new Error(
|
|
39
|
-
"array_pad(): Argument #2 ($length) must not exceed the maximum allowed array size"
|
|
40
|
-
);
|
|
41
|
-
return n;
|
|
29
|
+
function u(e) {
|
|
30
|
+
let t = a(e, "array_pad(): Argument #2 ($length) must be of type int, float given");
|
|
31
|
+
if (Math.abs(t) > o) throw Error("array_pad(): Argument #2 ($length) must not exceed the maximum allowed array size");
|
|
32
|
+
return t;
|
|
42
33
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"range(): Argument #3 ($step) must be less than the range spanned by argument #1 ($start) and argument #2 ($end)"
|
|
60
|
-
);
|
|
61
|
-
const i = a / r + 1, o = ![e, n, t].every(($) => d($));
|
|
62
|
-
if (i >= s)
|
|
63
|
-
throw b(
|
|
64
|
-
Math.min(e, n),
|
|
65
|
-
Math.max(e, n),
|
|
66
|
-
r,
|
|
67
|
-
o
|
|
68
|
-
);
|
|
69
|
-
const c = Math.floor(i);
|
|
70
|
-
return o && i - c >= 0.5 ? c + 1 : c;
|
|
34
|
+
function d(t, n, i) {
|
|
35
|
+
if (!e(i)) throw f("#3 ($step)", i);
|
|
36
|
+
if (i === 0) throw Error("range(): Argument #3 ($step) cannot be 0");
|
|
37
|
+
if (!e(t)) throw f("#1 ($start)", t);
|
|
38
|
+
if (!e(n)) throw f("#2 ($end)", n);
|
|
39
|
+
if (n > t && i < 0) throw Error("range(): Argument #3 ($step) must be greater than 0 for increasing ranges");
|
|
40
|
+
let a = Math.abs(i), s = Math.abs(n - t);
|
|
41
|
+
if (s !== 0 && s < a) throw Error("range(): Argument #3 ($step) must be less than the range spanned by argument #1 ($start) and argument #2 ($end)");
|
|
42
|
+
let c = s / a + 1, l = ![
|
|
43
|
+
t,
|
|
44
|
+
n,
|
|
45
|
+
i
|
|
46
|
+
].every((e) => r(e));
|
|
47
|
+
if (c >= o) throw p(Math.min(t, n), Math.max(t, n), a, l);
|
|
48
|
+
let u = Math.floor(c);
|
|
49
|
+
return l && c - u >= .5 ? u + 1 : u;
|
|
71
50
|
}
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
return new Error(
|
|
75
|
-
`range(): Argument ${e} must be a finite number, ${t} provided`
|
|
76
|
-
);
|
|
51
|
+
function f(e, t) {
|
|
52
|
+
return /* @__PURE__ */ Error(`range(): Argument ${e} must be a finite number, ${Number.isNaN(t) ? "NAN" : "INF"} provided`);
|
|
77
53
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const a = (BigInt(n) - BigInt(e)) / BigInt(t);
|
|
86
|
-
return new Error(
|
|
87
|
-
`The supplied range exceeds the maximum array size by ${a + 1n - BigInt(s)} elements: start=${e}, end=${n}, step=${t}. Calculated size: ${a}. Maximum size: ${s}.`
|
|
88
|
-
);
|
|
54
|
+
function p(e, t, n, r) {
|
|
55
|
+
if (r) {
|
|
56
|
+
let r = (t - e) / n + 1;
|
|
57
|
+
return /* @__PURE__ */ Error(`The supplied range exceeds the maximum array size by ${m(r - o)} elements: start=${m(e)}, end=${m(t)}, step=${m(n)}. Max size: ${o}`);
|
|
58
|
+
}
|
|
59
|
+
let i = (BigInt(t) - BigInt(e)) / BigInt(n);
|
|
60
|
+
return /* @__PURE__ */ Error(`The supplied range exceeds the maximum array size by ${i + 1n - BigInt(o)} elements: start=${e}, end=${t}, step=${n}. Calculated size: ${i}. Maximum size: ${o}.`);
|
|
89
61
|
}
|
|
90
|
-
function m(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const r = 2n ** BigInt(t), a = BigInt(n) * 10n, i = a % r * 2n;
|
|
97
|
-
let o = a / r;
|
|
98
|
-
return (i > r || i === r && o % 2n === 1n) && (o += 1n), `${e < 0 ? "-" : ""}${o / 10n}.${o % 10n}`;
|
|
62
|
+
function m(t) {
|
|
63
|
+
if (!e(t)) return "inf";
|
|
64
|
+
let n = Math.abs(t), r = 0;
|
|
65
|
+
for (; !Number.isInteger(n);) n *= 2, r++;
|
|
66
|
+
let i = 2n ** BigInt(r), a = BigInt(n) * 10n, o = a % i * 2n, s = a / i;
|
|
67
|
+
return (o > i || o === i && s % 2n == 1n) && (s += 1n), `${t < 0 ? "-" : ""}${s / 10n}.${s % 10n}`;
|
|
99
68
|
}
|
|
100
|
-
export {
|
|
101
|
-
v as resolvePadLength,
|
|
102
|
-
I as resolveRangeSize,
|
|
103
|
-
x as resolveSliceRange,
|
|
104
|
-
y as resolveSpliceRange,
|
|
105
|
-
A as resolveTakeCount
|
|
106
|
-
};
|
|
69
|
+
export { u as resolvePadLength, d as resolveRangeSize, s as resolveSliceRange, c as resolveSpliceRange, l as resolveTakeCount };
|
package/dist/reflect.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { isArray as e, isBoolean as t, isFunction as n, isInteger as r, isNull as i, isNumber as a, isObject as o, isPhpInt as s, isPlainObject as c, isString as l, isUndefined as u } from "./guards.js";
|
|
2
|
+
// src/reflect.ts
|
|
3
|
+
function d(t) {
|
|
4
|
+
return i(t) ? "object" : e(t) ? "array" : typeof t;
|
|
4
5
|
}
|
|
5
|
-
function
|
|
6
|
-
|
|
6
|
+
function f(e) {
|
|
7
|
+
return e === void 0 ? null : typeof e == "function" ? e() : e;
|
|
7
8
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
9
|
+
function p(t) {
|
|
10
|
+
return i(t) ? "NULL" : a(t) ? r(t) ? "integer" : "double" : e(t) ? "array" : Number.isNaN(t) ? "double" : n(t) ? "object" : u(t) ? "NULL" : typeof t;
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
12
|
+
function m(r) {
|
|
13
|
+
return i(r) || u(r) ? "null" : d(r) === "number" ? s(r) ? "int" : "float" : l(r) ? "string" : t(r) ? "bool" : e(r) || c(r) ? "array" : n(r) ? "Closure" : o(r) && n(r.constructor) ? h(r.constructor) : d(r);
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return `${n(t) && t.name ? t.name : "class"}@anonymous`;
|
|
15
|
+
function h(e) {
|
|
16
|
+
if (e.name) return e.name;
|
|
17
|
+
let t = Object.getPrototypeOf(e);
|
|
18
|
+
return `${n(t) && t.name ? t.name : "class"}@anonymous`;
|
|
19
19
|
}
|
|
20
|
-
export {
|
|
21
|
-
L as phpDebugType,
|
|
22
|
-
O as phpTypeName,
|
|
23
|
-
j as resolveDefault,
|
|
24
|
-
o as typeOf
|
|
25
|
-
};
|
|
20
|
+
export { m as phpDebugType, p as phpTypeName, f as resolveDefault, d as typeOf };
|
package/dist/sorting.js
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
1
|
+
import { isArray as e, isBoolean as t, isFunction as n, isNumber as r, isUndefined as i } from "./guards.js";
|
|
2
|
+
import { phpIntCast as a } from "./cast.js";
|
|
3
|
+
import { compareValues as o } from "./equality.js";
|
|
4
|
+
// src/sorting.ts
|
|
5
|
+
function s(t) {
|
|
6
|
+
return function(n, r) {
|
|
7
|
+
if (c(n)) return n;
|
|
8
|
+
if (e(n) && c(n[0])) return n[0];
|
|
9
|
+
let [a, s] = e(n) ? n : [n, void 0], l = i(s) || s === !0 || s === "asc" || s === "Ascending", u = r || !l;
|
|
10
|
+
return (e, n) => {
|
|
11
|
+
let r = o(t(e, a), t(n, a));
|
|
12
|
+
return u ? -r : r;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
16
15
|
}
|
|
17
|
-
function c(
|
|
18
|
-
|
|
16
|
+
function c(e) {
|
|
17
|
+
return n(e);
|
|
19
18
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
function l(e) {
|
|
20
|
+
return (t, n) => {
|
|
21
|
+
let r = e(t, n);
|
|
22
|
+
return r === !1 ? -u(e(n, t)) : u(r);
|
|
23
|
+
};
|
|
25
24
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
25
|
+
function u(e) {
|
|
26
|
+
return t(e) ? +!!e : r(e) ? Math.sign(a(e)) : 0;
|
|
28
27
|
}
|
|
29
|
-
export {
|
|
30
|
-
B as createSortSpecComparator,
|
|
31
|
-
D as phpSortComparator
|
|
32
|
-
};
|
|
28
|
+
export { s as createSortSpecComparator, l as phpSortComparator };
|
package/dist/string.d.ts
CHANGED
|
@@ -24,4 +24,23 @@ export declare function upperFirst(value: string): string;
|
|
|
24
24
|
* @returns The formatted error message.
|
|
25
25
|
*/
|
|
26
26
|
export declare function arrayValueMessage(value: unknown, key: PathKey): string;
|
|
27
|
+
/**
|
|
28
|
+
* Escape a value for safe interpolation into a shell command string.
|
|
29
|
+
*
|
|
30
|
+
* Uses POSIX single-quote wrapping: the only character that requires
|
|
31
|
+
* escaping inside single quotes is the single quote itself.
|
|
32
|
+
*
|
|
33
|
+
* @param value - The raw string to escape.
|
|
34
|
+
* @returns A shell-safe string.
|
|
35
|
+
*/
|
|
36
|
+
export declare function escapeShellArg(value: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Escape a value for safe interpolation into a cmd.exe command string, the shell Node's `exec` runs on Windows.
|
|
39
|
+
*
|
|
40
|
+
* `%` cannot be escaped on a cmd.exe command line, so a `%NAME%` in the value still expands.
|
|
41
|
+
*
|
|
42
|
+
* @param value - The raw string to escape.
|
|
43
|
+
* @returns The value bare when every character is safe, else double-quoted by the MSVCRT argv rules.
|
|
44
|
+
*/
|
|
45
|
+
export declare function escapeWindowsShellArg(value: string): string;
|
|
27
46
|
//# sourceMappingURL=string.d.ts.map
|
package/dist/string.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUhD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUhD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,CAEtE"}
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUhD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUhD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,CAEtE;AAID;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUpD;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CA2B3D"}
|
package/dist/string.js
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
import { phpTypeName as
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { phpTypeName as e } from "./reflect.js";
|
|
2
|
+
// src/string.ts
|
|
3
|
+
function t(e) {
|
|
4
|
+
return e.toLowerCase();
|
|
4
5
|
}
|
|
5
|
-
function
|
|
6
|
-
|
|
6
|
+
function n(e) {
|
|
7
|
+
return e.toUpperCase();
|
|
7
8
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
function r(e) {
|
|
10
|
+
let t = [...e];
|
|
11
|
+
return t.length === 0 ? e : (t[0] = t[0].toLowerCase(), t.join(""));
|
|
11
12
|
}
|
|
12
|
-
function i(
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
function i(e) {
|
|
14
|
+
let t = [...e];
|
|
15
|
+
return t.length === 0 ? e : (t[0] = t[0].toUpperCase(), t.join(""));
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
-
|
|
17
|
+
function a(t, n) {
|
|
18
|
+
return `Array value for key [${String(n)}] must be an array, ${e(t)} found.`;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
var o = /^[\w@%+=:,./-]+$/;
|
|
21
|
+
function s(e) {
|
|
22
|
+
return e === "" ? "''" : o.test(e) ? e : "'" + e.replace(/'/g, "'\\''") + "'";
|
|
23
|
+
}
|
|
24
|
+
function c(e) {
|
|
25
|
+
if (e === "") return "\"\"";
|
|
26
|
+
if (o.test(e)) return e;
|
|
27
|
+
let t = "", n = 0;
|
|
28
|
+
for (let r of e) r === "\\" ? n++ : (t += r === "\"" ? `${"\\".repeat(n * 2 + 1)}"` : `${"\\".repeat(n)}${r}`, n = 0);
|
|
29
|
+
return `"${t}${"\\".repeat(n * 2)}"`;
|
|
30
|
+
}
|
|
31
|
+
export { a as arrayValueMessage, s as escapeShellArg, c as escapeWindowsShellArg, r as lowerFirst, t as toLower, n as toUpper, i as upperFirst };
|