@tolki/utils 1.3.0 → 1.4.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
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Cast a value to the string key PHP's `array_combine` stores it under:
3
+ * `null`, `undefined` and `false` become `""`, `true` becomes `"1"`, a number prints the way PHP's
4
+ * `(string)` cast prints it (`INF`, `-0`, `1.0E+21`, 14 significant digits), anything else is stringified.
5
+ *
6
+ * A whole-number JS number always prints as an integer: JS has one number type, so it can't tell
7
+ * PHP's float `123456789012345.0` from the integer `123456789012345`.
8
+ *
9
+ * @param value - The value to use as a key
10
+ * @returns The key string
11
+ *
12
+ * @example
13
+ * toPhpKeyString(true); -> "1"
14
+ * toPhpKeyString(0.1 + 0.2); -> "0.3"
15
+ */
16
+ export declare function toPhpKeyString(value: unknown): string;
1
17
  /**
2
18
  * Check if a value is arrayable (has a toArray method).
3
19
  *
@@ -94,6 +110,20 @@ export declare function getAccessibleValues<T>(data: ReadonlyArray<T> | unknown)
94
110
  * arrayableValues({ x: 20 }); -> [20]
95
111
  */
96
112
  export declare function arrayableValues<T>(items: unknown): T[];
113
+ /**
114
+ * Normalize a keyed operand the way Laravel's `getArrayableItems()` does:
115
+ * nullish becomes `{}`, an Enumerable/Arrayable-like object unwraps via `all()`/`toArray()`/`toJSON()`,
116
+ * a Map or other iterable becomes an object, a list becomes an index-keyed object, and a WeakMap or
117
+ * WeakSet, whose entries can't be read, becomes `{}`. A Map's keys are cast as PHP casts an array key.
118
+ *
119
+ * @param items - The operand to normalize
120
+ * @returns The operand's entries as a plain object
121
+ *
122
+ * @example
123
+ * arrayableItems({ all: () => ({ a: 1 }) }); -> { a: 1 }
124
+ * arrayableItems(new Map([[1, "a"], ["1", "b"]])); -> { 1: "b" }
125
+ */
126
+ export declare function arrayableItems(items: unknown): Record<string, unknown>;
97
127
  /**
98
128
  * Cast a CSS-list value the way PHP casts it when pushed raw into
99
129
  * `implode()`/`Str::finish()`: `null` becomes `""`, a boolean becomes
@@ -1 +1 @@
1
- {"version":3,"file":"cast.d.ts","sourceRoot":"","sources":["../src/cast.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IAAE,OAAO,IAAI,CAAC,EAAE,CAAA;CAAE,CAM1E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,CAAC,EACxB,KAAK,EAAE,OAAO,GACf,KAAK,IAAI;IAAE,MAAM,IAAI,CAAC,CAAA;CAAE,GAAG;IAAE,MAAM,IAAI,CAAC,CAAA;CAAE,CAS5C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAChC,KAAK,EAAE,OAAO,GACf,KAAK,IAAI;IAAE,aAAa,IAAI,CAAC,CAAA;CAAE,CAMjC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,EAAE,GAAG,IAAI,CAG7D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAC9B,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,GACjC,CAAC,EAAE,GAAG,IAAI,CAKZ;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,EAAE,CAG5E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,EAAE,CAsCtD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAU1D"}
1
+ {"version":3,"file":"cast.d.ts","sourceRoot":"","sources":["../src/cast.ts"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAYrD;AAqFD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IAAE,OAAO,IAAI,CAAC,EAAE,CAAA;CAAE,CAM1E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,CAAC,EACxB,KAAK,EAAE,OAAO,GACf,KAAK,IAAI;IAAE,MAAM,IAAI,CAAC,CAAA;CAAE,GAAG;IAAE,MAAM,IAAI,CAAC,CAAA;CAAE,CAS5C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAChC,KAAK,EAAE,OAAO,GACf,KAAK,IAAI;IAAE,aAAa,IAAI,CAAC,CAAA;CAAE,CAMjC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,EAAE,GAAG,IAAI,CAG7D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAC9B,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,GACjC,CAAC,EAAE,GAAG,IAAI,CAKZ;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,EAAE,CAG5E;AAuBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,EAAE,CAyBtD;AAED;;;;;;;;;;;;GAYG;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"}
package/dist/cast.js CHANGED
@@ -1,46 +1,104 @@
1
- import { isNull as o, isUndefined as u, isArray as f, isObject as i, isFunction as t, isMap as c, isIterable as a, isBoolean as l } from "./guards.js";
2
- function b(r) {
3
- return i(r) && !o(r) && t(r.toArray);
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);
4
6
  }
5
7
  function J(r) {
6
- if (!i(r) || o(r))
8
+ if (Number.isNaN(r))
9
+ return "NAN";
10
+ if (!Number.isFinite(r))
11
+ return r > 0 ? "INF" : "-INF";
12
+ if (O(r) && !Object.is(r, -0))
13
+ 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)}`;
18
+ }
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}`;
23
+ }
24
+ function T(r) {
25
+ if (r === 0)
26
+ 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) {
33
+ const N = String(BigInt(i) + 1n);
34
+ a += N.length - i.length, i = N;
35
+ }
36
+ for (; i.endsWith("0"); )
37
+ i = i.slice(0, -1);
38
+ return [i, a];
39
+ }
40
+ function B(r) {
41
+ return c(r) && !s(r) && u(r.toArray);
42
+ }
43
+ function E(r) {
44
+ if (!c(r) || s(r))
7
45
  return !1;
8
- const n = t(r.toJson), s = t(r.toJSON);
9
- return n || s;
46
+ const n = u(r.toJson), t = u(r.toJSON);
47
+ return n || t;
10
48
  }
11
- function S(r) {
12
- return i(r) && !o(r) && t(r.jsonSerialize);
49
+ function P(r) {
50
+ return c(r) && !s(r) && u(r.jsonSerialize);
13
51
  }
14
- function O(r) {
15
- return f(r) ? r : null;
52
+ function k(r) {
53
+ return b(r) ? r : null;
16
54
  }
17
- function y(r) {
55
+ function w(r) {
18
56
  return Array.isArray(r) ? r.slice() : null;
19
57
  }
20
- function z(r) {
21
- return y(r) || [];
22
- }
23
- function e(r) {
24
- if (o(r) || u(r))
25
- return [];
26
- if (f(r))
27
- return r.slice();
28
- if (i(r)) {
29
- const n = r;
30
- return t(n.all) ? e(n.all()) : t(n.toArray) ? e(n.toArray()) : t(n.toJSON) ? e(n.toJSON()) : c(r) ? [...r.values()] : a(r) ? [...r] : Object.values(r);
58
+ function M(r) {
59
+ return w(r) || [];
60
+ }
61
+ function g(r) {
62
+ if (!c(r))
63
+ return r;
64
+ for (const n of ["all", "toArray", "toJSON"])
65
+ if (u(r[n]))
66
+ return g(r[n]());
67
+ return r;
68
+ }
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];
72
+ }
73
+ function K(r) {
74
+ const n = g(r);
75
+ if (s(n) || l(n))
76
+ 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;
85
+ }
86
+ return m(n) || S(n) ? {} : d(n) ? { ...[...n] } : n;
31
87
  }
32
- return [r];
88
+ return { 0: n };
33
89
  }
34
- function N(r) {
35
- return o(r) || u(r) ? "" : l(r) ? r ? "1" : "" : String(r);
90
+ function W(r) {
91
+ return s(r) || l(r) ? "" : A(r) ? r ? "1" : "" : String(r);
36
92
  }
37
93
  export {
38
- e as arrayableValues,
39
- O as castableToArray,
40
- N as cssListItemToString,
41
- z as getAccessibleValues,
42
- y as normalizeToArray,
43
- b as toArrayable,
44
- S as toJsonSerializable,
45
- J as toJsonable
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
46
104
  };
@@ -2,17 +2,35 @@
2
2
  * Order two values the way PHP 8's `<=>` does.
3
3
  *
4
4
  * Numeric operands compare numerically (`"9"` sorts below `"10"`); null/boolean
5
- * compares both sides as booleans; arrays/objects order by JSON form.
5
+ * compares both sides as booleans; two arrays or objects take PHP's array rule —
6
+ * fewer entries first, then element-wise over the left operand's keys. Two `Date`s
7
+ * compare by time value, as PHP compares two `DateTime` objects.
6
8
  *
7
9
  * Faithful to PHP, this order is **not transitive** — `null` ties `0` and `""`,
8
10
  * yet `0 > ""`.
9
11
  *
12
+ * Four recorded divergences from PHP:
13
+ * - a cyclic pair ties, where PHP raises `Error: Nesting level too deep`;
14
+ * - an array against a scalar keeps JS coercion, where PHP sorts every array above
15
+ * every scalar;
16
+ * - a `Date` against an array or a plain object keeps the entry-count rule, where
17
+ * PHP sorts every object above every array: `new DateTime(...) <=> []` is 1 and
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
+ *
23
+ * JS-only: a `Map`, a `Set` and a `RegExp` have no PHP analogue, so there is no
24
+ * rule to port — each carries no own enumerable keys, and any two of them tie.
25
+ * That is a decision, not a divergence; do not "fix" it by analogy with `Date`.
26
+ *
10
27
  * @param a - First value to compare
11
28
  * @param b - Second value to compare
12
29
  * @returns -1 if a < b, 1 if a > b, 0 if equal
13
30
  *
14
31
  * @example
15
32
  * compareValues(0, ""); -> 1
33
+ * compareValues([1], [1, 2]); -> -1
16
34
  */
