@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.
@@ -1,3 +1,13 @@
1
+ class n extends Error {
2
+ /**
3
+ * Create a new exception instance.
4
+ *
5
+ * @param message - The exception message
6
+ */
7
+ constructor(e) {
8
+ super(e), this.name = "InvalidArgumentException";
9
+ }
10
+ }
1
11
  class o extends Error {
2
12
  /**
3
13
  * Create a new exception instance.
@@ -6,7 +16,7 @@ class o extends Error {
6
16
  super(""), this.name = "ItemNotFoundException";
7
17
  }
8
18
  }
9
- class n extends Error {
19
+ class r extends Error {
10
20
  /** The number of items found, as Laravel's public `$count`. */
11
21
  count;
12
22
  /**
@@ -14,11 +24,31 @@ class n extends Error {
14
24
  *
15
25
  * @param count - The number of items the lookup matched
16
26
  */
17
- constructor(t) {
18
- super(`${t} items were found.`), this.name = "MultipleItemsFoundException", this.count = t;
27
+ constructor(e) {
28
+ super(`${e} items were found.`), this.name = "MultipleItemsFoundException", this.count = e;
29
+ }
30
+ /**
31
+ * Get the number of items found.
32
+ *
33
+ * @returns The number of items the lookup matched
34
+ */
35
+ getCount() {
36
+ return this.count;
37
+ }
38
+ }
39
+ class s extends Error {
40
+ /**
41
+ * Create a new exception instance.
42
+ *
43
+ * @param message - The exception message
44
+ */
45
+ constructor(e) {
46
+ super(e), this.name = "UnexpectedValueException";
19
47
  }
20
48
  }
21
49
  export {
50
+ n as InvalidArgumentException,
22
51
  o as ItemNotFoundException,
23
- n as MultipleItemsFoundException
52
+ r as MultipleItemsFoundException,
53
+ s as UnexpectedValueException
24
54
  };
package/dist/guards.d.ts CHANGED
@@ -34,6 +34,18 @@ export declare function isObject<T, K extends PropertyKey = PropertyKey>(value:
34
34
  * isPlainObject([1, 2]); -> false
35
35
  */
36
36
  export declare function isPlainObject(value: unknown): value is Record<PropertyKey, unknown>;
37
+ /**
38
+ * Check if a value is an `@tolki/enum` case, the shape `from()` and `cases()` build.
39
+ *
40
+ * @param value - The value to check
41
+ * @returns True for a plain object with its own string `name` and its own string or number `value`
42
+ *
43
+ * @example
44
+ *
45
+ * isEnumCase({ value: 1, backed: true, name: "A" }); -> true
46
+ * isEnumCase({ value: 1 }); -> false
47
+ */
48
+ export declare function isEnumCase(value: unknown): value is Record<"name" | "value", string | number>;
37
49
  /**
38
50
  * Check if a value is any object (including arrays, null).
39
51
  *
@@ -148,6 +160,19 @@ export declare function isInteger(value: unknown): value is number;
148
160
  * @returns True if the value is a float
149
161
  */
150
162
  export declare function isFloat(value: unknown): value is number;
163
+ /**
164
+ * Check if a value is a number PHP holds as an int: an integer within its 64-bit range, and never -0.
165
+ *
166
+ * @param value - The value to check
167
+ * @returns True if PHP would hold the number as an int, false for a float PHP holds, such as 1.5, 1e19 or -0.0
168
+ *
169
+ * @example
170
+ *
171
+ * isPhpInt(2 ** 62); -> true
172
+ * isPhpInt(1e19); -> false
173
+ * isPhpInt(-0); -> false
174
+ */
175
+ export declare function isPhpInt(value: unknown): value is number;
151
176
  /**
152
177
  * Check if a value is a positive number.
153
178
  *
@@ -333,8 +358,9 @@ export declare function isTruthy(value: unknown): boolean;
333
358
  * Determine whether a value is falsy the way PHP's `array_filter()` (no
334
359
  * callback) treats it — PHP's own truthiness, not JS's.
335
360
  *
336
- * Drops `false`, `null`/`undefined`, `0`, `""`, `"0"`, and an empty array or
337
- * plain object; keeps `"00"`, `"0.0"`, and `NaN` (all truthy in PHP).
361
+ * Drops `false`, `null`/`undefined`, `0`, `0n`, `""`, `"0"`, and an empty array,
362
+ * plain object, `Map` or `Set`; keeps `"00"`, `"0.0"`, `NaN` and every other
363
+ * object, however empty, as PHP keeps every object.
338
364
  *
339
365
  * @param value - The value to check
340
366
  * @returns True if the value is falsy under PHP's rules
@@ -343,6 +369,7 @@ export declare function isTruthy(value: unknown): boolean;
343
369
  *
344
370
  * isPhpFalsy("0"); -> true
345
371
  * isPhpFalsy("00"); -> false
372
+ * isPhpFalsy(new Date(0)); -> false
346
373
  */
347
374
  export declare function isPhpFalsy(value: unknown): boolean;
348
375
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../src/guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,OAAO,GAAG,KAAK,IAAI,CAAC,EAAE,CAE5E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,GAAG,WAAW,EAC3D,KAAK,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,GACjC,KAAK,IAAI,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAEvB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CACzB,KAAK,EAAE,OAAO,GACf,KAAK,IAAI,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAQvC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE3D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAczD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,OAAO,GACf,KAAK,IAAI,MAAM,GAAG;IAAE,QAAQ,IAAI,MAAM,CAAA;CAAE,CAc1C;A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}
4
- function b(t) {
5
- return !i(t) && typeof t == "object" && !y(t);
4
+ function y(t) {
5
+ return !o(t) && typeof t == "object" && !b(t);
6
6
  }
7
- function h(t) {
8
- if (!b(t))
7
+ function m(t) {
8
+ if (!y(t))
9
9
  return !1;
10
10
  const n = Object.getPrototypeOf(t);
11
11
  return n === Object.prototype || n === null;
12
12
  }
13
- function S(t) {
13
+ function w(t) {
14
+ return m(t) && Object.hasOwn(t, "name") && e(t.name) && Object.hasOwn(t, "value") && (e(t.value) || r(t.value));
15
+ }
16
+ function j(t) {
14
17
  return typeof t == "object";
15
18
  }
16
19
  function P(t) {
17
- return !i(t) && !c(t) && S(t);
20
+ return !o(t) && !c(t) && j(t);
18
21
  }
19
- function T(t) {
22
+ function E(t) {
20
23
  if (!P(t) && !u(t))
21
24
  return !1;
22
25
  const n = Object.getOwnPropertyDescriptor(
@@ -25,29 +28,32 @@ function T(t) {
25
28
  )?.value;
26
29
  return u(n) && n.prototype === t;
27
30
  }
28
- function o(t) {
31
+ function e(t) {
29
32
  return typeof t == "string";
30
33
  }
31
34
  function W(t) {
32
- return !!(o(t) || e(t) || j(t));
35
+ return !!(e(t) || r(t) || S(t));
33
36
  }
34
- function j(t) {
35
- return !!(b(t) && u(t.toString));
37
+ function S(t) {
38
+ return !!(y(t) && u(t.toString));
36
39
  }
37
- function e(t) {
40
+ function r(t) {
38
41
  return typeof t == "number" && !isNaN(t);
39
42
  }
40
- function E(t) {
41
- return e(t) && Number.isInteger(t);
43
+ function d(t) {
44
+ return r(t) && Number.isInteger(t);
45
+ }
46
+ function z(t) {
47
+ return r(t) && !Number.isInteger(t);
42
48
  }
43
49
  function R(t) {
44
- return e(t) && !Number.isInteger(t);
50
+ return d(t) && t >= -9223372036854776e3 && t < 2 ** 63 && !Object.is(t, -0);
45
51
  }
46
52
  function _(t) {
47
- return e(t) && t >= 0;
53
+ return r(t) && t >= 0;
48
54
  }
49
- function w(t) {
50
- return e(t) && t < 0;
55
+ function B(t) {
56
+ return r(t) && t < 0;
51
57
  }
52
58
  function N(t) {
53
59
  return typeof t == "boolean";
@@ -58,63 +64,63 @@ function u(t) {
58
64
  function c(t) {
59
65
  return typeof t > "u";
60
66
  }
61
- function d(t) {
67
+ function A(t) {
62
68
  return typeof t == "symbol";
63
69
  }
64
- function i(t) {
70
+ function o(t) {
65
71
  return t === null;
66
72
  }
67
- function m(t) {
73
+ function h(t) {
68
74
  return t instanceof Map;
69
75
  }
70
- function O(t) {
76
+ function g(t) {
71
77
  return t instanceof Set;
72
78
  }
73
- function z(t) {
74
- return i(t) || c(t) || o(t) ? !1 : u(
79
+ function C(t) {
80
+ return o(t) || c(t) || e(t) ? !1 : u(
75
81
  t[Symbol.iterator]
76
82
  );
77
83
  }
78
- function B(t) {
84
+ function D(t) {
79
85
  return t instanceof WeakMap;
80
86
  }
81
- function D(t) {
87
+ function U(t) {
82
88
  return t instanceof WeakSet;
83
89
  }
84
- function A(t) {
85
- return Number.isNaN(t) ? !0 : e(t) ? t === 0 : c(t) || i(t) ? !0 : N(t) ? t === !1 : o(t) ? t.trim() === "" : m(t) || O(t) ? t.size === 0 : y(t) ? t.length === 0 : b(t) ? Object.keys(t).length === 0 : !1;
86
- }
87
- function U(t) {
88
- return !A(t);
90
+ function k(t) {
91
+ return Number.isNaN(t) ? !0 : r(t) ? t === 0 : c(t) || o(t) ? !0 : N(t) ? t === !1 : e(t) ? t.trim() === "" : h(t) || g(t) ? t.size === 0 : b(t) ? t.length === 0 : y(t) ? Object.keys(t).length === 0 : !1;
89
92
  }
90
93
  function V(t) {
91
- return t === !1 || t === null || c(t) || t === 0 || t === "" || t === "0" ? !0 : y(t) ? t.length === 0 : b(t) ? Object.keys(t).length === 0 : !1;
94
+ return !k(t);
92
95
  }
93
- const k = /^[ \t\n\r\v\f]*[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?[ \t\n\r\v\f]*$/;
94
96
  function x(t) {
95
- return typeof t == "number" ? !0 : o(t) ? k.test(t) : !1;
97
+ return t === !1 || t === null || c(t) || t === 0 || t === 0n || t === "" || t === "0" ? !0 : b(t) ? t.length === 0 : h(t) || g(t) ? t.size === 0 : m(t) ? Object.keys(t).length === 0 : !1;
98
+ }
99
+ const I = /^[ \t\n\r\v\f]*[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?[ \t\n\r\v\f]*$/;
100
+ function G(t) {
101
+ return typeof t == "number" ? !0 : e(t) ? I.test(t) : !1;
96
102
  }
97
103
  function M(t) {
98
- return i(t) || N(t) || e(t) || o(t) || d(t) || c(t);
104
+ return o(t) || N(t) || r(t) || e(t) || A(t) || c(t);
99
105
  }
100
- function C(t) {
106
+ function H(t) {
101
107
  return !M(t);
102
108
  }
103
109
  function F(t) {
104
- return e(t) && Number.isFinite(t);
110
+ return r(t) && Number.isFinite(t);
105
111
  }
106
- function G(t) {
112
+ function $(t) {
107
113
  return Array.isArray(t);
108
114
  }
109
- function H(t) {
110
- return y(t) || h(t) || m(t);
115
+ function q(t) {
116
+ return b(t) || m(t) || h(t);
111
117
  }
112
118
  function p(t) {
113
- if (o(t))
119
+ if (e(t))
114
120
  return t;
115
121
  if (N(t))
116
122
  return t ? "1" : "";
117
- if (i(t))
123
+ if (o(t))
118
124
  return "";
119
125
  if (F(t)) {
120
126
  const n = String(t);
@@ -122,55 +128,57 @@ function p(t) {
122
128
  }
123
129
  return null;
124
130
  }
125
- function I(t, n) {
126
- const f = p(t), r = p(n);
127
- return f !== null && r !== null ? f === r : t === n || typeof t == "number" && typeof n == "number" && Number.isNaN(t) && Number.isNaN(n);
131
+ function T(t, n) {
132
+ const f = p(t), i = p(n);
133
+ return f !== null && i !== null ? f === i : t === n || typeof t == "number" && typeof n == "number" && Number.isNaN(t) && Number.isNaN(n);
128
134
  }
129
- function $(t) {
135
+ function J(t) {
130
136
  const n = /* @__PURE__ */ new Set(), f = [];
131
- for (const r of t) {
132
- const s = p(r);
133
- i(s) ? f.push(r) : n.add(s);
137
+ for (const i of t) {
138
+ const s = p(i);
139
+ o(s) ? f.push(i) : n.add(s);
134
140
  }
135
- return (r) => {
136
- const s = p(r);
137
- return i(s) ? f.some((g) => I(r, g)) : n.has(s);
141
+ return (i) => {
142
+ const s = p(i);
143
+ return o(s) ? f.some((O) => T(i, O)) : n.has(s);
138
144
  };
139
145
  }
140
146
  export {
141
- G as isAccessibleData,
142
- y as isArray,
147
+ $ as isAccessibleData,
148
+ b as isArray,
143
149
  N as isBoolean,
144
- A as isFalsy,
150
+ w as isEnumCase,
151
+ k as isFalsy,
145
152
  F as isFiniteNumber,
146
- R as isFloat,
153
+ z as isFloat,
147
154
  u as isFunction,
148
- E as isInteger,
149
- z as isIterable,
150
- m as isMap,
151
- w as isNegativeNumber,
152
- C as isNonPrimitive,
153
- i as isNull,
154
- e as isNumber,
155
- b as isObject,
156
- S as isObjectAny,
157
- H as isPhpAccessible,
158
- V as isPhpFalsy,
159
- x as isPhpNumeric,
160
- h as isPlainObject,
155
+ d as isInteger,
156
+ C as isIterable,
157
+ h as isMap,
158
+ B as isNegativeNumber,
159
+ H as isNonPrimitive,
160
+ o as isNull,
161
+ r as isNumber,
162
+ y as isObject,
163
+ j as isObjectAny,
164
+ q as isPhpAccessible,
165
+ x as isPhpFalsy,
166
+ R as isPhpInt,
167
+ G as isPhpNumeric,
168
+ m as isPlainObject,
161
169
  _ as isPositiveNumber,
162
170
  M as isPrimitive,
163
- T as isPrototypeObject,
164
- O as isSet,
165
- o as isString,
171
+ E as isPrototypeObject,
172
+ g as isSet,
173
+ e as isString,
166
174
  W as isStringable,
167
- d as isSymbol,
168
- U as isTruthy,
175
+ A as isSymbol,
176
+ V as isTruthy,
169
177
  P as isTruthyObject,
170
178
  c as isUndefined,
171
- B as isWeakMap,
172
- D as isWeakSet,
173
- j as objectToString,
174
- I as phpValueMatch,
175
- $ as phpValueMatcher
179
+ D as isWeakMap,
180
+ U as isWeakSet,
181
+ S as objectToString,
182
+ T as phpValueMatch,
183
+ J as phpValueMatcher
176
184
  };
package/dist/index.js CHANGED
@@ -1,81 +1,102 @@
1
- import { arrayableItems as i, arrayableValues as t, castableToArray as s, cssListItemToString as o, getAccessibleValues as a, normalizeToArray as p, toArrayable as l, toJsonSerializable as n, toJsonable as y, toPhpKeyString as c } from "./cast.js";
2
- import { compareValues as u, looseEqual as b, operatorMatch as h, strictEqual as f } from "./equality.js";
3
- import { ItemNotFoundException as x, MultipleItemsFoundException as S } from "./exceptions.js";
4
- import { isAccessibleData as A, isArray as N, isBoolean as F, isFalsy as I, isFiniteNumber as K, isFloat as d, isFunction as M, isInteger as T, isIterable as V, isMap as j, isNegativeNumber as v, isNonPrimitive as O, isNull as E, isNumber as k, isObject as L, isObjectAny as U, isPhpAccessible as q, isPhpFalsy as w, isPhpNumeric as z, isPlainObject as D, isPositiveNumber as J, isPrimitive as W, isPrototypeObject as B, isSet as C, isString as R, isStringable as G, isSymbol as H, isTruthy as Q, isTruthyObject as X, isUndefined as Y, isWeakMap as Z, isWeakSet as _, objectToString as $, phpValueMatch as ee, phpValueMatcher as re } from "./guards.js";
5
- import { defineKey as te, entriesKeyValue as se, isIntegerLikeKey as oe, isPhpArrayKey as ae, isUnsafeKey as pe, keyedEntries as le, phpArrayKey as ne, reindexIntegerKeys as ye, renumberPhpIntegerKeys as ce } from "./keys.js";
6
- import { resolveSliceRange as ue } from "./range.js";
7
- import { phpTypeName as he, resolveDefault as fe, typeOf as ge } from "./reflect.js";
8
- import { createSortSpecComparator as Se } from "./sorting.js";
9
- import { arrayValueMessage as Ae, lowerFirst as Ne, toLower as Fe, toUpper as Ie, upperFirst as Ke } from "./string.js";
1
+ import { arrayableItems as t, arrayableValues as i, castableToArray as s, cssListItemToString as a, getAccessibleValues as o, normalizeToArray as p, phpIntArgument as n, phpIntCast as l, phpStringCast as y, toArrayable as m, toJsonSerializable as u, toJsonable as c, toPhpKeyString as b } from "./cast.js";
2
+ import { compareValues as g, looseEqual as x, operatorMatch as S, strictEqual as f } from "./equality.js";
3
+ import { InvalidArgumentException as K, ItemNotFoundException as d, MultipleItemsFoundException as P, UnexpectedValueException as A } from "./exceptions.js";
4
+ import { isAccessibleData as E, isArray as M, isBoolean as N, isEnumCase as T, isFalsy as F, isFiniteNumber as O, isFloat as V, isFunction as C, isInteger as j, isIterable as k, isMap as w, isNegativeNumber as L, isNonPrimitive as U, isNull as z, isNumber as D, isObject as R, isObjectAny as q, isPhpAccessible as J, isPhpFalsy as W, isPhpInt as B, isPhpNumeric as G, isPlainObject as H, isPositiveNumber as Q, isPrimitive as X, isPrototypeObject as Y, isSet as Z, isString as _, isStringable as $, isSymbol as ee, isTruthy as re, isTruthyObject as te, isUndefined as ie, isWeakMap as se, isWeakSet as ae, objectToString as oe, phpValueMatch as pe, phpValueMatcher as ne } from "./guards.js";
5
+ import { arrayKeyExistsError as ye, defineKey as me, deleteMapKey as ue, entriesKeyValue as ce, hasOwnToString as be, isIllegalOffset as he, isIntegerLikeKey as ge, isPhpArrayKey as xe, isUnsafeKey as Se, keyedEntries as fe, nextIntegerKey as Ie, phpArrayKey as Ke, phpComputedKey as de, readMapKey as Pe, reindexIntegerKeys as Ae, renumberPhpIntegerKeys as ve, writeMapKey as Ee } from "./keys.js";
6
+ import { resolvePadLength as Ne, resolveRangeSize as Te, resolveSliceRange as Fe, resolveSpliceRange as Oe, resolveTakeCount as Ve } from "./range.js";
7
+ import { phpDebugType as je, phpTypeName as ke, resolveDefault as we, typeOf as Le } from "./reflect.js";
8
+ import { createSortSpecComparator as ze, phpSortComparator as De } from "./sorting.js";
9
+ import { arrayValueMessage as qe, lowerFirst as Je, toLower as We, toUpper as Be, upperFirst as Ge } from "./string.js";
10
10
  export {
11
- x as ItemNotFoundException,
12
- S as MultipleItemsFoundException,
13
- Ae as arrayValueMessage,
14
- i as arrayableItems,
15
- t as arrayableValues,
11
+ K as InvalidArgumentException,
12
+ d as ItemNotFoundException,
13
+ P as MultipleItemsFoundException,
14
+ A as UnexpectedValueException,
15
+ ye as arrayKeyExistsError,
16
+ qe as arrayValueMessage,
17
+ t as arrayableItems,
18
+ i as arrayableValues,
16
19
  s as castableToArray,
17
- u as compareValues,
18
- Se as createSortSpecComparator,
19
- o as cssListItemToString,
20
- te as defineKey,
21
- se as entriesKeyValue,
22
- a as getAccessibleValues,
23
- A as isAccessibleData,
24
- N as isArray,
25
- F as isBoolean,
26
- I as isFalsy,
27
- K as isFiniteNumber,
28
- d as isFloat,
29
- M as isFunction,
30
- T as isInteger,
31
- oe as isIntegerLikeKey,
32
- V as isIterable,
33
- j as isMap,
34
- v as isNegativeNumber,
35
- O as isNonPrimitive,
36
- E as isNull,
37
- k as isNumber,
38
- L as isObject,
39
- U as isObjectAny,
40
- q as isPhpAccessible,
41
- ae as isPhpArrayKey,
42
- w as isPhpFalsy,
43
- z as isPhpNumeric,
44
- D as isPlainObject,
45
- J as isPositiveNumber,
46
- W as isPrimitive,
47
- B as isPrototypeObject,
48
- C as isSet,
49
- R as isString,
50
- G as isStringable,
51
- H as isSymbol,
52
- Q as isTruthy,
53
- X as isTruthyObject,
54
- Y as isUndefined,
55
- pe as isUnsafeKey,
56
- Z as isWeakMap,
57
- _ as isWeakSet,
58
- le as keyedEntries,
59
- b as looseEqual,
60
- Ne as lowerFirst,
20
+ g as compareValues,
21
+ ze as createSortSpecComparator,
22
+ a as cssListItemToString,
23
+ me as defineKey,
24
+ ue as deleteMapKey,
25
+ ce as entriesKeyValue,
26
+ o as getAccessibleValues,
27
+ be as hasOwnToString,
28
+ E as isAccessibleData,
29
+ M as isArray,
30
+ N as isBoolean,
31
+ T as isEnumCase,
32
+ F as isFalsy,
33
+ O as isFiniteNumber,
34
+ V as isFloat,
35
+ C as isFunction,
36
+ he as isIllegalOffset,
37
+ j as isInteger,
38
+ ge as isIntegerLikeKey,
39
+ k as isIterable,
40
+ w as isMap,
41
+ L as isNegativeNumber,
42
+ U as isNonPrimitive,
43
+ z as isNull,
44
+ D as isNumber,
45
+ R as isObject,
46
+ q as isObjectAny,
47
+ J as isPhpAccessible,
48
+ xe as isPhpArrayKey,
49
+ W as isPhpFalsy,
50
+ B as isPhpInt,
51
+ G as isPhpNumeric,
52
+ H as isPlainObject,
53
+ Q as isPositiveNumber,
54
+ X as isPrimitive,
55
+ Y as isPrototypeObject,
56
+ Z as isSet,
57
+ _ as isString,
58
+ $ as isStringable,
59
+ ee as isSymbol,
60
+ re as isTruthy,
61
+ te as isTruthyObject,
62
+ ie as isUndefined,
63
+ Se as isUnsafeKey,
64
+ se as isWeakMap,
65
+ ae as isWeakSet,
66
+ fe as keyedEntries,
67
+ x as looseEqual,
68
+ Je as lowerFirst,
69
+ Ie as nextIntegerKey,
61
70
  p as normalizeToArray,
62
- $ as objectToString,
63
- h as operatorMatch,
64
- ne as phpArrayKey,
65
- he as phpTypeName,
66
- ee as phpValueMatch,
67
- re as phpValueMatcher,
68
- ye as reindexIntegerKeys,
69
- ce as renumberPhpIntegerKeys,
70
- fe as resolveDefault,
71
- ue as resolveSliceRange,
71
+ oe as objectToString,
72
+ S as operatorMatch,
73
+ Ke as phpArrayKey,
74
+ de as phpComputedKey,
75
+ je as phpDebugType,
76
+ n as phpIntArgument,
77
+ l as phpIntCast,
78
+ De as phpSortComparator,
79
+ y as phpStringCast,
80
+ ke as phpTypeName,
81
+ pe as phpValueMatch,
82
+ ne as phpValueMatcher,
83
+ Pe as readMapKey,
84
+ Ae as reindexIntegerKeys,
85
+ ve as renumberPhpIntegerKeys,
86
+ we as resolveDefault,
87
+ Ne as resolvePadLength,
88
+ Te as resolveRangeSize,
89
+ Fe as resolveSliceRange,
90
+ Oe as resolveSpliceRange,
91
+ Ve as resolveTakeCount,
72
92
  f as strictEqual,
73
- l as toArrayable,
74
- n as toJsonSerializable,
75
- y as toJsonable,
76
- Fe as toLower,
77
- c as toPhpKeyString,
78
- Ie as toUpper,
79
- ge as typeOf,
80
- Ke as upperFirst
93
+ m as toArrayable,
94
+ u as toJsonSerializable,
95
+ c as toJsonable,
96
+ We as toLower,
97
+ b as toPhpKeyString,
98
+ Be as toUpper,
99
+ Le as typeOf,
100
+ Ge as upperFirst,
101
+ Ee as writeMapKey
81
102
  };