@tolki/utils 1.4.0 → 1.5.0

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.d.ts CHANGED
@@ -99,28 +99,30 @@ export declare function getAccessibleValues<T>(data: ReadonlyArray<T> | unknown)
99
99
  /**
100
100
  * Normalize a set-operation operand the way Laravel's
101
101
  * `EnumeratesValues::getArrayableItems()` does: nullish becomes an empty array,
102
- * an Enumerable/Arrayable-like object unwraps via `all()`/`toArray()`, an
103
- * iterable spreads, a plain object contributes its values, anything else
104
- * becomes a one-element array.
102
+ * an Enumerable/Arrayable-like class instance unwraps via `all()`/`toArray()`/`toJSON()`,
103
+ * an iterable spreads, a plain object contributes its values whatever members it
104
+ * has, anything else becomes a one-element array.
105
105
  *
106
106
  * @param items - The operand to normalize
107
107
  * @returns The operand's values, in iteration order
108
108
  *
109
109
  * @example
110
110
  * arrayableValues({ x: 20 }); -> [20]
111
+ * arrayableValues(collect([20])); -> [20]
111
112
  */
112
113
  export declare function arrayableValues<T>(items: unknown): T[];
113
114
  /**
114
115
  * Normalize a keyed operand the way Laravel's `getArrayableItems()` does:
115
- * nullish becomes `{}`, an Enumerable/Arrayable-like object unwraps via `all()`/`toArray()`/`toJSON()`,
116
+ * nullish becomes `{}`, an Enumerable/Arrayable-like class instance unwraps via `all()`/`toArray()`/`toJSON()`,
116
117
  * a Map or other iterable becomes an object, a list becomes an index-keyed object, and a WeakMap or
117
118
  * WeakSet, whose entries can't be read, becomes `{}`. A Map's keys are cast as PHP casts an array key.
119
+ * A plain object is returned as it is, whatever members it has.
118
120
  *
119
121
  * @param items - The operand to normalize
120
122
  * @returns The operand's entries as a plain object
121
123
  *
122
124
  * @example
123
- * arrayableItems({ all: () => ({ a: 1 }) }); -> { a: 1 }
125
+ * arrayableItems(collect({ a: 1 })); -> { a: 1 }
124
126
  * arrayableItems(new Map([[1, "a"], ["1", "b"]])); -> { 1: "b" }
125
127
  */
126
128
  export declare function arrayableItems(items: unknown): Record<string, unknown>;
@@ -133,4 +135,44 @@ export declare function arrayableItems(items: unknown): Record<string, unknown>;
133
135
  * @returns The string PHP would have interpolated.
134
136
  */
135
137
  export declare function cssListItemToString(value: unknown): string;
138
+ /**
139
+ * Read a number PHP passes to an int parameter, which drops a fraction as PHP's coercion does.
140
+ *
141
+ * @param value - The number passed where PHP declares an int
142
+ * @param message - The TypeError message PHP gives for a number no int can hold
143
+ * @returns The number without its fraction
144
+ * @throws TypeError when the number is NAN, infinite or outside PHP's 64-bit int range
145
+ *
146
+ * @example
147
+ * phpIntArgument(7.5, "array_pad(): Argument #2 ($length) must be of type int, float given"); -> 7
148
+ * phpIntArgument(NaN, "array_pad(): Argument #2 ($length) must be of type int, float given"); -> throws TypeError
149
+ */
150
+ export declare function phpIntArgument(value: number, message: string): number;
151
+ /**
152
+ * Cast a number to an int as PHP's `(int)` cast does, as it also reads a comparator's answer and the operands of `%`.
153
+ *
154
+ * @param value - The number to cast
155
+ * @returns The number without its fraction; past PHP's 64-bit int range its low 64 bits as PHP 8 keeps them, and 0 for
156
+ * NAN or an infinity
157
+ *
158
+ * @example
159
+ * phpIntCast(2.7); -> 2
160
+ * phpIntCast(1e19); -> -8446744073709551616
161
+ * phpIntCast(NaN); -> 0
162
+ */
163
+ export declare function phpIntCast(value: number): number;
164
+ /**
165
+ * Cast a value to a string as PHP's `(string)` cast does, as `implode()` casts each piece and `.` its operands.
166
+ *
167
+ * @param value - The value to cast
168
+ * @returns "Array" for an array or what stands for one, an object's own toString, else toPhpKeyString()'s cast of a
169
+ * scalar: true to "1", false and null to "", a float to 14 digits
170
+ * @throws Error `Object of class X could not be converted to string` for any other object and for a closure
171
+ *
172
+ * @example
173
+ * phpStringCast([1, 2]); -> "Array"
174
+ * phpStringCast(true); -> "1"
175
+ * phpStringCast(() => 1); -> throws Error("Object of class Closure could not be converted to string")
176
+ */
177
+ export declare function phpStringCast(value: unknown): string;
136
178
  //# sourceMappingURL=cast.d.ts.map