17
35
  export declare function compareValues(a: unknown, b: unknown): number;
18
36
  /**
@@ -41,7 +59,8 @@ export declare function compareValues(a: unknown, b: unknown): number;
41
59
  export declare function looseEqual(a: unknown, b: unknown): boolean;
42
60
  /**
43
61
  * PHP-like strict equality comparison (=== operator).
44
- * Performs strict type checking for primitives but value-based comparison for arrays and objects.
62
+ * Performs strict type checking for primitives but value-based comparison for arrays and objects:
63
+ * like PHP's `===` on arrays, two plain objects need the same key/value pairs in the same order.
45
64
  * NOTE: For class instances (objects with constructors other than Object), uses reference equality.
46
65
  *
47
66
  * @param a - First value to compare
@@ -54,6 +73,37 @@ export declare function looseEqual(a: unknown, b: unknown): boolean;
54
73
  * strictEqual(1, '1'); -> false (different types)
55
74
  * strictEqual(['a'], ['a']); -> true (same array content)
56
75
  * strictEqual({a: 1}, {a: 1}); -> true (same object content)
76
+ * strictEqual({a: 1, b: 2}, {b: 2, a: 1}); -> false (same pairs, another order)
57
77
  */
58
78
  export declare function strictEqual(a: unknown, b: unknown): boolean;
