@tolki/utils 1.5.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/equality.js CHANGED
@@ -186,9 +186,9 @@ function Y(t, r, n) {
186
186
  return l((o) => o <= 0);
187
187
  case ">=":
188
188
  return l((o) => o >= 0);
189
- // PHP's `===` compares an array by value — same keys, same order, same types —
190
- // and only a real object by identity. strictEqual is that rule; JS's own `===`
191
- // would call every pair of equal arrays unequal (task-24, "r4-strict-operators").
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").
192
192
  case "===":
193
193
  return O(t, n);
194
194
  case "!==":
@@ -14,8 +14,8 @@ export declare class InvalidArgumentException extends Error {
14
14
  *
15
15
  * Laravel's `Illuminate\Support\ItemNotFoundException` extends `RuntimeException`
16
16
  * without a constructor, so it carries no message at all — probed as
17
- * `docs/php-parity/task-24-data-release-readiness.json`, "sole-empty-no-callback"
18
- * and `task-23-obj-release-readiness.json`, "sole-none".
17
+ * `docs/php-parity/Arr/sole.json`, "sole-empty-no-callback"
18
+ * and `docs/php-parity/Arr/sole.json`, "sole-none".
19
19
  */
20
20
  export declare class ItemNotFoundException extends Error {
21
21
  /**
@@ -27,8 +27,8 @@ export declare class ItemNotFoundException extends Error {
27
27
  * Thrown when a lookup that must match exactly one item matches several.
28
28
  *
29
29
  * The message is Laravel's `"{$count} items were found."` — probed as
30
- * `docs/php-parity/task-24-data-release-readiness.json`, "sole-multi-no-callback"
31
- * and `task-23-obj-release-readiness.json`, "sole-multi-list".
30
+ * `docs/php-parity/Arr/sole.json`, "sole-multi-no-callback"
31
+ * and `docs/php-parity/Arr/sole.json`, "sole-multi-list".
32
32
  */
33
33
  export declare class MultipleItemsFoundException extends Error {
34
34
  /** The number of items found, as Laravel's public `$count`. */
package/dist/index.js CHANGED
@@ -1,50 +1,51 @@
1
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 S, operatorMatch as f, strictEqual as x } from "./equality.js";
3
- import { InvalidArgumentException as P, ItemNotFoundException as A, MultipleItemsFoundException as d, UnexpectedValueException as v } from "./exceptions.js";
4
- import { isAccessibleData as E, isArray as N, isBoolean as T, isEnumCase as F, isFalsy as O, isFiniteNumber as V, isFloat as C, isFunction as M, isInteger as j, isIterable as k, isMap as L, isNegativeNumber as U, isNonPrimitive as w, 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, entriesKeyValue as ue, hasOwnToString as ce, isIllegalOffset as be, isIntegerLikeKey as he, isPhpArrayKey as ge, isUnsafeKey as Se, keyedEntries as fe, phpArrayKey as xe, phpComputedKey as Ie, reindexIntegerKeys as Pe, renumberPhpIntegerKeys as Ae } from "./keys.js";
6
- import { resolvePadLength as ve, resolveRangeSize as Ke, resolveSliceRange as Ee, resolveSpliceRange as Ne, resolveTakeCount as Te } from "./range.js";
7
- import { phpDebugType as Oe, phpTypeName as Ve, resolveDefault as Ce, typeOf as Me } from "./reflect.js";
8
- import { createSortSpecComparator as ke, phpSortComparator as Le } from "./sorting.js";
9
- import { arrayValueMessage as we, lowerFirst as ze, toLower as De, toUpper as Re, upperFirst as qe } from "./string.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
- P as InvalidArgumentException,
12
- A as ItemNotFoundException,
13
- d as MultipleItemsFoundException,
14
- v as UnexpectedValueException,
11
+ K as InvalidArgumentException,
12
+ d as ItemNotFoundException,
13
+ P as MultipleItemsFoundException,
14
+ A as UnexpectedValueException,
15
15
  ye as arrayKeyExistsError,
16
- we as arrayValueMessage,
16
+ qe as arrayValueMessage,
17
17
  t as arrayableItems,
18
18
  i as arrayableValues,
19
19
  s as castableToArray,
20
20
  g as compareValues,
21
- ke as createSortSpecComparator,
21
+ ze as createSortSpecComparator,
22
22
  a as cssListItemToString,
23
23
  me as defineKey,
24
- ue as entriesKeyValue,
24
+ ue as deleteMapKey,
25
+ ce as entriesKeyValue,
25
26
  o as getAccessibleValues,
26
- ce as hasOwnToString,
27
+ be as hasOwnToString,
27
28
  E as isAccessibleData,
28
- N as isArray,
29
- T as isBoolean,
30
- F as isEnumCase,
31
- O as isFalsy,
32
- V as isFiniteNumber,
33
- C as isFloat,
34
- M as isFunction,
35
- be as isIllegalOffset,
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,
36
37
  j as isInteger,
37
- he as isIntegerLikeKey,
38
+ ge as isIntegerLikeKey,
38
39
  k as isIterable,
39
- L as isMap,
40
- U as isNegativeNumber,
41
- w as isNonPrimitive,
40
+ w as isMap,
41
+ L as isNegativeNumber,
42
+ U as isNonPrimitive,
42
43
  z as isNull,
43
44
  D as isNumber,
44
45
  R as isObject,
45
46
  q as isObjectAny,
46
47
  J as isPhpAccessible,
47
- ge as isPhpArrayKey,
48
+ xe as isPhpArrayKey,
48
49
  W as isPhpFalsy,
49
50
  B as isPhpInt,
50
51
  G as isPhpNumeric,
@@ -63,36 +64,39 @@ export {
63
64
  se as isWeakMap,
64
65
  ae as isWeakSet,
65
66
  fe as keyedEntries,
66
- S as looseEqual,
67
- ze as lowerFirst,
67
+ x as looseEqual,
68
+ Je as lowerFirst,
69
+ Ie as nextIntegerKey,
68
70
  p as normalizeToArray,
69
71
  oe as objectToString,
70
- f as operatorMatch,
71
- xe as phpArrayKey,
72
- Ie as phpComputedKey,
73
- Oe as phpDebugType,
72
+ S as operatorMatch,
73
+ Ke as phpArrayKey,
74
+ de as phpComputedKey,
75
+ je as phpDebugType,
74
76
  n as phpIntArgument,
75
77
  l as phpIntCast,
76
- Le as phpSortComparator,
78
+ De as phpSortComparator,
77
79
  y as phpStringCast,
78
- Ve as phpTypeName,
80
+ ke as phpTypeName,
79
81
  pe as phpValueMatch,
80
82
  ne as phpValueMatcher,
81
- Pe as reindexIntegerKeys,
82
- Ae as renumberPhpIntegerKeys,
83
- Ce as resolveDefault,
84
- ve as resolvePadLength,
85
- Ke as resolveRangeSize,
86
- Ee as resolveSliceRange,
87
- Ne as resolveSpliceRange,
88
- Te as resolveTakeCount,
89
- x as strictEqual,
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,
92
+ f as strictEqual,
90
93
  m as toArrayable,
91
94
  u as toJsonSerializable,
92
95
  c as toJsonable,
93
- De as toLower,
96
+ We as toLower,
94
97
  b as toPhpKeyString,
95
- Re as toUpper,
96
- Me as typeOf,
97
- qe as upperFirst
98
+ Be as toUpper,
99
+ Le as typeOf,
100
+ Ge as upperFirst,
101
+ Ee as writeMapKey
98
102
  };
package/dist/keys.d.ts CHANGED
@@ -117,6 +117,64 @@ export declare function hasOwnToString(value: unknown): value is {
117
117
  * keyedEntries(new Map([[1, "a"], ["1", "b"]])); -> [["1", "b"]]
118
118
  */
119
119
  export declare function keyedEntries<TValue = unknown>(data: object): [string, TValue][];
120
+ /**
121
+ * Read a Map entry by the key PHP stores for the given key.
122
+ *
123
+ * Of several Map keys PHP stores as one, the last value wins, as in {@linkcode keyedEntries}.
124
+ * A stored `null` or `undefined` counts as found.
125
+ *
126
+ * @param map - The Map to read.
127
+ * @param key - The key to look up, cast as PHP casts an array key.
128
+ * @returns Whether a key matched, and its value when one did.
129
+ *
130
+ * @example
131
+ * readMapKey(new Map([[1, "a"]]), "1"); -> { found: true, value: "a" }
132
+ * readMapKey(new Map([["01", "a"]]), 1); -> { found: false }
133
+ */
134
+ export declare function readMapKey(map: ReadonlyMap<unknown, unknown>, key: string | number): {
135
+ found: boolean;
136
+ value?: unknown;
137
+ };
138
+ /**
139
+ * Set a Map entry under the key PHP stores for the given key.
140
+ *
141
+ * An existing key keeps its place, and any later key PHP stores as the same one is removed.
142
+ *
143
+ * @param map - The Map to write into, changed in place.
144
+ * @param key - The key to write, cast as PHP casts an array key.
145
+ * @param value - The value to store.
146
+ *
147
+ * @example
148
+ * const map = new Map([[2, "c"], [0, "a"]]);
149
+ * writeMapKey(map, "2", "C"); -> map is [[2, "C"], [0, "a"]]
150
+ * writeMapKey(map, "1", "b"); -> map is [[2, "C"], [0, "a"], [1, "b"]]
151
+ */
152
+ export declare function writeMapKey(map: Map<unknown, unknown>, key: string | number, value: unknown): void;
153
+ /**
154
+ * Delete every Map entry whose key PHP stores as the given key.
155
+ *
156
+ * @param map - The Map to remove from, changed in place.
157
+ * @param key - The key to remove, cast as PHP casts an array key.
158
+ *
159
+ * @example
160
+ * const map = new Map([[1, "a"], ["1", "b"], [2, "c"]]);
161
+ * deleteMapKey(map, "1"); -> map is [[2, "c"]]
162
+ */
163
+ export declare function deleteMapKey(map: Map<unknown, unknown>, key: string | number): void;
164
+ /**
165
+ * Get the key PHP gives the next value appended to a plain object or Map.
166
+ *
167
+ * That is one past the highest integer key, negative ones included (PHP 8.3+), or 0 with none.
168
+ *
169
+ * @param container - The plain object or Map to inspect.
170
+ * @returns The next integer key.
171
+ *
172
+ * @example
173
+ * nextIntegerKey({ k: 1, 5: "z" }); -> 6
174
+ * nextIntegerKey(new Map([[2, "c"], [0, "a"]])); -> 3
175
+ * nextIntegerKey({ "-5": "n" }); -> -4
176
+ */
177
+ export declare function nextIntegerKey(container: object): number;
120
178
  /**
121
179
  * Renumber the integer-like keys in `entries` to a fresh 0-based sequence, in
122
180
  * the order they appear; string keys pass through unchanged.
@@ -144,8 +202,8 @@ export declare function renumberPhpIntegerKeys<TValue>(entries: [string, TValue]
144
202
  * reaching `Object.prototype` through the inherited setter.
145
203
  *
146
204
  * `defineKey` is the sanctioned way to write a computed key onto a fresh result object;
147
- * plain `result[key] = value` lets a `"__proto__"` key reparent `result`. A key that is
148
- * already non-configurable falls back to assignment, since it cannot be a setter.
205
+ * plain `result[key] = value` lets a `"__proto__"` key reparent `result`. A key that is already
206
+ * non-configurable keeps its attributes and only takes the new value.
149
207
  *
150
208
  * @param target - The object to define the key on
151
209
  * @param key - The key to define
@@ -1 +1 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AA0BA;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,WAAW,EACjD,KAAK,EAAE,CAAC,GACT,CAAC,SAAS,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,CAMpC;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,GAAG,MAAM,CAatE;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAkCzD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,OAAO,EACd,OAAO,GAAE;IACL,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC;CAChC,GACP,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wBAAgB,WAAW,CACvB,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,EAC1B,GAAG,EAAE,MAAM,GAAG,MAAM,EACpB,KAAK,EAAE,OAAO,GACf,IAAI,CAmBN;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CACxB,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,EAC1B,GAAG,EAAE,MAAM,GAAG,MAAM,GACrB,IAAI,CAMN;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAYxD;AA2BD;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EACrC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAC5B,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAUpB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EACzC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAC5B,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAQpB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,MAAM,GACd,IAAI,CAqBN"}
package/dist/keys.js CHANGED
@@ -1,89 +1,116 @@
1
- import { isPrototypeObject as p, isObject as f, isFunction as s, isArray as b, isString as c, isInteger as g, isMap as m, isNull as N, isUndefined as l, isBoolean as y, isNumber as a, isEnumCase as S, isTruthyObject as d, isSymbol as I } from "./guards.js";
2
- import { phpDebugType as K } from "./reflect.js";
3
- const u = 2 ** 63;
4
- function T(r) {
5
- return !isNaN(Number(r)) && !isNaN(parseFloat(String(r))) ? Number(r) : r;
1
+ import { isPrototypeObject as b, isObject as a, isFunction as s, isArray as l, isString as p, isInteger as y, isMap as d, isNull as m, isUndefined as K, isBoolean as S, isNumber as f, isEnumCase as N, isTruthyObject as h, isSymbol as I } from "./guards.js";
2
+ import { phpDebugType as O } from "./reflect.js";
3
+ const c = 2 ** 63;
4
+ function A(e) {
5
+ return !isNaN(Number(e)) && !isNaN(parseFloat(String(e))) ? Number(e) : e;
6
6
  }
7
- function A(r) {
8
- return r === "__proto__" || r === "constructor" || r === "prototype";
7
+ function B(e) {
8
+ return e === "__proto__" || e === "constructor" || e === "prototype";
9
9
  }
10
- function B(r) {
11
- return c(r) ? !0 : g(r) ? r >= -u && r < u : !1;
10
+ function C(e) {
11
+ return p(e) ? !0 : y(e) ? e >= -c && e < c : !1;
12
12
  }
13
- function O(r) {
14
- return /^(0|[1-9]\d*)$/.test(r);
13
+ function P(e) {
14
+ return /^(0|[1-9]\d*)$/.test(e);
15
15
  }
16
- function o(r) {
17
- if (c(r)) {
18
- if (/^(0|-?[1-9]\d*)$/.test(r)) {
19
- const t = Number(r);
16
+ function o(e) {
17
+ if (p(e)) {
18
+ if (/^(0|-?[1-9]\d*)$/.test(e)) {
19
+ const t = Number(e);
20
20
  if (Number.isSafeInteger(t))
21
21
  return t;
22
22
  }
23
- return r;
23
+ return e;
24
24
  }
25
- if (N(r) || l(r))
25
+ if (m(e) || K(e))
26
26
  return "";
27
- if (y(r))
28
- return r ? 1 : 0;
29
- if (a(r) || Number.isNaN(r)) {
30
- const t = Number.isFinite(r) ? BigInt.asIntN(64, BigInt(Math.trunc(r))) : 0n;
27
+ if (S(e))
28
+ return e ? 1 : 0;
29
+ if (f(e) || Number.isNaN(e)) {
30
+ const t = Number.isFinite(e) ? BigInt.asIntN(64, BigInt(Math.trunc(e))) : 0n;
31
31
  return Number.isSafeInteger(Number(t)) ? Number(t) : String(t);
32
32
  }
33
- return String(r);
33
+ return String(e);
34
34
  }
35
- function C(r, t = {}) {
36
- const { enumCases: n = !1, stringables: i = !1 } = t;
37
- let e = r;
38
- if (n && S(e) && (e = e.value), i && x(e) && (e = String(e.toString())), h(e))
39
- throw (t.invalid ?? P)(K(e));
40
- return o(e);
35
+ function D(e, t = {}) {
36
+ const { enumCases: r = !1, stringables: n = !1 } = t;
37
+ let i = e;
38
+ if (r && N(i) && (i = i.value), n && x(i) && (i = String(i.toString())), w(i))
39
+ throw (t.invalid ?? j)(O(i));
40
+ return o(i);
41
41
  }
42
- function h(r) {
43
- return b(r) || f(r) || s(r);
42
+ function w(e) {
43
+ return l(e) || a(e) || s(e);
44
44
  }
45
- function D() {
45
+ function $() {
46
46
  return new TypeError(
47
47
  "array_key_exists(): Argument #1 ($key) must be a valid array offset type"
48
48
  );
49
49
  }
50
- function x(r) {
51
- return f(r) && !(r instanceof Date) && s(r.toString) && r.toString !== Object.prototype.toString;
50
+ function x(e) {
51
+ return a(e) && !(e instanceof Date) && s(e.toString) && e.toString !== Object.prototype.toString;
52
52
  }
53
- function P(r) {
54
- return new TypeError(`Cannot access offset of type ${r} on array`);
53
+ function j(e) {
54
+ return new TypeError(`Cannot access offset of type ${e} on array`);
55
55
  }
56
- function $(r) {
57
- if (!m(r))
58
- return Object.entries(r);
56
+ function _(e) {
57
+ if (!d(e))
58
+ return Object.entries(e);
59
59
  const t = /* @__PURE__ */ new Map();
60
- for (const [n, i] of r) {
61
- const e = _(n) ? String(o(n)) : void 0;
62
- t.set(e ?? n, [e ?? String(n), i]);
60
+ for (const [r, n] of e) {
61
+ const i = g(r) ? String(o(r)) : void 0;
62
+ t.set(i ?? r, [i ?? String(r), n]);
63
63
  }
64
64
  return [...t.values()];
65
65
  }
66
- function _(r) {
67
- return !d(r) && !s(r) && !I(r);
66
+ function F(e, t) {
67
+ let r = { found: !1 };
68
+ for (const [n, i] of e)
69
+ u(n, t) && (r = { found: !0, value: i });
70
+ return r;
68
71
  }
69
- function F(r) {
72
+ function U(e, t, r) {
73
+ let n = !1;
74
+ for (const i of [...e.keys()])
75
+ u(i, t) && (n ? e.delete(i) : (e.set(i, r), n = !0));
76
+ n || e.set(o(t), r);
77
+ }
78
+ function H(e, t) {
79
+ for (const r of [...e.keys()])
80
+ u(r, t) && e.delete(r);
81
+ }
82
+ function L(e) {
83
+ let t;
84
+ for (const [r] of _(e)) {
85
+ const n = o(r);
86
+ f(n) && (t === void 0 || n > t) && (t = n);
87
+ }
88
+ return t === void 0 ? 0 : t + 1;
89
+ }
90
+ function u(e, t) {
91
+ return g(e) && String(o(e)) === String(o(t));
92
+ }
93
+ function g(e) {
94
+ return !h(e) && !s(e) && !I(e);
95
+ }
96
+ function V(e) {
70
97
  let t = 0;
71
- return r.map(([n, i]) => O(n) ? [String(t++), i] : [n, i]);
98
+ return e.map(([r, n]) => P(r) ? [String(t++), n] : [r, n]);
72
99
  }
73
- function M(r) {
100
+ function q(e) {
74
101
  let t = 0;
75
- return r.map(
76
- ([n, i]) => a(o(n)) ? [String(t++), i] : [n, i]
102
+ return e.map(
103
+ ([r, n]) => f(o(r)) ? [String(t++), n] : [r, n]
77
104
  );
78
105
  }
79
- function U(r, t, n) {
80
- if (!p(r)) {
81
- if (Object.getOwnPropertyDescriptor(r, t)?.configurable === !1) {
82
- r[t] = n;
106
+ function z(e, t, r) {
107
+ if (!b(e)) {
108
+ if (Object.getOwnPropertyDescriptor(e, t)?.configurable === !1) {
109
+ Object.defineProperty(e, t, { value: r });
83
110
  return;
84
111
  }
85
- Object.defineProperty(r, t, {
86
- value: n,
112
+ Object.defineProperty(e, t, {
113
+ value: r,
87
114
  enumerable: !0,
88
115
  writable: !0,
89
116
  configurable: !0
@@ -91,17 +118,21 @@ function U(r, t, n) {
91
118
  }
92
119
  }
93
120
  export {
94
- D as arrayKeyExistsError,
95
- U as defineKey,
96
- T as entriesKeyValue,
121
+ $ as arrayKeyExistsError,
122
+ z as defineKey,
123
+ H as deleteMapKey,
124
+ A as entriesKeyValue,
97
125
  x as hasOwnToString,
98
- h as isIllegalOffset,
99
- O as isIntegerLikeKey,
100
- B as isPhpArrayKey,
101
- A as isUnsafeKey,
102
- $ as keyedEntries,
126
+ w as isIllegalOffset,
127
+ P as isIntegerLikeKey,
128
+ C as isPhpArrayKey,
129
+ B as isUnsafeKey,
130
+ _ as keyedEntries,
131
+ L as nextIntegerKey,
103
132
  o as phpArrayKey,
104
- C as phpComputedKey,
105
- F as reindexIntegerKeys,
106
- M as renumberPhpIntegerKeys
133
+ D as phpComputedKey,
134
+ F as readMapKey,
135
+ V as reindexIntegerKeys,
136
+ q as renumberPhpIntegerKeys,
137
+ U as writeMapKey
107
138
  };
package/dist/utils.js CHANGED
@@ -1,50 +1,51 @@
1
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 S, operatorMatch as f, strictEqual as x } from "./equality.js";
3
- import { InvalidArgumentException as P, ItemNotFoundException as A, MultipleItemsFoundException as d, UnexpectedValueException as v } from "./exceptions.js";
4
- import { isAccessibleData as E, isArray as N, isBoolean as T, isEnumCase as F, isFalsy as O, isFiniteNumber as V, isFloat as C, isFunction as M, isInteger as j, isIterable as k, isMap as L, isNegativeNumber as U, isNonPrimitive as w, 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, entriesKeyValue as ue, hasOwnToString as ce, isIllegalOffset as be, isIntegerLikeKey as he, isPhpArrayKey as ge, isUnsafeKey as Se, keyedEntries as fe, phpArrayKey as xe, phpComputedKey as Ie, reindexIntegerKeys as Pe, renumberPhpIntegerKeys as Ae } from "./keys.js";
6
- import { resolvePadLength as ve, resolveRangeSize as Ke, resolveSliceRange as Ee, resolveSpliceRange as Ne, resolveTakeCount as Te } from "./range.js";
7
- import { phpDebugType as Oe, phpTypeName as Ve, resolveDefault as Ce, typeOf as Me } from "./reflect.js";
8
- import { createSortSpecComparator as ke, phpSortComparator as Le } from "./sorting.js";
9
- import { arrayValueMessage as we, lowerFirst as ze, toLower as De, toUpper as Re, upperFirst as qe } from "./string.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
- P as InvalidArgumentException,
12
- A as ItemNotFoundException,
13
- d as MultipleItemsFoundException,
14
- v as UnexpectedValueException,
11
+ K as InvalidArgumentException,
12
+ d as ItemNotFoundException,
13
+ P as MultipleItemsFoundException,
14
+ A as UnexpectedValueException,
15
15
  ye as arrayKeyExistsError,
16
- we as arrayValueMessage,
16
+ qe as arrayValueMessage,
17
17
  t as arrayableItems,
18
18
  i as arrayableValues,
19
19
  s as castableToArray,
20
20
  g as compareValues,
21
- ke as createSortSpecComparator,
21
+ ze as createSortSpecComparator,
22
22
  a as cssListItemToString,
23
23
  me as defineKey,
24
- ue as entriesKeyValue,
24
+ ue as deleteMapKey,
25
+ ce as entriesKeyValue,
25
26
  o as getAccessibleValues,
26
- ce as hasOwnToString,
27
+ be as hasOwnToString,
27
28
  E as isAccessibleData,
28
- N as isArray,
29
- T as isBoolean,
30
- F as isEnumCase,
31
- O as isFalsy,
32
- V as isFiniteNumber,
33
- C as isFloat,
34
- M as isFunction,
35
- be as isIllegalOffset,
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,
36
37
  j as isInteger,
37
- he as isIntegerLikeKey,
38
+ ge as isIntegerLikeKey,
38
39
  k as isIterable,
39
- L as isMap,
40
- U as isNegativeNumber,
41
- w as isNonPrimitive,
40
+ w as isMap,
41
+ L as isNegativeNumber,
42
+ U as isNonPrimitive,
42
43
  z as isNull,
43
44
  D as isNumber,
44
45
  R as isObject,
45
46
  q as isObjectAny,
46
47
  J as isPhpAccessible,
47
- ge as isPhpArrayKey,
48
+ xe as isPhpArrayKey,
48
49
  W as isPhpFalsy,
49
50
  B as isPhpInt,
50
51
  G as isPhpNumeric,
@@ -63,36 +64,39 @@ export {
63
64
  se as isWeakMap,
64
65
  ae as isWeakSet,
65
66
  fe as keyedEntries,
66
- S as looseEqual,
67
- ze as lowerFirst,
67
+ x as looseEqual,
68
+ Je as lowerFirst,
69
+ Ie as nextIntegerKey,
68
70
  p as normalizeToArray,
69
71
  oe as objectToString,
70
- f as operatorMatch,
71
- xe as phpArrayKey,
72
- Ie as phpComputedKey,
73
- Oe as phpDebugType,
72
+ S as operatorMatch,
73
+ Ke as phpArrayKey,
74
+ de as phpComputedKey,
75
+ je as phpDebugType,
74
76
  n as phpIntArgument,
75
77
  l as phpIntCast,
76
- Le as phpSortComparator,
78
+ De as phpSortComparator,
77
79
  y as phpStringCast,
78
- Ve as phpTypeName,
80
+ ke as phpTypeName,
79
81
  pe as phpValueMatch,
80
82
  ne as phpValueMatcher,
81
- Pe as reindexIntegerKeys,
82
- Ae as renumberPhpIntegerKeys,
83
- Ce as resolveDefault,
84
- ve as resolvePadLength,
85
- Ke as resolveRangeSize,
86
- Ee as resolveSliceRange,
87
- Ne as resolveSpliceRange,
88
- Te as resolveTakeCount,
89
- x as strictEqual,
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,
92
+ f as strictEqual,
90
93
  m as toArrayable,
91
94
  u as toJsonSerializable,
92
95
  c as toJsonable,
93
- De as toLower,
96
+ We as toLower,
94
97
  b as toPhpKeyString,
95
- Re as toUpper,
96
- Me as typeOf,
97
- qe as upperFirst
98
+ Be as toUpper,
99
+ Le as typeOf,
100
+ Ge as upperFirst,
101
+ Ee as writeMapKey
98
102
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/utils",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "A set of utility functions for the @tolki packages.",
5
5
  "author": "Abraham Arango <https://github.com/abetwothree>",
6
6
  "license": "MIT",
@@ -15,7 +15,7 @@
15
15
  "type": "module",
16
16
  "main": "dist/index.js",
17
17
  "dependencies": {
18
- "@tolki/types": "^1.8.0"
18
+ "@tolki/types": "^1.9.0"
19
19
  },
20
20
  "sideEffects": false,
21
21
  "files": [