@tolki/utils 1.4.0 → 1.6.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 +47 -5
- package/dist/cast.d.ts.map +1 -1
- package/dist/cast.js +93 -67
- package/dist/equality.d.ts +1 -4
- package/dist/equality.d.ts.map +1 -1
- package/dist/equality.js +79 -78
- package/dist/exceptions.d.ts +32 -4
- package/dist/exceptions.d.ts.map +1 -1
- package/dist/exceptions.js +34 -4
- package/dist/guards.d.ts +29 -2
- package/dist/guards.d.ts.map +1 -1
- package/dist/guards.js +88 -80
- package/dist/index.js +97 -76
- package/dist/keys.d.ts +110 -2
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +118 -61
- package/dist/range.d.ts +70 -0
- package/dist/range.d.ts.map +1 -1
- package/dist/range.js +103 -5
- package/dist/reflect.d.ts +16 -2
- package/dist/reflect.d.ts.map +1 -1
- package/dist/reflect.js +19 -9
- package/dist/sorting.d.ts +16 -2
- package/dist/sorting.d.ts.map +1 -1
- package/dist/sorting.js +27 -13
- package/dist/utils.js +97 -76
- package/package.json +2 -2
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
|
|
103
|
-
* iterable spreads, a plain object contributes its values
|
|
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
|
|
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(
|
|
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
|
package/dist/cast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cast.d.ts","sourceRoot":"","sources":["../src/cast.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cast.d.ts","sourceRoot":"","sources":["../src/cast.ts"],"names":[],"mappings":"AAsBA;;;;;;;;;;;;;;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;AAwBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,GAAG,CAAC,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
|
|
2
|
-
import { keyedEntries as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 (
|
|
13
|
+
if (B(r) && !Object.is(r, -0))
|
|
13
14
|
return BigInt(r).toString();
|
|
14
|
-
const [
|
|
15
|
-
if (
|
|
16
|
-
const i =
|
|
17
|
-
return `${e}${
|
|
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 (
|
|
20
|
-
return `${e}0.${"0".repeat(-
|
|
21
|
-
const o =
|
|
22
|
-
return
|
|
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
|
|
25
|
+
function P(r) {
|
|
25
26
|
if (r === 0)
|
|
26
27
|
return ["0", 1];
|
|
27
|
-
let
|
|
28
|
-
for (; !Number.isInteger(
|
|
29
|
-
|
|
30
|
-
const e = (BigInt(
|
|
31
|
-
let i = e.slice(0,
|
|
32
|
-
if (o >
|
|
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
|
-
|
|
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,
|
|
39
|
+
return [i, p];
|
|
39
40
|
}
|
|
40
|
-
function
|
|
41
|
-
return c(r) && !s(r) &&
|
|
41
|
+
function C(r) {
|
|
42
|
+
return c(r) && !s(r) && f(r.toArray);
|
|
42
43
|
}
|
|
43
|
-
function
|
|
44
|
+
function K(r) {
|
|
44
45
|
if (!c(r) || s(r))
|
|
45
46
|
return !1;
|
|
46
|
-
const
|
|
47
|
-
return
|
|
47
|
+
const t = f(r.toJson), n = f(r.toJSON);
|
|
48
|
+
return t || n;
|
|
48
49
|
}
|
|
49
|
-
function
|
|
50
|
-
return c(r) && !s(r) &&
|
|
50
|
+
function W(r) {
|
|
51
|
+
return c(r) && !s(r) && f(r.jsonSerialize);
|
|
51
52
|
}
|
|
52
|
-
function
|
|
53
|
+
function D(r) {
|
|
53
54
|
return b(r) ? r : null;
|
|
54
55
|
}
|
|
55
|
-
function
|
|
56
|
+
function M(r) {
|
|
56
57
|
return Array.isArray(r) ? r.slice() : null;
|
|
57
58
|
}
|
|
58
|
-
function
|
|
59
|
-
return
|
|
59
|
+
function L(r) {
|
|
60
|
+
return M(r) || [];
|
|
60
61
|
}
|
|
61
|
-
function
|
|
62
|
-
if (!c(r))
|
|
62
|
+
function h(r) {
|
|
63
|
+
if (w(r) || !c(r))
|
|
63
64
|
return r;
|
|
64
|
-
for (const
|
|
65
|
-
if (
|
|
66
|
-
return
|
|
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
|
|
70
|
-
const
|
|
71
|
-
return s(
|
|
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
|
|
74
|
-
const
|
|
75
|
-
if (s(
|
|
74
|
+
function _(r) {
|
|
75
|
+
const t = h(r);
|
|
76
|
+
if (s(t) || a(t))
|
|
76
77
|
return {};
|
|
77
|
-
if (b(
|
|
78
|
-
return { ...
|
|
79
|
-
if (c(
|
|
80
|
-
if (
|
|
81
|
-
const
|
|
82
|
-
for (const [e, o] of
|
|
83
|
-
|
|
84
|
-
return
|
|
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
|
|
87
|
+
return l(t) || A(t) ? {} : y(t) ? { ...[...t] } : t;
|
|
87
88
|
}
|
|
88
|
-
return { 0:
|
|
89
|
+
return { 0: t };
|
|
89
90
|
}
|
|
90
|
-
function
|
|
91
|
-
return s(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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
};
|
package/dist/equality.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
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.
|
package/dist/equality.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"equality.d.ts","sourceRoot":"","sources":["../src/equality.ts"],"names":[],"mappings":"
|
|
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
|
|
2
|
-
function
|
|
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
|
|
9
|
-
function
|
|
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 (
|
|
14
|
-
const i = BigInt(t), c = BigInt(r),
|
|
15
|
-
return
|
|
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
|
|
21
|
-
return
|
|
20
|
+
function p(t) {
|
|
21
|
+
return !H(t);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function _(t, r) {
|
|
24
24
|
return G(t, r, void 0);
|
|
25
25
|
}
|
|
26
26
|
function G(t, r, n) {
|
|
27
|
-
if (
|
|
27
|
+
if (g(t) && u(r))
|
|
28
28
|
return N("", r);
|
|
29
|
-
if (
|
|
29
|
+
if (u(t) && g(r))
|
|
30
30
|
return N(t, "");
|
|
31
|
-
if (
|
|
32
|
-
const e =
|
|
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 (
|
|
42
|
-
if (
|
|
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
|
|
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,
|
|
63
|
-
for (const
|
|
64
|
-
if (!Object.hasOwn(r,
|
|
62
|
+
const c = t, s = r;
|
|
63
|
+
for (const f of e) {
|
|
64
|
+
if (!Object.hasOwn(r, f))
|
|
65
65
|
return 1;
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
return
|
|
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
|
|
72
|
+
function I(t, r) {
|
|
73
73
|
if (t === r)
|
|
74
74
|
return !0;
|
|
75
|
-
|
|
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
|
|
80
|
-
return s
|
|
83
|
+
const s = n ? r : t;
|
|
84
|
+
return u(s) ? s === "" : !p(s);
|
|
81
85
|
}
|
|
82
|
-
if (
|
|
83
|
-
return
|
|
84
|
-
if (
|
|
86
|
+
if (h(t) || h(r))
|
|
87
|
+
return p(t) === p(r);
|
|
88
|
+
if (P(t) || P(r))
|
|
85
89
|
return !1;
|
|
86
|
-
if (
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
return String(
|
|
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 =
|
|
95
|
+
const i = E(t) || u(t), c = E(r) || u(r);
|
|
92
96
|
if (i && c)
|
|
93
|
-
return
|
|
94
|
-
if (
|
|
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
|
|
98
|
-
if (!
|
|
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 (
|
|
103
|
-
const
|
|
104
|
-
return
|
|
105
|
-
(
|
|
106
|
-
t[
|
|
107
|
-
r[
|
|
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
|
|
114
|
-
return typeof t == "
|
|
117
|
+
function E(t) {
|
|
118
|
+
return typeof t == "number" || typeof t == "bigint";
|
|
115
119
|
}
|
|
116
120
|
function d(t) {
|
|
117
|
-
return typeof t == "
|
|
121
|
+
return typeof t == "bigint" || y(t);
|
|
118
122
|
}
|
|
119
123
|
function w(t) {
|
|
120
|
-
return typeof t == "bigint"
|
|
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
|
|
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
|
|
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
|
|
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 (!
|
|
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 [
|
|
160
|
-
if (
|
|
161
|
-
t[
|
|
162
|
-
r[
|
|
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 = (
|
|
171
|
+
const e = [t, n], i = (o) => m(o) && !V(o);
|
|
171
172
|
if (e.filter(
|
|
172
|
-
(
|
|
173
|
+
(o) => u(o) || i(o) && x(o)
|
|
173
174
|
).length < 2 && e.filter(i).length === 1)
|
|
174
175
|
return ["!=", "<>", "!=="].includes(r);
|
|
175
|
-
const
|
|
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 !
|
|
180
|
+
return !I(t, n);
|
|
180
181
|
case "<":
|
|
181
|
-
return
|
|
182
|
+
return l((o) => o < 0);
|
|
182
183
|
case ">":
|
|
183
|
-
return
|
|
184
|
+
return l((o) => o > 0);
|
|
184
185
|
case "<=":
|
|
185
|
-
return
|
|
186
|
+
return l((o) => o <= 0);
|
|
186
187
|
case ">=":
|
|
187
|
-
return
|
|
188
|
-
// PHP's `===` compares an array by value — same keys, same order, same types —
|
|
189
|
-
//
|
|
190
|
-
//
|
|
188
|
+
return l((o) => o >= 0);
|
|
189
|
+
// PHP's `===` compares an array by value — same keys, same order, same types — and only a real object by
|
|
190
|
+
// identity. strictEqual is that rule; JS's own `===` would call every pair of equal arrays unequal
|
|
191
|
+
// (docs/php-parity/Collection/contains.json, "r4-strict-operators").
|
|
191
192
|
case "===":
|
|
192
|
-
return
|
|
193
|
+
return O(t, n);
|
|
193
194
|
case "!==":
|
|
194
|
-
return !
|
|
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
|
|
199
|
+
return f || _(t, n) !== 0;
|
|
199
200
|
default:
|
|
200
|
-
return
|
|
201
|
+
return I(t, n);
|
|
201
202
|
}
|
|
202
203
|
}
|
|
203
204
|
export {
|
|
204
|
-
|
|
205
|
-
|
|
205
|
+
_ as compareValues,
|
|
206
|
+
I as looseEqual,
|
|
206
207
|
Y as operatorMatch,
|
|
207
|
-
|
|
208
|
+
O as strictEqual
|
|
208
209
|
};
|
package/dist/exceptions.d.ts
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
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
|
*
|
|
4
15
|
* Laravel's `Illuminate\Support\ItemNotFoundException` extends `RuntimeException`
|
|
5
16
|
* without a constructor, so it carries no message at all — probed as
|
|
6
|
-
* `docs/php-parity/
|
|
7
|
-
* and `
|
|
17
|
+
* `docs/php-parity/Arr/sole.json`, "sole-empty-no-callback"
|
|
18
|
+
* and `docs/php-parity/Arr/sole.json`, "sole-none".
|
|
8
19
|
*/
|
|
9
20
|
export declare class ItemNotFoundException extends Error {
|
|
10
21
|
/**
|
|
@@ -16,8 +27,8 @@ export declare class ItemNotFoundException extends Error {
|
|
|
16
27
|
* Thrown when a lookup that must match exactly one item matches several.
|
|
17
28
|
*
|
|
18
29
|
* The message is Laravel's `"{$count} items were found."` — probed as
|
|
19
|
-
* `docs/php-parity/
|
|
20
|
-
* and `
|
|
30
|
+
* `docs/php-parity/Arr/sole.json`, "sole-multi-no-callback"
|
|
31
|
+
* and `docs/php-parity/Arr/sole.json`, "sole-multi-list".
|
|
21
32
|
*/
|
|
22
33
|
export declare class MultipleItemsFoundException extends Error {
|
|
23
34
|
/** The number of items found, as Laravel's public `$count`. */
|
|
@@ -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
|
package/dist/exceptions.d.ts.map
CHANGED
|
@@ -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;
|
|
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"}
|