79
+ /**
80
+ * Compare two values with one of PHP's `where()` operators, the way Laravel's
81
+ * `EnumeratesValues::operatorForWhere()` does.
82
+ *
83
+ * An unrecognised operator falls through to `=`, as PHP's `switch` default does.
84
+ * When exactly one side is an object and the pair holds fewer than two strings,
85
+ * only the inequality operators answer true. That short-circuit is Laravel's own, ahead
86
+ * of the switch; raw PHP does order such a pair, emitting `Notice: Object of class P
87
+ * could not be converted to int` and comparing as if the object were 1. A plain
88
+ * object is not one of those objects, because it models a PHP array here. `===` and
89
+ * `!==` take `strictEqual`, PHP's by-value rule for an array. Every other
90
+ * relational operator orders through `compareValues`, PHP's own comparison rule, so
91
+ * `null` is ordered rather than refused. `NaN` orders with no number and no string —
92
+ * `<`, `>`, `<=` and `>=` are all false there and `<=>` still answers 1, as PHP's
93
+ * `NAN <=> 1` does — but against a bool or null PHP casts both sides to bool and
94
+ * orders normally, so `NAN <=> true` is 0 and `NAN <=> null` is 1.
95
+ *
96
+ * @param retrieved - The value read from the item
97
+ * @param operator - The comparison operator (`=`, `==`, `!=`, `<>`, `<`, `>`, `<=`, `>=`, `===`, `!==`, `<=>`)
98
+ * @param value - The value to compare against
99
+ * @returns True if the comparison holds
100
+ *
101
+ * @example
102
+ *
103
+ * operatorMatch(3, '>', 2); -> true
104
+ * operatorMatch('4', '===', 4); -> false
105
+ * operatorMatch(1, '>', null); -> true (PHP casts null to false and 1 to true)
106
+ * operatorMatch(1, 'nonsense', '1'); -> true (unknown operators compare loosely)
107
+ */
108
+ export declare function operatorMatch(retrieved: unknown, operator: string, value: unknown): boolean;
59
109
  //# sourceMappingURL=equality.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"equality.d.ts","sourceRoot":"","sources":["../src/equality.ts"],"names":[],"mappings":"AAwIA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,CAyC5D;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CA0G1D;AAgID;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAqE3D"}
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"}
package/dist/equality.js CHANGED
@@ -1,109 +1,135 @@
1
- import { isString as i, isBoolean as g, isPhpNumeric as p, isObject as N, isArray as I, isNull as V, isUndefined as H, isPhpFalsy as R } from "./guards.js";
2
- function s(t) {
3
- return V(t) || H(t);
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) {
3
+ return R(t) || U(t);
4
4
  }
