@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/keys.js CHANGED
@@ -1,138 +1,105 @@
1
- import { isPrototypeObject as b, isObject as a, isFunction as s, isArray as l, isString as p, isInteger as y, isMap as d, isNull as m, isUndefined as K, isBoolean as S, isNumber as f, isEnumCase as N, isTruthyObject as h, isSymbol as I } from "./guards.js";
2
- import { phpDebugType as O } from "./reflect.js";
3
- const c = 2 ** 63;
4
- function A(e) {
5
- return !isNaN(Number(e)) && !isNaN(parseFloat(String(e))) ? Number(e) : e;
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 P(e) {
14
- return /^(0|[1-9]\d*)$/.test(e);
15
- }
16
- function o(e) {
17
- if (p(e)) {
18
- if (/^(0|-?[1-9]\d*)$/.test(e)) {
19
- const t = Number(e);
20
- if (Number.isSafeInteger(t))
21
- return t;
22
- }
23
- return e;
24
- }
25
- if (m(e) || K(e))
26
- return "";
27
- if (S(e))
28
- return e ? 1 : 0;
29
- if (f(e) || Number.isNaN(e)) {
30
- const t = Number.isFinite(e) ? BigInt.asIntN(64, BigInt(Math.trunc(e))) : 0n;
31
- return Number.isSafeInteger(Number(t)) ? Number(t) : String(t);
32
- }
33
- return String(e);
34
- }
35
- function D(e, t = {}) {
36
- const { enumCases: r = !1, stringables: n = !1 } = t;
37
- let i = e;
38
- if (r && N(i) && (i = i.value), n && x(i) && (i = String(i.toString())), w(i))
39
- throw (t.invalid ?? j)(O(i));
40
- return o(i);
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
- return l(e) || a(e) || s(e);
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
- return new TypeError(
47
- "array_key_exists(): Argument #1 ($key) must be a valid array offset type"
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 x(e) {
51
- return a(e) && !(e instanceof Date) && s(e.toString) && e.toString !== Object.prototype.toString;
83
+ function j(e, t) {
84
+ return M(e) && String(b(e)) === String(b(t));
52
85
  }
53
- function j(e) {
54
- return new TypeError(`Cannot access offset of type ${e} on array`);
86
+ function M(e) {
87
+ return !f(e) && !r(e) && !d(e);
55
88
  }
56
- function _(e) {
57
- if (!d(e))
58
- return Object.entries(e);
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 g(e) {
94
- return !h(e) && !s(e) && !I(e);
95
- }
96
- function V(e) {
97
- let t = 0;
98
- return e.map(([r, n]) => P(r) ? [String(t++), n] : [r, n]);
99
- }
100
- function q(e) {
101
- let t = 0;
102
- return e.map(
103
- ([r, n]) => f(o(r)) ? [String(t++), n] : [r, n]
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 { phpIntArgument as f } from "./cast.js";
2
- import { isFiniteNumber as u, isNull as h, isUndefined as l, isInteger as p, isPhpInt as d } from "./guards.js";
3
- const s = 2 ** 30;
4
- function x(e, n, t) {
5
- const r = n < 0 ? Math.max(e + n, 0) : n, a = h(t) ? void 0 : t >= 0 ? r + t : Math.max(r, e + t);
6
- return { start: r, end: a };
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 y(e, n, t) {
9
- const r = f(
10
- n,
11
- "array_splice(): Argument #2 ($offset) must be of type int, float given"
12
- ), a = r < 0 ? Math.max(e + r, 0) : Math.min(r, e);
13
- if (h(t) || l(t))
14
- return { start: a, count: e - a };
15
- const i = f(
16
- t,
17
- "array_splice(): Argument #3 ($length) must be of type ?int, float given"
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 A(e, n) {
25
- const t = Number.isNaN(e) ? n : Math.min(e, n);
26
- if (!p(t) && t < 2)
27
- throw new Error(
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 v(e) {
33
- const n = f(
34
- e,
35
- "array_pad(): Argument #2 ($length) must be of type int, float given"
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 I(e, n, t) {
44
- if (!u(t))
45
- throw g("#3 ($step)", t);
46
- if (t === 0)
47
- throw new Error("range(): Argument #3 ($step) cannot be 0");
48
- if (!u(e))
49
- throw g("#1 ($start)", e);
50
- if (!u(n))
51
- throw g("#2 ($end)", n);
52
- if (n > e && t < 0)
53
- throw new Error(
54
- "range(): Argument #3 ($step) must be greater than 0 for increasing ranges"
55
- );
56
- const r = Math.abs(t), a = Math.abs(n - e);
57
- if (a !== 0 && a < r)
58
- throw new Error(
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 g(e, n) {
73
- const t = Number.isNaN(n) ? "NAN" : "INF";
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 b(e, n, t, r) {
79
- if (r) {
80
- const i = (n - e) / t + 1;
81
- return new Error(
82
- `The supplied range exceeds the maximum array size by ${m(i - s)} elements: start=${m(e)}, end=${m(n)}, step=${m(t)}. Max size: ${s}`
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(e) {
91
- if (!u(e))
92
- return "inf";
93
- let n = Math.abs(e), t = 0;
94
- for (; !Number.isInteger(n); )
95
- n *= 2, t++;
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 { isNull as i, isUndefined as f, isPhpInt as s, isString as u, isBoolean as c, isArray as e, isPlainObject as p, isFunction as n, isObject as b, isNumber as m, isInteger as y } from "./guards.js";
2
- function o(r) {
3
- return i(r) ? "object" : e(r) ? "array" : typeof r;
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 j(r) {
6
- return r === void 0 ? null : typeof r == "function" ? r() : r;
6
+ function f(e) {
7
+ return e === void 0 ? null : typeof e == "function" ? e() : e;
7
8
  }
8
- function O(r) {
9
- return i(r) ? "NULL" : m(r) ? y(r) ? "integer" : "double" : e(r) ? "array" : Number.isNaN(r) ? "double" : n(r) ? "object" : f(r) ? "NULL" : typeof r;
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 L(r) {
12
- return i(r) || f(r) ? "null" : o(r) === "number" ? s(r) ? "int" : "float" : u(r) ? "string" : c(r) ? "bool" : e(r) || p(r) ? "array" : n(r) ? "Closure" : b(r) && n(r.constructor) ? N(r.constructor) : o(r);
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 N(r) {
15
- if (r.name)
16
- return r.name;
17
- const t = Object.getPrototypeOf(r);
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 { phpIntCast as g } from "./cast.js";
2
- import { compareValues as C } from "./equality.js";
3
- import { isArray as a, isFunction as S, isUndefined as h, isBoolean as A, isNumber as l } from "./guards.js";
4
- function B(r) {
5
- return function(n, t) {
6
- if (c(n))
7
- return n;
8
- if (a(n) && c(n[0]))
9
- return n[0];
10
- const [u, o] = a(n) ? n : [n, void 0], m = h(o) || o === !0 || o === "asc" || o === "Ascending", s = t || !m;
11
- return (p, d) => {
12
- const e = C(r(p, u), r(d, u));
13
- return s ? -e : e;
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(r) {
18
- return S(r);
16
+ function c(e) {
17
+ return n(e);
19
18
  }
20
- function D(r) {
21
- return (i, n) => {
22
- const t = r(i, n);
23
- return t === !1 ? -f(r(n, i)) : f(t);
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 f(r) {
27
- return A(r) ? r ? 1 : 0 : l(r) ? Math.sign(g(r)) : 0;
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
@@ -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 t } from "./reflect.js";
2
- function o(r) {
3
- return r.toLowerCase();
1
+ import { phpTypeName as e } from "./reflect.js";
2
+ // src/string.ts
3
+ function t(e) {
4
+ return e.toLowerCase();
4
5
  }
5
- function u(r) {
6
- return r.toUpperCase();
6
+ function n(e) {
7
+ return e.toUpperCase();
7
8
  }
8
- function a(r) {
9
- const e = [...r];
10
- return e.length === 0 ? r : (e[0] = e[0].toLowerCase(), e.join(""));
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(r) {
13
- const e = [...r];
14
- return e.length === 0 ? r : (e[0] = e[0].toUpperCase(), e.join(""));
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 p(r, e) {
17
- return `Array value for key [${String(e)}] must be an array, ${t(r)} found.`;
17
+ function a(t, n) {
18
+ return `Array value for key [${String(n)}] must be an array, ${e(t)} found.`;
18
19
  }
19
- export {
20
- p as arrayValueMessage,
21
- a as lowerFirst,
22
- o as toLower,
23
- u as toUpper,
24
- i as upperFirst
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 };