@tolki/utils 1.2.0 → 1.3.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/guards.js CHANGED
@@ -1,116 +1,165 @@
1
- function f(n) {
2
- return Array.isArray(n);
1
+ function p(t) {
2
+ return Array.isArray(t);
3
3
  }
4
- function o(n) {
5
- return !r(n) && typeof n == "object" && !f(n);
4
+ function b(t) {
5
+ return !i(t) && typeof t == "object" && !p(t);
6
6
  }
7
- function c(n) {
8
- return typeof n == "object";
7
+ function g(t) {
8
+ return typeof t == "object";
9
9
  }
10
- function S(n) {
11
- return !r(n) && !e(n) && c(n);
10
+ function h(t) {
11
+ return !i(t) && !u(t) && g(t);
12
12
  }
13
- function i(n) {
14
- return typeof n == "string";
13
+ function I(t) {
14
+ if (!h(t) && !c(t))
15
+ return !1;
16
+ const n = Object.getOwnPropertyDescriptor(
17
+ t,
18
+ "constructor"
19
+ )?.value;
20
+ return c(n) && n.prototype === t;
15
21
  }
16
- function j(n) {
17
- return !!(i(n) || t(n) || b(n));
22
+ function o(t) {
23
+ return typeof t == "string";
18
24
  }
19
- function b(n) {
20
- return !!(o(n) && s(n.toString));
25
+ function T(t) {
26
+ return !!(o(t) || e(t) || S(t));
21
27
  }
22
- function t(n) {
23
- return typeof n == "number" && !isNaN(n);
28
+ function S(t) {
29
+ return !!(b(t) && c(t.toString));
24
30
  }
25
- function A(n) {
26
- return t(n) && Number.isInteger(n);
31
+ function e(t) {
32
+ return typeof t == "number" && !isNaN(t);
27
33
  }
28
- function k(n) {
29
- return t(n) && !Number.isInteger(n);
34
+ function W(t) {
35
+ return e(t) && Number.isInteger(t);
30
36
  }
31
- function F(n) {
32
- return t(n) && n >= 0;
37
+ function E(t) {
38
+ return e(t) && !Number.isInteger(t);
33
39
  }
34
- function d(n) {
35
- return t(n) && n < 0;
40
+ function R(t) {
41
+ return e(t) && t >= 0;
36
42
  }
37
- function u(n) {
38
- return typeof n == "boolean";
43
+ function _(t) {
44
+ return e(t) && t < 0;
39
45
  }
40
- function s(n) {
41
- return typeof n == "function";
46
+ function N(t) {
47
+ return typeof t == "boolean";
42
48
  }
43
- function e(n) {
44
- return typeof n > "u";
49
+ function c(t) {
50
+ return typeof t == "function";
45
51
  }
46
- function y(n) {
47
- return typeof n == "symbol";
52
+ function u(t) {
53
+ return typeof t > "u";
48
54
  }
49
- function r(n) {
50
- return n === null;
55
+ function d(t) {
56
+ return typeof t == "symbol";
51
57
  }
52
- function m(n) {
53
- return n instanceof Map;
58
+ function i(t) {
59
+ return t === null;
54
60
  }
55
- function N(n) {
56
- return n instanceof Set;
61
+ function P(t) {
62
+ return t instanceof Map;
57
63
  }
58
- function h(n) {
59
- return r(n) || e(n) || i(n) ? !1 : s(
60
- n[Symbol.iterator]
61
- );
62
- }
63
- function I(n) {
64
- return n instanceof WeakMap;
65
- }
66
- function M(n) {
67
- return n instanceof WeakSet;
68
- }
69
- function p(n) {
70
- return Number.isNaN(n) ? !0 : t(n) ? n === 0 : e(n) || r(n) ? !0 : u(n) ? n === !1 : i(n) ? n.trim() === "" : m(n) || N(n) ? n.size === 0 : f(n) ? n.length === 0 : o(n) ? Object.keys(n).length === 0 : !1;
64
+ function j(t) {
65
+ return t instanceof Set;
71
66
  }
72
- function O(n) {
73
- return !p(n);
74
- }
75
- function g(n) {
76
- return r(n) || u(n) || t(n) || i(n) || y(n) || e(n);
77
- }
78
- function W(n) {
79
- return !g(n);
80
- }
81
- function P(n) {
82
- return t(n) && Number.isFinite(n);
67
+ function w(t) {
68
+ return i(t) || u(t) || o(t) ? !1 : c(
69
+ t[Symbol.iterator]
70
+ );
83
71
  }
84
- function T(n) {
85
- return Array.isArray(n);
72
+ function z(t) {
73
+ return t instanceof WeakMap;
74
+ }
75
+ function B(t) {
76
+ return t instanceof WeakSet;
77
+ }
78
+ function A(t) {
79
+ return Number.isNaN(t) ? !0 : e(t) ? t === 0 : u(t) || i(t) ? !0 : N(t) ? t === !1 : o(t) ? t.trim() === "" : P(t) || j(t) ? t.size === 0 : p(t) ? t.length === 0 : b(t) ? Object.keys(t).length === 0 : !1;
80
+ }
81
+ function D(t) {
82
+ return !A(t);
83
+ }
84
+ function U(t) {
85
+ return t === !1 || t === null || u(t) || t === 0 || t === "" || t === "0" ? !0 : p(t) ? t.length === 0 : b(t) ? Object.keys(t).length === 0 : !1;
86
+ }
87
+ const k = /^[ \t\n\r\v\f]*[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?[ \t\n\r\v\f]*$/;
88
+ function V(t) {
89
+ return typeof t == "number" ? !0 : o(t) ? k.test(t) : !1;
90
+ }
91
+ function O(t) {
92
+ return i(t) || N(t) || e(t) || o(t) || d(t) || u(t);
93
+ }
94
+ function x(t) {
95
+ return !O(t);
96
+ }
97
+ function M(t) {
98
+ return e(t) && Number.isFinite(t);
99
+ }
100
+ function C(t) {
101
+ return Array.isArray(t);
102
+ }
103
+ function y(t) {
104
+ if (o(t))
105
+ return t;
106
+ if (N(t))
107
+ return t ? "1" : "";
108
+ if (i(t))
109
+ return "";
110
+ if (M(t)) {
111
+ const n = String(t);
112
+ return n.includes("e") ? null : n;
113
+ }
114
+ return null;
115
+ }
116
+ function F(t, n) {
117
+ const f = y(t), r = y(n);
118
+ return f !== null && r !== null ? f === r : t === n || typeof t == "number" && typeof n == "number" && Number.isNaN(t) && Number.isNaN(n);
119
+ }
120
+ function G(t) {
121
+ const n = /* @__PURE__ */ new Set(), f = [];
122
+ for (const r of t) {
123
+ const s = y(r);
124
+ i(s) ? f.push(r) : n.add(s);
125
+ }
126
+ return (r) => {
127
+ const s = y(r);
128
+ return i(s) ? f.some((m) => F(r, m)) : n.has(s);
129
+ };
86
130
  }
87
131
  export {
88
- T as isAccessibleData,
89
- f as isArray,
90
- u as isBoolean,
91
- p as isFalsy,
92
- P as isFiniteNumber,
93
- k as isFloat,
94
- s as isFunction,
95
- A as isInteger,
96
- h as isIterable,
97
- m as isMap,
98
- d as isNegativeNumber,
99
- W as isNonPrimitive,
100
- r as isNull,
101
- t as isNumber,
102
- o as isObject,
103
- c as isObjectAny,
104
- F as isPositiveNumber,
105
- g as isPrimitive,
106
- N as isSet,
107
- i as isString,
108
- j as isStringable,
109
- y as isSymbol,
110
- O as isTruthy,
111
- S as isTruthyObject,
112
- e as isUndefined,
113
- I as isWeakMap,
114
- M as isWeakSet,
115
- b as objectToString
132
+ C as isAccessibleData,
133
+ p as isArray,
134
+ N as isBoolean,
135
+ A as isFalsy,
136
+ M as isFiniteNumber,
137
+ E as isFloat,
138
+ c as isFunction,
139
+ W as isInteger,
140
+ w as isIterable,
141
+ P as isMap,
142
+ _ as isNegativeNumber,
143
+ x as isNonPrimitive,
144
+ i as isNull,
145
+ e as isNumber,
146
+ b as isObject,
147
+ g as isObjectAny,
148
+ U as isPhpFalsy,
149
+ V as isPhpNumeric,
150
+ R as isPositiveNumber,
151
+ O as isPrimitive,
152
+ I as isPrototypeObject,
153
+ j as isSet,
154
+ o as isString,
155
+ T as isStringable,
156
+ d as isSymbol,
157
+ D as isTruthy,
158
+ h as isTruthyObject,
159
+ u as isUndefined,
160
+ z as isWeakMap,
161
+ B as isWeakSet,
162
+ S as objectToString,
163
+ F as phpValueMatch,
164
+ G as phpValueMatcher
116
165
  };
package/dist/index.js CHANGED
@@ -1,55 +1,70 @@
1
- import { castableToArray as r, getAccessibleValues as s, normalizeToArray as t, toArrayable as o, toJsonSerializable as a, toJsonable as l } from "./cast.js";
2
- import { compareValues as b, looseEqual as m, strictEqual as p } from "./equality.js";
3
- import { isAccessibleData as y, isArray as c, isBoolean as f, isFalsy as A, isFiniteNumber as N, isFloat as S, isFunction as g, isInteger as x, isIterable as F, isMap as v, isNegativeNumber as T, isNonPrimitive as j, isNull as K, isNumber as O, isObject as P, isObjectAny as d, isPositiveNumber as h, isPrimitive as U, isSet as V, isString as k, isStringable as q, isSymbol as w, isTruthy as z, isTruthyObject as D, isUndefined as E, isWeakMap as I, isWeakSet as J, objectToString as M } from "./guards.js";
4
- import { defineKey as B, entriesKeyValue as L, isPhpArrayKey as C, isUnsafeKey as G } from "./keys.js";
5
- import { resolveDefault as Q, typeOf as R } from "./reflect.js";
6
- import { lowerFirst as Y, toLower as Z, toUpper as _, upperFirst as $ } from "./string.js";
1
+ import { arrayableValues as i, castableToArray as s, cssListItemToString as t, getAccessibleValues as a, normalizeToArray as o, toArrayable as l, toJsonSerializable as p, toJsonable as n } from "./cast.js";
2
+ import { compareValues as m, looseEqual as c, strictEqual as u } from "./equality.js";
3
+ import { isAccessibleData as f, isArray as g, isBoolean as S, isFalsy as h, isFiniteNumber as x, isFloat as N, isFunction as A, isInteger as F, isIterable as P, isMap as T, isNegativeNumber as V, isNonPrimitive as v, isNull as K, isNumber as j, isObject as I, isObjectAny as M, isPhpFalsy as O, isPhpNumeric as d, isPositiveNumber as k, isPrimitive as L, isPrototypeObject as U, isSet as q, isString as w, isStringable as z, isSymbol as D, isTruthy as E, isTruthyObject as J, isUndefined as W, isWeakMap as B, isWeakSet as C, objectToString as R, phpValueMatch as G, phpValueMatcher as H } from "./guards.js";
4
+ import { defineKey as X, entriesKeyValue as Y, isIntegerLikeKey as Z, isPhpArrayKey as _, isUnsafeKey as $, reindexIntegerKeys as ee } from "./keys.js";
5
+ import { resolveSliceRange as ie } from "./range.js";
6
+ import { phpTypeName as te, resolveDefault as ae, typeOf as oe } from "./reflect.js";
7
+ import { createSortSpecComparator as pe } from "./sorting.js";
8
+ import { arrayValueMessage as ye, lowerFirst as me, toLower as ce, toUpper as ue, upperFirst as be } from "./string.js";
7
9
  export {
8
- r as castableToArray,
9
- b as compareValues,
10
- B as defineKey,
11
- L as entriesKeyValue,
12
- s as getAccessibleValues,
13
- y as isAccessibleData,
14
- c as isArray,
15
- f as isBoolean,
16
- A as isFalsy,
17
- N as isFiniteNumber,
18
- S as isFloat,
19
- g as isFunction,
20
- x as isInteger,
21
- F as isIterable,
22
- v as isMap,
23
- T as isNegativeNumber,
24
- j as isNonPrimitive,
10
+ ye as arrayValueMessage,
11
+ i as arrayableValues,
12
+ s as castableToArray,
13
+ m as compareValues,
14
+ pe as createSortSpecComparator,
15
+ t as cssListItemToString,
16
+ X as defineKey,
17
+ Y as entriesKeyValue,
18
+ a as getAccessibleValues,
19
+ f as isAccessibleData,
20
+ g as isArray,
21
+ S as isBoolean,
22
+ h as isFalsy,
23
+ x as isFiniteNumber,
24
+ N as isFloat,
25
+ A as isFunction,
26
+ F as isInteger,
27
+ Z as isIntegerLikeKey,
28
+ P as isIterable,
29
+ T as isMap,
30
+ V as isNegativeNumber,
31
+ v as isNonPrimitive,
25
32
  K as isNull,
26
- O as isNumber,
27
- P as isObject,
28
- d as isObjectAny,
29
- C as isPhpArrayKey,
30
- h as isPositiveNumber,
31
- U as isPrimitive,
32
- V as isSet,
33
- k as isString,
34
- q as isStringable,
35
- w as isSymbol,
36
- z as isTruthy,
37
- D as isTruthyObject,
38
- E as isUndefined,
39
- G as isUnsafeKey,
40
- I as isWeakMap,
41
- J as isWeakSet,
42
- m as looseEqual,
43
- Y as lowerFirst,
44
- t as normalizeToArray,
45
- M as objectToString,
46
- Q as resolveDefault,
47
- p as strictEqual,
48
- o as toArrayable,
49
- a as toJsonSerializable,
50
- l as toJsonable,
51
- Z as toLower,
52
- _ as toUpper,
53
- R as typeOf,
54
- $ as upperFirst
33
+ j as isNumber,
34
+ I as isObject,
35
+ M as isObjectAny,
36
+ _ as isPhpArrayKey,
37
+ O as isPhpFalsy,
38
+ d as isPhpNumeric,
39
+ k as isPositiveNumber,
40
+ L as isPrimitive,
41
+ U as isPrototypeObject,
42
+ q as isSet,
43
+ w as isString,
44
+ z as isStringable,
45
+ D as isSymbol,
46
+ E as isTruthy,
47
+ J as isTruthyObject,
48
+ W as isUndefined,
49
+ $ as isUnsafeKey,
50
+ B as isWeakMap,
51
+ C as isWeakSet,
52
+ c as looseEqual,
53
+ me as lowerFirst,
54
+ o as normalizeToArray,
55
+ R as objectToString,
56
+ te as phpTypeName,
57
+ G as phpValueMatch,
58
+ H as phpValueMatcher,
59
+ ee as reindexIntegerKeys,
60
+ ae as resolveDefault,
61
+ ie as resolveSliceRange,
62
+ u as strictEqual,
63
+ l as toArrayable,
64
+ p as toJsonSerializable,
65
+ n as toJsonable,
66
+ ce as toLower,
67
+ ue as toUpper,
68
+ oe as typeOf,
69
+ be as upperFirst
55
70
  };
package/dist/keys.d.ts CHANGED
@@ -23,14 +23,40 @@ export declare function isUnsafeKey(key: string): boolean;
23
23
  * @returns True if the value can be used as a PHP array key
24
24
  */
25
25
  export declare function isPhpArrayKey(value: unknown): value is string | number;
26
+ /**
27
+ * Whether `key` is a canonical non-negative integer string ("0", "1", "23",
28
+ * but not "01", "-1", "1.5") — the key class JS always sorts ahead of string
29
+ * keys, and PHP treats as an integer array key.
30
+ *
31
+ * @param key - The key to test
32
+ * @returns True if `key` is a canonical non-negative integer string
33
+ */
34
+ export declare function isIntegerLikeKey(key: string): boolean;
35
+ /**
36
+ * Renumber the integer-like keys in `entries` to a fresh 0-based sequence, in
37
+ * the order they appear; string keys pass through unchanged.
38
+ *
39
+ * The one integer-key policy for every reordering helper, since a plain JS
40
+ * object always re-sorts integer-like keys ascending (ECMA-262). Negative keys
41
+ * are excluded — JS doesn't re-sort those. A mixed object keeps neither order:
42
+ * integer keys hoist ahead of string keys, so `sort({x: 5, 0: 9})` gives `[9, 5]`.
43
+ *
44
+ * @param entries - The entries to renumber, in their intended order
45
+ * @returns The same entries with integer-like keys renumbered from 0
46
+ */
47
+ export declare function reindexIntegerKeys<TValue>(entries: [string, TValue][]): [string, TValue][];
26
48
  /**
27
49
  * Define an own enumerable property on the target without going through a
28
50
  * setter, so a key such as `__proto__` becomes a real own key rather than
29
51
  * reaching `Object.prototype` through the inherited setter.
30
52
  *
53
+ * `defineKey` is the sanctioned way to write a computed key onto a fresh result object;
54
+ * plain `result[key] = value` lets a `"__proto__"` key reparent `result`. A key that is
55
+ * already non-configurable falls back to assignment, since it cannot be a setter.
56
+ *
31
57
  * @param target - The object to define the key on
32
58
  * @param key - The key to define
33
59
  * @param value - The value to store under the key
34
60
  */
35
- export declare function defineKey<TValue>(target: Record<string, TValue>, key: string, value: TValue): void;
61
+ export declare function defineKey<TValue>(target: Record<string, TValue>, key: PropertyKey, value: TValue): void;
36
62
  //# sourceMappingURL=keys.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAUA;;;;;GAKG;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;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACd,IAAI,CAON"}
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAUA;;;;;GAKG;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;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EACrC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAC5B,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAUpB;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,CAsBN"}
package/dist/keys.js CHANGED
@@ -1,25 +1,40 @@
1
- import { isString as i, isInteger as o } from "./guards.js";
2
- const t = 2 ** 63;
3
- function f(r) {
1
+ import { isPrototypeObject as o, isString as u, isInteger as f } from "./guards.js";
2
+ const i = 2 ** 63;
3
+ function p(r) {
4
4
  return !isNaN(Number(r)) && !isNaN(parseFloat(String(r))) ? Number(r) : r;
5
5
  }
6
- function s(r) {
6
+ function b(r) {
7
7
  return r === "__proto__" || r === "constructor" || r === "prototype";
8
8
  }
9
- function c(r) {
10
- return i(r) ? !0 : o(r) ? r >= -t && r < t : !1;
9
+ function N(r) {
10
+ return u(r) ? !0 : f(r) ? r >= -i && r < i : !1;
11
+ }
12
+ function s(r) {
13
+ return /^(0|[1-9]\d*)$/.test(r);
14
+ }
15
+ function g(r) {
16
+ let e = 0;
17
+ return r.map(([t, n]) => s(t) ? [String(e++), n] : [t, n]);
11
18
  }
12
- function p(r, e, n) {
13
- Object.defineProperty(r, e, {
14
- value: n,
15
- enumerable: !0,
16
- writable: !0,
17
- configurable: !0
18
- });
19
+ function m(r, e, t) {
20
+ if (!o(r)) {
21
+ if (Object.getOwnPropertyDescriptor(r, e)?.configurable === !1) {
22
+ r[e] = t;
23
+ return;
24
+ }
25
+ Object.defineProperty(r, e, {
26
+ value: t,
27
+ enumerable: !0,
28
+ writable: !0,
29
+ configurable: !0
30
+ });
31
+ }
19
32
  }
20
33
  export {
21
- p as defineKey,
22
- f as entriesKeyValue,
23
- c as isPhpArrayKey,
24
- s as isUnsafeKey
34
+ m as defineKey,
35
+ p as entriesKeyValue,
36
+ s as isIntegerLikeKey,
37
+ N as isPhpArrayKey,
38
+ b as isUnsafeKey,
39
+ g as reindexIntegerKeys
25
40
  };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The half-open `[start, end)` window `array_slice($items, $offset, $length)`
3
+ * selects, expressed for `Array.prototype.slice`.
4
+ */
5
+ export type SliceRange = {
6
+ start: number;
7
+ end: number | undefined;
8
+ };
9
+ /**
10
+ * Resolve `array_slice`'s offset/length pair into a slice window.
11
+ *
12
+ * A negative offset is normalised against the item count BEFORE it is
13
+ * combined with the length, matching `array_slice` — a raw negative offset
14
+ * fed straight into `Array.prototype.slice` combines the two differently.
15
+ *
16
+ * @param count - The number of items being sliced.
17
+ * @param offset - The starting index, negative to count back from the end.
18
+ * @param length - How many items to take, negative to stop that many from
19
+ * the end, or `null` to run to the end.
20
+ * @returns The `start` and `end` bounds to slice with.
21
+ */
22
+ export declare function resolveSliceRange(count: number, offset: number, length: number | null): SliceRange;
23
+ //# sourceMappingURL=range.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../src/range.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEpE;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAC7B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GAAG,IAAI,GACtB,UAAU,CASZ"}
package/dist/range.js ADDED
@@ -0,0 +1,8 @@
1
+ import { isNull as t } from "./guards.js";
2
+ function n(o, a, r) {
3
+ const i = a < 0 ? Math.max(o + a, 0) : a, m = t(r) ? void 0 : r >= 0 ? i + r : Math.max(i, o + r);
4
+ return { start: i, end: m };
5
+ }
6
+ export {
7
+ n as resolveSliceRange
8
+ };
package/dist/reflect.d.ts CHANGED
@@ -23,4 +23,11 @@ export declare function typeOf(v: unknown): string;
23
23
  * resolveDefault(undefined); -> null
24
24
  */
25
25
  export declare function resolveDefault<D>(defaultValue?: D | (() => D)): D | null;
26
+ /**
27
+ * Render a value's type the way PHP's gettype() does, for Arr::array()-style messages.
28
+ *
29
+ * @param value - The value whose type name is needed.
30
+ * @returns The PHP type name ("NULL", "integer", "double", or the JS typeof otherwise).
31
+ */
32
+ export declare function phpTypeName(value: unknown): string;
26
33
  //# sourceMappingURL=reflect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reflect.d.ts","sourceRoot":"","sources":["../src/reflect.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CASzC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAOxE"}
1
+ {"version":3,"file":"reflect.d.ts","sourceRoot":"","sources":["../src/reflect.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CASzC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAOxE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA6BlD"}
package/dist/reflect.js CHANGED
@@ -1,11 +1,15 @@
1
- import { isNull as n, isArray as t } from "./guards.js";
2
- function i(r) {
3
- return n(r) ? "object" : t(r) ? "array" : typeof r;
1
+ import { isNull as n, isNumber as t, isInteger as e, isArray as i, isFunction as f, isUndefined as o } from "./guards.js";
2
+ function p(r) {
3
+ return n(r) ? "object" : i(r) ? "array" : typeof r;
4
4
  }
5
- function f(r) {
5
+ function s(r) {
6
6
  return r === void 0 ? null : typeof r == "function" ? r() : r;
7
7
  }
8
+ function y(r) {
9
+ return n(r) ? "NULL" : t(r) ? e(r) ? "integer" : "double" : i(r) ? "array" : Number.isNaN(r) ? "double" : f(r) ? "object" : o(r) ? "NULL" : typeof r;
10
+ }
8
11
  export {
9
- f as resolveDefault,
10
- i as typeOf
12
+ y as phpTypeName,
13
+ s as resolveDefault,
14
+ p as typeOf
11
15
  };
@@ -0,0 +1,20 @@
1
+ import { PathKey, SortSpec } from '@tolki/types';
2
+ /**
3
+ * Reads the value a sort descriptor's key names on one item.
4
+ *
5
+ * @param item - The item being sorted.
6
+ * @param key - The descriptor's key path.
7
+ * @returns The value to compare.
8
+ */
9
+ export type SortValueResolver = (item: unknown, key: PathKey) => unknown;
10
+ /**
11
+ * Build the sort-descriptor comparator factory for one path resolver.
12
+ *
13
+ * `@tolki/utils` sits below every path package, so the caller supplies the
14
+ * resolver: `getNestedValue` for `Arr`/`Obj`, `dataGet` for `Collection`.
15
+ *
16
+ * @param resolve - Reads a descriptor's key off an item.
17
+ * @returns A function building the comparator one sort descriptor implies.
18
+ */
19
+ export declare function createSortSpecComparator(resolve: SortValueResolver): <TValue>(spec: SortSpec<TValue>, forceDescending: boolean) => (a: TValue, b: TValue) => number;
20
+ //# sourceMappingURL=sorting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sorting.d.ts","sourceRoot":"","sources":["../src/sorting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAKtD;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;AAEzE;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,iBAAiB,IAC5B,MAAM,EACrC,MAAM,QAAQ,CAAC,MAAM,CAAC,EACtB,iBAAiB,OAAO,KACzB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAkCtC"}
@@ -0,0 +1,18 @@
1
+ import { compareValues as f } from "./equality.js";
2
+ import { isFunction as e, isArray as a, isUndefined as g } from "./guards.js";
3
+ function y(o) {
4
+ return function(r, c) {
5
+ if (e(r))
6
+ return r;
7
+ if (a(r) && e(r[0]))
8
+ return r[0];
9
+ const [t, n] = a(r) ? r : [r, void 0], u = g(n) || n === !0 || n === "asc" || n === "Ascending", m = c || !u;
10
+ return (s, d) => {
11
+ const i = f(o(s, t), o(d, t));
12
+ return m ? -i : i;
13
+ };
14
+ };
15
+ }
16
+ export {
17
+ y as createSortSpecComparator
18
+ };
package/dist/string.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { PathKey } from '@tolki/types';
1
2
  /**
2
3
  * Convert a string to lower-case.
3
4
  */
@@ -14,4 +15,13 @@ export declare function lowerFirst(value: string): string;
14
15
  * Convert the first character of a string to upper-case.
15
16
  */
16
17
  export declare function upperFirst(value: string): string;
18
+ /**
19
+ * Build Arr::array()'s exact "must be an array" message, shared by every
20
+ * push/array guard so arr, obj, and the path leaf-check agree on one string.
21
+ *
22
+ * @param value - The resolved value that failed the array check.
23
+ * @param key - The key or path used in the error message.
24
+ * @returns The formatted error message.
25
+ */
26
+ export declare function arrayValueMessage(value: unknown, key: PathKey): string;
17
27
  //# sourceMappingURL=string.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUhD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUhD"}
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUhD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUhD;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,CAEtE"}