@@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EAAE,CAyBtD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAkCtE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAU1D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAOrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAahD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAiBpD"}
package/dist/cast.js CHANGED
@@ -1,104 +1,130 @@
1
- import { isNull as s, isUndefined as l, isArray as b, isObject as c, isMap as h, isWeakMap as m, isWeakSet as S, isIterable as d, isBoolean as A, isFunction as u, isNumber as $ } from "./guards.js";
2
- import { keyedEntries as y, defineKey as I, isPhpArrayKey as O } from "./keys.js";
3
- const p = 14;
4
- function z(r) {
5
- return s(r) || l(r) || r === !1 ? "" : r === !0 ? "1" : $(r) || Number.isNaN(r) ? J(r) : String(r);
1
+ import { isNull as s, isUndefined as a, isArray as b, isObject as c, isMap as d, isWeakMap as l, isWeakSet as A, isIterable as y, isBoolean as I, isFiniteNumber as m, isPhpAccessible as $, isFunction as f, isNumber as O, isPlainObject as w } from "./guards.js";
2
+ import { keyedEntries as S, defineKey as T, hasOwnToString as j, isPhpArrayKey as B } from "./keys.js";
3
+ import { phpDebugType as E } from "./reflect.js";
4
+ const g = 14;
5
+ function F(r) {
6
+ return s(r) || a(r) || r === !1 ? "" : r === !0 ? "1" : O(r) || Number.isNaN(r) ? J(r) : String(r);
6
7
  }
7
8
  function J(r) {
8
9
  if (Number.isNaN(r))
9
10
  return "NAN";
10
11
  if (!Number.isFinite(r))
11
12
  return r > 0 ? "INF" : "-INF";
12
- if (O(r) && !Object.is(r, -0))
13
+ if (B(r) && !Object.is(r, -0))
13
14
  return BigInt(r).toString();
14
- const [n, t] = T(Math.abs(r)), e = r < 0 || Object.is(r, -0) ? "-" : "";
15
- if (t < -3 || t > p) {
16
- const i = t - 1, a = `${n.charAt(0)}.${n.slice(1) || "0"}`;
17
- return `${e}${a}E${i < 0 ? "-" : "+"}${Math.abs(i)}`;
15
+ const [t, n] = P(Math.abs(r)), e = r < 0 || Object.is(r, -0) ? "-" : "";
16
+ if (n < -3 || n > g) {
17
+ const i = n - 1, p = `${t.charAt(0)}.${t.slice(1) || "0"}`;
18
+ return `${e}${p}E${i < 0 ? "-" : "+"}${Math.abs(i)}`;
18
19
  }
19
- if (t <= 0)
20
- return `${e}0.${"0".repeat(-t)}${n}`;
21
- const o = n.slice(0, t).padEnd(t, "0"), f = n.slice(t);
22
- return f === "" ? `${e}${o}` : `${e}${o}.${f}`;
20
+ if (n <= 0)
21
+ return `${e}0.${"0".repeat(-n)}${t}`;
22
+ const o = t.slice(0, n).padEnd(n, "0"), u = t.slice(n);
23
+ return u === "" ? `${e}${o}` : `${e}${o}.${u}`;
23
24
  }
24
- function T(r) {
25
+ function P(r) {
25
26
  if (r === 0)
26
27
  return ["0", 1];
27
- let n = r, t = 0;
28
- for (; !Number.isInteger(n); )
29
- n *= 2, t++;
30
- const e = (BigInt(n) * 5n ** BigInt(t)).toString(), o = e.slice(p), f = "5".padEnd(o.length, "0");
31
- let i = e.slice(0, p), a = e.length - t;
32
- if (o > f || o === f && Number(i.at(-1)) % 2 === 1) {
28
+ let t = r, n = 0;
29
+ for (; !Number.isInteger(t); )
30
+ t *= 2, n++;
31
+ const e = (BigInt(t) * 5n ** BigInt(n)).toString(), o = e.slice(g), u = "5".padEnd(o.length, "0");
32
+ let i = e.slice(0, g), p = e.length - n;
33
+ if (o > u || o === u && Number(i.at(-1)) % 2 === 1) {
33
34
  const N = String(BigInt(i) + 1n);
34
- a += N.length - i.length, i = N;
35
+ p += N.length - i.length, i = N;
35
36
  }
36
37
  for (; i.endsWith("0"); )
37
38
  i = i.slice(0, -1);
38
- return [i, a];
39
+ return [i, p];
39
40
  }
40
- function B(r) {
41
- return c(r) && !s(r) && u(r.toArray);
41
+ function C(r) {
42
+ return c(r) && !s(r) && f(r.toArray);
42
43
  }
43
- function E(r) {
44
+ function K(r) {
44
45
  if (!c(r) || s(r))
45
46
  return !1;
46
- const n = u(r.toJson), t = u(r.toJSON);
47
- return n || t;
47
+ const t = f(r.toJson), n = f(r.toJSON);
48
+ return t || n;
48
49
  }
49
- function P(r) {
50
- return c(r) && !s(r) && u(r.jsonSerialize);
50
+ function W(r) {
51
+ return c(r) && !s(r) && f(r.jsonSerialize);
51
52
  }
52
- function k(r) {
53
+ function D(r) {
53
54
  return b(r) ? r : null;
54
55
  }
55
- function w(r) {
56
+ function M(r) {
56
57
  return Array.isArray(r) ? r.slice() : null;
57
58
  }
58
- function M(r) {
59
- return w(r) || [];
59
+ function L(r) {
60
+ return M(r) || [];
60
61
  }
61
- function g(r) {
62
- if (!c(r))
62
+ function h(r) {
63
+ if (w(r) || !c(r))
63
64
  return r;
64
- for (const n of ["all", "toArray", "toJSON"])
65
- if (u(r[n]))
66
- return g(r[n]());
65
+ for (const t of ["all", "toArray", "toJSON"])
66
+ if (f(r[t]))
67
+ return h(r[t]());
67
68
  return r;
68
69
  }
69
- function x(r) {
70
- const n = g(r);
71
- return s(n) || l(n) ? [] : b(n) ? n.slice() : c(n) ? h(n) ? y(n).map(([, t]) => t) : d(n) ? [...n] : Object.values(n) : [n];
70
+ function V(r) {
71
+ const t = h(r);
72
+ return s(t) || a(t) ? [] : b(t) ? t.slice() : c(t) ? d(t) ? S(t).map(([, n]) => n) : y(t) ? [...t] : Object.values(t) : [t];
72
73
  }
73
- function K(r) {
74
- const n = g(r);
75
- if (s(n) || l(n))
74
+ function _(r) {
75
+ const t = h(r);
76
+ if (s(t) || a(t))
76
77
  return {};
77
- if (b(n))
78
- return { ...n };
79
- if (c(n)) {
80
- if (h(n)) {
81
- const t = {};
82
- for (const [e, o] of y(n))
83
- I(t, e, o);
84
- return t;
78
+ if (b(t))
79
+ return { ...t };
80
+ if (c(t)) {
81
+ if (d(t)) {
82
+ const n = {};
83
+ for (const [e, o] of S(t))
84
+ T(n, e, o);
85
+ return n;
85
86
  }
86
- return m(n) || S(n) ? {} : d(n) ? { ...[...n] } : n;
87
+ return l(t) || A(t) ? {} : y(t) ? { ...[...t] } : t;
87
88
  }
88
- return { 0: n };
89
+ return { 0: t };
89
90
  }
90
- function W(r) {
91
- return s(r) || l(r) ? "" : A(r) ? r ? "1" : "" : String(r);
91
+ function H(r) {
92
+ return s(r) || a(r) ? "" : I(r) ? r ? "1" : "" : String(r);
93
+ }
94
+ function R(r, t) {
95
+ if (!m(r) || r < -9223372036854776e3 || r >= 2 ** 63)
96
+ throw new TypeError(t);
97
+ return Math.trunc(r);
98
+ }
99
+ function U(r) {
100
+ if (!m(r))
101
+ return 0;
102
+ const t = Math.trunc(r);
103
+ return t >= -9223372036854776e3 && t < 2 ** 63 ? t === 0 ? 0 : t : Number(BigInt.asIntN(64, BigInt(t)));
104
+ }
105
+ function q(r) {
106
+ if ($(r))
107
+ return "Array";
108
+ if (j(r))
109
+ return String(r.toString());
110
+ if (c(r) || f(r))
111
+ throw new Error(
112
+ `Object of class ${E(r)} could not be converted to string`
113
+ );
114
+ return F(r);
92
115
  }
93
116
  export {
94
- K as arrayableItems,
95
- x as arrayableValues,
96
- k as castableToArray,
97
- W as cssListItemToString,
98
- M as getAccessibleValues,
99
- w as normalizeToArray,
100
- B as toArrayable,
101
- P as toJsonSerializable,
102
- E as toJsonable,
103
- z as toPhpKeyString
117
+ _ as arrayableItems,
118
+ V as arrayableValues,
119
+ D as castableToArray,
120
+ H as cssListItemToString,
121
+ L as getAccessibleValues,
122
+ M as normalizeToArray,
123
+ R as phpIntArgument,
124
+ U as phpIntCast,
125
+ q as phpStringCast,
126
+ C as toArrayable,
127
+ W as toJsonSerializable,
128
+ K as toJsonable,
129
+ F as toPhpKeyString
104
130
  };
@@ -9,16 +9,13 @@
9
9
  * Faithful to PHP, this order is **not transitive** — `null` ties `0` and `""`,
10
10
  * yet `0 > ""`.
11
11
  *
12
- * Four recorded divergences from PHP:
12
+ * Three recorded divergences from PHP:
13
13
  * - a cyclic pair ties, where PHP raises `Error: Nesting level too deep`;
14
14
  * - an array against a scalar keeps JS coercion, where PHP sorts every array above
15
15
  * every scalar;
16
16
  * - a `Date` against an array or a plain object keeps the entry-count rule, where
17
17
  * PHP sorts every object above every array: `new DateTime(...) <=> []` is 1 and
18
18
  * `[] <=> new DateTime(...)` is -1. (Only two OBJECTS answer 1 from either side.)
19
- * - an EMPTY plain object against null or a boolean reads as truthy, where PHP casts
20
- * an empty array to false: `compareValues({}, null)` is 1 and `({}, true)` is 0,
21
- * where PHP's `[] <=> null` is 0 and `[] <=> true` is -1. The `[]` spelling agrees.
22
19
  *
23
20
  * JS-only: a `Map`, a `Set` and a `RegExp` have no PHP analogue, so there is no
24
21
  * rule to port — each carries no own enumerable keys, and any two of them tie.
@@ -1 +1 @@
1
- {"version":3,"file":"equality.d.ts","sourceRoot":"","sources":["../src/equality.ts"],"names":[],"mappings":"AA+IA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,CAE5D;AAuID;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CA0G1D;AAmHD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAqE3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,aAAa,CACzB,SAAS,EAAE,OAAO,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,OAAO,GACf,OAAO,CA2DT"}
1
+ {"version":3,"file":"equality.d.ts","sourceRoot":"","sources":["../src/equality.ts"],"names":[],"mappings":"AAmIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,CAE5D;AAuID;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAgH1D;AA8FD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAqE3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,aAAa,CACzB,SAAS,EAAE,OAAO,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,OAAO,GACf,OAAO,CA2DT"}
package/dist/equality.js CHANGED
@@ -1,35 +1,35 @@
1
- import { isString as s, isBoolean as l, isObject as p, isPlainObject as S, isArray as O, isPhpNumeric as j, isPhpFalsy as H, isNull as R, isUndefined as U } from "./guards.js";
2
- function h(t) {
1
+ import { isNumber as T, isString as u, isPhpNumeric as y, isBoolean as h, isObject as m, isPlainObject as V, isArray as B, isPhpFalsy as H, isNull as R, isUndefined as U } from "./guards.js";
2
+ function g(t) {
3
3
  return R(t) || U(t);
4
4
  }
5
5
  function N(t, r) {
6
6
  return t < r ? -1 : t > r ? 1 : 0;
7
7
  }
8
- const T = /^[ \t\n\r\v\f]*[+-]?\d+[ \t\n\r\v\f]*$/, A = 2 ** 63, k = 2n ** 63n;
9
- function B(t) {
8
+ const j = /^[ \t\n\r\v\f]*[+-]?\d+[ \t\n\r\v\f]*$/, A = 2 ** 63, k = 2n ** 63n;
9
+ function S(t) {
10
10
  return t >= k ? 1 : t < -k ? -1 : 0;
11
11
  }
12
12
  function D(t, r) {
13
- if (T.test(t) && T.test(r)) {
14
- const i = BigInt(t), c = BigInt(r), o = B(i);
15
- return o !== 0 && o === B(c) && Number(t) === Number(r) ? N(t, r) : i < c ? -1 : i > c ? 1 : 0;
13
+ if (j.test(t) && j.test(r)) {
14
+ const i = BigInt(t), c = BigInt(r), s = S(i);
15
+ return s !== 0 && s === S(c) && Number(t) === Number(r) ? N(t, r) : i < c ? -1 : i > c ? 1 : 0;
16
16
  }
17
17
  const n = Number(t), e = Number(r);
18
18
  return n === e && !Number.isFinite(n) ? N(t, r) : n < e ? -1 : n > e ? 1 : 0;
19
19
  }
20
- function _(t) {
21
- return typeof t == "number" ? t !== 0 : s(t) ? t !== "" && t !== "0" : O(t) ? t.length > 0 : !!t;
20
+ function p(t) {
21
+ return !H(t);
22
22
  }
23
- function E(t, r) {
23
+ function _(t, r) {
24
24
  return G(t, r, void 0);
25
25
  }
26
26
  function G(t, r, n) {
27
- if (h(t) && s(r))
27
+ if (g(t) && u(r))
28
28
  return N("", r);
29
- if (s(t) && h(r))
29
+ if (u(t) && g(r))
30
30
  return N(t, "");
31
- if (h(t) || h(r) || l(t) || l(r)) {
32
- const e = _(t), i = _(r);
31
+ if (g(t) || g(r) || h(t) || h(r)) {
32
+ const e = p(t), i = p(r);
33
33
  return e === i ? 0 : e ? 1 : -1;
34
34
  }
35
35
  if (t instanceof Date && r instanceof Date) {
@@ -38,13 +38,13 @@ function G(t, r, n) {
38
38
  }
39
39
  if (typeof t == "object" && typeof r == "object")
40
40
  return q(t, r, n ?? /* @__PURE__ */ new Map());
41
- if (j(t) && j(r)) {
42
- if (s(t) && s(r))
41
+ if (y(t) && y(r)) {
42
+ if (u(t) && u(r))
43
43
  return D(t, r);
44
44
  const e = Number(t), i = Number(r);
45
45
  return e < i ? -1 : e > i ? 1 : 0;
46
46
  }
47
- return s(t) || s(r) ? N(String(t), String(r)) : t < r ? -1 : t > r ? 1 : 0;
47
+ return u(t) || u(r) ? N(String(t), String(r)) : t < r ? -1 : t > r ? 1 : 0;
48
48
  }
49
49
  function q(t, r, n) {
50
50
  const e = n.get(t);
@@ -59,77 +59,78 @@ function C(t, r, n) {
59
59
  const e = Object.keys(t), i = Object.keys(r).length;
60
60
  if (e.length !== i)
61
61
  return e.length < i ? -1 : 1;
62
- const c = t, o = r;
63
- for (const u of e) {
64
- if (!Object.hasOwn(r, u))
62
+ const c = t, s = r;
63
+ for (const f of e) {
64
+ if (!Object.hasOwn(r, f))
65
65
  return 1;
66
- const g = G(c[u], o[u], n);
67
- if (g !== 0)
68
- return g;
66
+ const l = G(c[f], s[f], n);
67
+ if (l !== 0)
68
+ return l;
69
69
  }
70
70
  return 0;
71
71
  }
72
- function y(t, r) {
72
+ function I(t, r) {
73
73
  if (t === r)
74
74
  return !0;
75
- const n = h(t), e = h(r);
75
+ if (T(t) && T(r))
76
+ return !1;
77
+ if (u(t) && u(r))
78
+ return y(t) && y(r) && D(t, r) === 0;
79
+ const n = g(t), e = g(r);
76
80
  if (n && e)
77
81
  return !0;
78
82
  if (n || e) {
79
- const o = n ? r : t;
80
- return s(o) ? o === "" : !P(o);
83
+ const s = n ? r : t;
84
+ return u(s) ? s === "" : !p(s);
81
85
  }
82
- if (l(t) || l(r))
83
- return P(t) === P(r);
84
- if (m(t) || m(r))
86
+ if (h(t) || h(r))
87
+ return p(t) === p(r);
88
+ if (P(t) || P(r))
85
89
  return !1;
86
- if (s(t) !== s(r)) {
87
- const o = s(t) ? r : t;
88
- if (p(o) && !S(o) && x(o))
89
- return String(o) === (s(t) ? t : r);
90
+ if (u(t) !== u(r)) {
91
+ const s = u(t) ? r : t;
92
+ if (m(s) && !V(s) && x(s))
93
+ return String(s) === (u(t) ? t : r);
90
94
  }
91
- const i = d(t) || s(t), c = d(r) || s(r);
95
+ const i = E(t) || u(t), c = E(r) || u(r);
92
96
  if (i && c)
93
- return w(t) && w(r) ? s(t) && s(r) ? D(t, r) === 0 : F(t) && F(r) ? BigInt(t) === BigInt(r) : Number(t) === Number(r) : V(t) === V(r);
94
- if (O(t) && O(r)) {
97
+ return d(t) && d(r) ? w(t) && w(r) ? BigInt(t) === BigInt(r) : Number(t) === Number(r) : F(t) === F(r);
98
+ if (B(t) && B(r)) {
95
99
  if (t.length !== r.length)
96
100
  return !1;
97
- for (let o = 0; o < t.length; o++)
98
- if (!y(t[o], r[o]))
101
+ for (let s = 0; s < t.length; s++)
102
+ if (!I(t[s], r[s]))
99
103
  return !1;
100
104
  return !0;
101
105
  }
102
- if (p(t) && p(r)) {
103
- const o = Object.keys(t), u = Object.keys(r);
104
- return o.length !== u.length ? !1 : o.every(
105
- (g) => u.includes(g) && y(
106
- t[g],
107
- r[g]
106
+ if (m(t) && m(r)) {
107
+ const s = Object.keys(t), f = Object.keys(r);
108
+ return s.length !== f.length ? !1 : s.every(
109
+ (l) => f.includes(l) && I(
110
+ t[l],
111
+ r[l]
108
112
  )
109
113
  );
110
114
  }
111
115
  return !1;
112
116
  }
113
- function P(t) {
114
- return typeof t == "bigint" ? t !== 0n : p(t) && !S(t) ? !0 : !H(t);
117
+ function E(t) {
118
+ return typeof t == "number" || typeof t == "bigint";
115
119
  }
116
120
  function d(t) {
117
- return typeof t == "number" || typeof t == "bigint";
121
+ return typeof t == "bigint" || y(t);
118
122
  }
119
123
  function w(t) {
120
- return typeof t == "bigint" || j(t);
121
- }
122
- function F(t) {
123
- return typeof t == "bigint" ? !0 : typeof t == "number" ? Number.isInteger(t) && t >= -A && t < A : T.test(t) && B(BigInt(t)) === 0;
124
+ return typeof t == "bigint" ? !0 : typeof t == "number" ? Number.isInteger(t) && t >= -A && t < A : j.test(t) && S(BigInt(t)) === 0;
124
125
  }
125
- function m(t) {
126
+ function P(t) {
126
127
  return typeof t == "number" && Number.isNaN(t);
127
128
  }
128
129
  function x(t) {
129
130
  const r = t.toString;
130
131
  return typeof r == "function" && r !== Object.prototype.toString;
131
132
  }
132
- function V(t) {
133
+ function F(t) {
133
134
  if (typeof t == "number") {
134
135
  if (t === Number.POSITIVE_INFINITY)
135
136
  return "INF";
@@ -138,14 +139,14 @@ function V(t) {
138
139
  }
139
140
  return String(t);
140
141
  }
141
- function I(t, r) {
142
+ function O(t, r) {
142
143
  if (t === r)
143
144
  return !0;
144
145
  if (Array.isArray(t) && Array.isArray(r)) {
145
146
  if (t.length !== r.length)
146
147
  return !1;
147
148
  for (let n = 0; n < t.length; n++)
148
- if (!I(t[n], r[n]))
149
+ if (!O(t[n], r[n]))
149
150
  return !1;
150
151
  return !0;
151
152
  }
@@ -156,10 +157,10 @@ function I(t, r) {
156
157
  const i = Object.keys(t), c = Object.keys(r);
157
158
  if (i.length !== c.length)
158
159
  return !1;
159
- for (const [o, u] of i.entries())
160
- if (u !== c[o] || !I(
161
- t[u],
162
- r[u]
160
+ for (const [s, f] of i.entries())
161
+ if (f !== c[s] || !O(
162
+ t[f],
163
+ r[f]
163
164
  ))
164
165
  return !1;
165
166
  return !0;
@@ -167,42 +168,42 @@ function I(t, r) {
167
168
  return !1;
168
169
  }
169
170
  function Y(t, r, n) {
170
- const e = [t, n], i = (f) => p(f) && !S(f);
171
+ const e = [t, n], i = (o) => m(o) && !V(o);
171
172
  if (e.filter(
172
- (f) => s(f) || i(f) && x(f)
173
+ (o) => u(o) || i(o) && x(o)
173
174
  ).length < 2 && e.filter(i).length === 1)
174
175
  return ["!=", "<>", "!=="].includes(r);
175
- const u = !(l(t) || l(n) || h(t) || h(n)) && (m(t) || m(n)), g = (f) => !u && f(E(t, n));
176
+ const f = !(h(t) || h(n) || g(t) || g(n)) && (P(t) || P(n)), l = (o) => !f && o(_(t, n));
176
177
  switch (r) {
177
178
  case "!=":
178
179
  case "<>":
179
- return !y(t, n);
180
+ return !I(t, n);
180
181
  case "<":
181
- return g((f) => f < 0);
182
+ return l((o) => o < 0);
182
183
  case ">":
183
- return g((f) => f > 0);
184
+ return l((o) => o > 0);
184
185
  case "<=":
185
- return g((f) => f <= 0);
186
+ return l((o) => o <= 0);
186
187
  case ">=":
187
- return g((f) => f >= 0);
188
+ return l((o) => o >= 0);
188
189
  // PHP's `===` compares an array by value — same keys, same order, same types —
189
190
  // and only a real object by identity. strictEqual is that rule; JS's own `===`
190
191
  // would call every pair of equal arrays unequal (task-24, "r4-strict-operators").
191
192
  case "===":
192
- return I(t, n);
193
+ return O(t, n);
193
194
  case "!==":
194
- return !I(t, n);
195
+ return !O(t, n);
195
196
  // PHP's `<=>` is truthy for any non-zero result, so only an equal pair is
196
197
  // falsy; an uncomparable one answers 1, not 0, and so counts as unequal.
197
198
  case "<=>":
198
- return u || E(t, n) !== 0;
199
+ return f || _(t, n) !== 0;
199
200
  default:
200
- return y(t, n);
201
+ return I(t, n);
201
202
  }
202
203
  }
203
204
  export {
204
- E as compareValues,
205
- y as looseEqual,
205
+ _ as compareValues,
206
+ I as looseEqual,
206
207
  Y as operatorMatch,
207
- I as strictEqual
208
+ O as strictEqual
208
209
  };
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Thrown for an argument out of range, as Laravel's `nth()` throws `'Step value must be at least 1.'`.
3
+ */
4
+ export declare class InvalidArgumentException extends Error {
5
+ /**
6
+ * Create a new exception instance.
7
+ *
8
+ * @param message - The exception message
9
+ */
10
+ constructor(message: string);
11
+ }
1
12
  /**
2
13
  * Thrown when a lookup that must match exactly one item matches none.
3
14
  *
@@ -28,5 +39,22 @@ export declare class MultipleItemsFoundException extends Error {
28
39
  * @param count - The number of items the lookup matched
29
40
  */
30
41
  constructor(count: number);
42
+ /**
43
+ * Get the number of items found.
44
+ *
45
+ * @returns The number of items the lookup matched
46
+ */
47
+ getCount(): number;
48
+ }
49
+ /**
50
+ * Thrown for a value of the wrong type, as Laravel's `ensure()` and `reduceSpread()` throw it.
51
+ */
52
+ export declare class UnexpectedValueException extends Error {
53
+ /**
54
+ * Create a new exception instance.
55
+ *
56
+ * @param message - The exception message
57
+ */
58
+ constructor(message: string);
31
59
  }
32
60
  //# sourceMappingURL=exceptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../src/exceptions.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC5C;;OAEG;;CAMN;AAED;;;;;;GAMG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;IAClD,+DAA+D;IAC/D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB;;;;OAIG;gBACS,KAAK,EAAE,MAAM;CAM5B"}
1
+ {"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../src/exceptions.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IAC/C;;;;OAIG;gBACS,OAAO,EAAE,MAAM;CAK9B;AAED;;;;;;;GAOG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC5C;;OAEG;;CAMN;AAED;;;;;;GAMG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;IAClD,+DAA+D;IAC/D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEvB;;;;OAIG;gBACS,KAAK,EAAE,MAAM;IAOzB;;;;OAIG;IACH,QAAQ,IAAI,MAAM;CAGrB;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,KAAK;IAC/C;;;;OAIG;gBACS,OAAO,EAAE,MAAM;CAK9B"}