5
- function c(t, r) {
5
+ function N(t, r) {
6
6
  return t < r ? -1 : t > r ? 1 : 0;
7
7
  }
8
- const m = /^[ \t\n\r\v\f]*[+-]?\d+[ \t\n\r\v\f]*$/, S = 2 ** 63, P = 2n ** 63n;
9
- function h(t) {
10
- return t >= P ? 1 : t < -P ? -1 : 0;
8
+ const T = /^[ \t\n\r\v\f]*[+-]?\d+[ \t\n\r\v\f]*$/, A = 2 ** 63, k = 2n ** 63n;
9
+ function B(t) {
10
+ return t >= k ? 1 : t < -k ? -1 : 0;
11
11
  }
12
- function F(t, r) {
13
- if (m.test(t) && m.test(r)) {
14
- const o = BigInt(t), u = BigInt(r), n = h(o);
15
- return n !== 0 && n === h(u) && Number(t) === Number(r) ? c(t, r) : o < u ? -1 : o > u ? 1 : 0;
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;
16
16
  }
17
- const e = Number(t), f = Number(r);
18
- return e === f && !Number.isFinite(e) ? c(t, r) : e < f ? -1 : e > f ? 1 : 0;
19
- }
20
- function j(t) {
21
- return typeof t == "number" ? t !== 0 : i(t) ? t !== "" && t !== "0" : I(t) ? t.length > 0 : !!t;
22
- }
23
- function w(t, r) {
24
- if (s(t) && i(r))
25
- return c("", r);
26
- if (i(t) && s(r))
27
- return c(t, "");
28
- if (s(t) || s(r) || g(t) || g(r)) {
29
- const e = j(t), f = j(r);
30
- return e === f ? 0 : e ? 1 : -1;
17
+ const n = Number(t), e = Number(r);
18
+ return n === e && !Number.isFinite(n) ? N(t, r) : n < e ? -1 : n > e ? 1 : 0;
19
+ }
20
+ function _(t) {
21
+ return typeof t == "number" ? t !== 0 : s(t) ? t !== "" && t !== "0" : O(t) ? t.length > 0 : !!t;
22
+ }
23
+ function E(t, r) {
24
+ return G(t, r, void 0);
25
+ }
26
+ function G(t, r, n) {
27
+ if (h(t) && s(r))
28
+ return N("", r);
29
+ if (s(t) && h(r))
30
+ return N(t, "");
31
+ if (h(t) || h(r) || l(t) || l(r)) {
32
+ const e = _(t), i = _(r);
33
+ return e === i ? 0 : e ? 1 : -1;
34
+ }
35
+ if (t instanceof Date && r instanceof Date) {
36
+ const e = t.getTime(), i = r.getTime();
37
+ return e < i ? -1 : e > i ? 1 : 0;
31
38
  }
32
39
  if (typeof t == "object" && typeof r == "object")
33
- return c(JSON.stringify(t), JSON.stringify(r));
34
- if (p(t) && p(r)) {
35
- if (i(t) && i(r))
36
- return F(t, r);
37
- const e = Number(t), f = Number(r);
38
- return e < f ? -1 : e > f ? 1 : 0;
40
+ return q(t, r, n ?? /* @__PURE__ */ new Map());
41
+ if (j(t) && j(r)) {
42
+ if (s(t) && s(r))
43
+ return D(t, r);
44
+ const e = Number(t), i = Number(r);
45
+ return e < i ? -1 : e > i ? 1 : 0;
46
+ }
47
+ return s(t) || s(r) ? N(String(t), String(r)) : t < r ? -1 : t > r ? 1 : 0;
48
+ }
49
+ function q(t, r, n) {
50
+ const e = n.get(t);
51
+ if (e?.has(r))
52
+ return 0;
53
+ const i = e ?? /* @__PURE__ */ new Set();
54
+ e || n.set(t, i), i.add(r);
55
+ const c = C(t, r, n);
56
+ return i.delete(r), c;
57
+ }
58
+ function C(t, r, n) {
59
+ const e = Object.keys(t), i = Object.keys(r).length;
60
+ if (e.length !== i)
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))
65
+ return 1;
66
+ const g = G(c[u], o[u], n);
67
+ if (g !== 0)
68
+ return g;
39
69
  }
40
- return i(t) || i(r) ? c(String(t), String(r)) : t < r ? -1 : t > r ? 1 : 0;
70
+ return 0;
41
71
  }
42
- function B(t, r) {
72
+ function y(t, r) {
43
73
  if (t === r)
44
74
  return !0;
45
- const e = s(t), f = s(r);
46
- if (e && f)
75
+ const n = h(t), e = h(r);
76
+ if (n && e)
47
77
  return !0;
48
- if (e || f) {
49
- const n = e ? r : t;
50
- return i(n) ? n === "" : !l(n);
78
+ if (n || e) {
79
+ const o = n ? r : t;
80
+ return s(o) ? o === "" : !P(o);
51
81
  }
52
- if (g(t) || g(r))
53
- return l(t) === l(r);
54
- if (d(t) || d(r))
82
+ if (l(t) || l(r))
83
+ return P(t) === P(r);
84
+ if (m(t) || m(r))
55
85
  return !1;
56
- if (i(t) !== i(r)) {
57
- const n = i(t) ? r : t;
58
- if (N(n) && !G(n) && U(n))
59
- return String(n) === (i(t) ? t : r);
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);
60
90
  }
61
- const o = A(t) || i(t), u = A(r) || i(r);
62
- if (o && u)
63
- return T(t) && T(r) ? i(t) && i(r) ? F(t, r) === 0 : _(t) && _(r) ? BigInt(t) === BigInt(r) : Number(t) === Number(r) : k(t) === k(r);
64
- if (I(t) && I(r)) {
91
+ const i = d(t) || s(t), c = d(r) || s(r);
92
+ 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)) {
65
95
  if (t.length !== r.length)
66
96
  return !1;
67
- for (let n = 0; n < t.length; n++)
68
- if (!B(t[n], r[n]))
97
+ for (let o = 0; o < t.length; o++)
98
+ if (!y(t[o], r[o]))
69
99
  return !1;
70
100
  return !0;
71
101
  }
72
- if (N(t) && N(r)) {
73
- const n = Object.keys(t), O = Object.keys(r);
74
- return n.length !== O.length ? !1 : n.every(
75
- (y) => O.includes(y) && B(
76
- t[y],
77
- r[y]
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]
78
108
  )
79
109
  );
80
110
  }
81
111
  return !1;
82
112
  }
83
- function G(t) {
84
- const r = Object.getPrototypeOf(t);
85
- return r === Object.prototype || r === null;
86
- }
87
- function l(t) {
88
- return typeof t == "bigint" ? t !== 0n : N(t) && !G(t) ? !0 : !R(t);
113
+ function P(t) {
114
+ return typeof t == "bigint" ? t !== 0n : p(t) && !S(t) ? !0 : !H(t);
89
115
  }
90
- function A(t) {
116
+ function d(t) {
91
117
  return typeof t == "number" || typeof t == "bigint";
92
118
  }
93
- function T(t) {
94
- return typeof t == "bigint" || p(t);
119
+ function w(t) {
120
+ return typeof t == "bigint" || j(t);
95
121
  }
96
- function _(t) {
97
- return typeof t == "bigint" ? !0 : typeof t == "number" ? Number.isInteger(t) && t >= -S && t < S : m.test(t) && h(BigInt(t)) === 0;
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;
98
124
  }
99
- function d(t) {
125
+ function m(t) {
100
126
  return typeof t == "number" && Number.isNaN(t);
101
127
  }
102
- function U(t) {
128
+ function x(t) {
103
129
  const r = t.toString;
104
130
  return typeof r == "function" && r !== Object.prototype.toString;
105
131
  }
106
- function k(t) {
132
+ function V(t) {
107
133
  if (typeof t == "number") {
108
134
  if (t === Number.POSITIVE_INFINITY)
109
135
  return "INF";
@@ -112,36 +138,71 @@ function k(t) {
112
138
  }
113
139
  return String(t);
114
140
  }
115
- function E(t, r) {
141
+ function I(t, r) {
116
142
  if (t === r)
117
143
  return !0;
118
144
  if (Array.isArray(t) && Array.isArray(r)) {
119
145
  if (t.length !== r.length)
120
146
  return !1;
121
- for (let e = 0; e < t.length; e++)
122
- if (!E(t[e], r[e]))
147
+ for (let n = 0; n < t.length; n++)
148
+ if (!I(t[n], r[n]))
123
149
  return !1;
124
150
  return !0;
125
151
  }
126
152
  if (t !== null && r !== null && typeof t == "object" && typeof r == "object" && !Array.isArray(t) && !Array.isArray(r)) {
127
- const e = t.constructor === Object || t.constructor === void 0, f = r.constructor === Object || r.constructor === void 0;
128
- if (!e || !f)
153
+ const n = t.constructor === Object || t.constructor === void 0, e = r.constructor === Object || r.constructor === void 0;
154
+ if (!n || !e)
129
155
  return !1;
130
- const o = Object.keys(t), u = Object.keys(r);
131
- if (o.length !== u.length)
156
+ const i = Object.keys(t), c = Object.keys(r);
157
+ if (i.length !== c.length)
132
158
  return !1;
133
- for (const n of o)
134
- if (!u.includes(n) || !E(
135
- t[n],
136
- r[n]
159
+ for (const [o, u] of i.entries())
160
+ if (u !== c[o] || !I(
161
+ t[u],
162
+ r[u]
137
163
  ))
138
164
  return !1;
139
165
  return !0;
140
166
  }
141
167
  return !1;
142
168
  }
169
+ function Y(t, r, n) {
170
+ const e = [t, n], i = (f) => p(f) && !S(f);
171
+ if (e.filter(
172
+ (f) => s(f) || i(f) && x(f)
173
+ ).length < 2 && e.filter(i).length === 1)
174
+ 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
+ switch (r) {
177
+ case "!=":
178
+ case "<>":
179
+ return !y(t, n);
180
+ case "<":
181
+ return g((f) => f < 0);
182
+ case ">":
183
+ return g((f) => f > 0);
184
+ case "<=":
185
+ return g((f) => f <= 0);
186
+ case ">=":
187
+ return g((f) => f >= 0);
188
+ // PHP's `===` compares an array by value — same keys, same order, same types —
189
+ // and only a real object by identity. strictEqual is that rule; JS's own `===`
190
+ // would call every pair of equal arrays unequal (task-24, "r4-strict-operators").
191
+ case "===":
192
+ return I(t, n);
193
+ case "!==":
194
+ return !I(t, n);
195
+ // PHP's `<=>` is truthy for any non-zero result, so only an equal pair is
196
+ // falsy; an uncomparable one answers 1, not 0, and so counts as unequal.
197
+ case "<=>":
198
+ return u || E(t, n) !== 0;
199
+ default:
200
+ return y(t, n);
201
+ }
202
+ }
143
203
  export {
144
- w as compareValues,
145
- B as looseEqual,
146
- E as strictEqual
204
+ E as compareValues,
205
+ y as looseEqual,
206
+ Y as operatorMatch,
207
+ I as strictEqual
147
208
  };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Thrown when a lookup that must match exactly one item matches none.
3
+ *
4
+ * Laravel's `Illuminate\Support\ItemNotFoundException` extends `RuntimeException`
5
+ * without a constructor, so it carries no message at all — probed as
6
+ * `docs/php-parity/task-24-data-release-readiness.json`, "sole-empty-no-callback"
7
+ * and `task-23-obj-release-readiness.json`, "sole-none".
8
+ */
9
+ export declare class ItemNotFoundException extends Error {
10
+ /**
11
+ * Create a new exception instance.
12
+ */
13
+ constructor();
14
+ }
15
+ /**
16
+ * Thrown when a lookup that must match exactly one item matches several.
17
+ *
18
+ * The message is Laravel's `"{$count} items were found."` — probed as
19
+ * `docs/php-parity/task-24-data-release-readiness.json`, "sole-multi-no-callback"
20
+ * and `task-23-obj-release-readiness.json`, "sole-multi-list".
21
+ */
22
+ export declare class MultipleItemsFoundException extends Error {
23
+ /** The number of items found, as Laravel's public `$count`. */
24
+ readonly count: number;
25
+ /**
26
+ * Create a new exception instance.
27
+ *
28
+ * @param count - The number of items the lookup matched
29
+ */
30
+ constructor(count: number);
31
+ }
32
+ //# sourceMappingURL=exceptions.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,24 @@
1
+ class o extends Error {
2
+ /**
3
+ * Create a new exception instance.
4
+ */
5
+ constructor() {
6
+ super(""), this.name = "ItemNotFoundException";
7
+ }
8
+ }
9
+ class n extends Error {
10
+ /** The number of items found, as Laravel's public `$count`. */
11
+ count;
12
+ /**
13
+ * Create a new exception instance.
14
+ *
15
+ * @param count - The number of items the lookup matched
16
+ */
17
+ constructor(t) {
18
+ super(`${t} items were found.`), this.name = "MultipleItemsFoundException", this.count = t;
19
+ }
20
+ }
21
+ export {
22
+ o as ItemNotFoundException,
23
+ n as MultipleItemsFoundException
24
+ };