@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/cast.d.ts +23 -0
- package/dist/cast.d.ts.map +1 -1
- package/dist/cast.js +36 -20
- package/dist/equality.d.ts +16 -8
- package/dist/equality.d.ts.map +1 -1
- package/dist/equality.js +120 -48
- package/dist/guards.d.ts +76 -0
- package/dist/guards.d.ts.map +1 -1
- package/dist/guards.js +141 -92
- package/dist/index.js +67 -52
- package/dist/keys.d.ts +27 -1
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +32 -17
- package/dist/range.d.ts +23 -0
- package/dist/range.d.ts.map +1 -0
- package/dist/range.js +8 -0
- package/dist/reflect.d.ts +7 -0
- package/dist/reflect.d.ts.map +1 -1
- package/dist/reflect.js +10 -6
- package/dist/sorting.d.ts +20 -0
- package/dist/sorting.d.ts.map +1 -0
- package/dist/sorting.js +18 -0
- package/dist/string.d.ts +10 -0
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +15 -10
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +67 -52
- package/package.json +2 -2
package/dist/guards.js
CHANGED
|
@@ -1,116 +1,165 @@
|
|
|
1
|
-
function
|
|
2
|
-
return Array.isArray(
|
|
1
|
+
function p(t) {
|
|
2
|
+
return Array.isArray(t);
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
return !
|
|
4
|
+
function b(t) {
|
|
5
|
+
return !i(t) && typeof t == "object" && !p(t);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
return typeof
|
|
7
|
+
function g(t) {
|
|
8
|
+
return typeof t == "object";
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
return !
|
|
10
|
+
function h(t) {
|
|
11
|
+
return !i(t) && !u(t) && g(t);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
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
|
|
17
|
-
return
|
|
22
|
+
function o(t) {
|
|
23
|
+
return typeof t == "string";
|
|
18
24
|
}
|
|
19
|
-
function
|
|
20
|
-
return !!(o(
|
|
25
|
+
function T(t) {
|
|
26
|
+
return !!(o(t) || e(t) || S(t));
|
|
21
27
|
}
|
|
22
|
-
function t
|
|
23
|
-
return
|
|
28
|
+
function S(t) {
|
|
29
|
+
return !!(b(t) && c(t.toString));
|
|
24
30
|
}
|
|
25
|
-
function
|
|
26
|
-
return t
|
|
31
|
+
function e(t) {
|
|
32
|
+
return typeof t == "number" && !isNaN(t);
|
|
27
33
|
}
|
|
28
|
-
function
|
|
29
|
-
return t
|
|
34
|
+
function W(t) {
|
|
35
|
+
return e(t) && Number.isInteger(t);
|
|
30
36
|
}
|
|
31
|
-
function
|
|
32
|
-
return t
|
|
37
|
+
function E(t) {
|
|
38
|
+
return e(t) && !Number.isInteger(t);
|
|
33
39
|
}
|
|
34
|
-
function
|
|
35
|
-
return t
|
|
40
|
+
function R(t) {
|
|
41
|
+
return e(t) && t >= 0;
|
|
36
42
|
}
|
|
37
|
-
function
|
|
38
|
-
return
|
|
43
|
+
function _(t) {
|
|
44
|
+
return e(t) && t < 0;
|
|
39
45
|
}
|
|
40
|
-
function
|
|
41
|
-
return typeof
|
|
46
|
+
function N(t) {
|
|
47
|
+
return typeof t == "boolean";
|
|
42
48
|
}
|
|
43
|
-
function
|
|
44
|
-
return typeof
|
|
49
|
+
function c(t) {
|
|
50
|
+
return typeof t == "function";
|
|
45
51
|
}
|
|
46
|
-
function
|
|
47
|
-
return typeof
|
|
52
|
+
function u(t) {
|
|
53
|
+
return typeof t > "u";
|
|
48
54
|
}
|
|
49
|
-
function
|
|
50
|
-
return
|
|
55
|
+
function d(t) {
|
|
56
|
+
return typeof t == "symbol";
|
|
51
57
|
}
|
|
52
|
-
function
|
|
53
|
-
return
|
|
58
|
+
function i(t) {
|
|
59
|
+
return t === null;
|
|
54
60
|
}
|
|
55
|
-
function
|
|
56
|
-
return
|
|
61
|
+
function P(t) {
|
|
62
|
+
return t instanceof Map;
|
|
57
63
|
}
|
|
58
|
-
function
|
|
59
|
-
return
|
|
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
|
|
73
|
-
return !
|
|
74
|
-
|
|
75
|
-
|
|
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
|
|
85
|
-
return
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
|
2
|
-
import { compareValues as
|
|
3
|
-
import { isAccessibleData as
|
|
4
|
-
import { defineKey as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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:
|
|
61
|
+
export declare function defineKey<TValue>(target: Record<string, TValue>, key: PropertyKey, value: TValue): void;
|
|
36
62
|
//# sourceMappingURL=keys.d.ts.map
|
package/dist/keys.d.ts.map
CHANGED
|
@@ -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
|
|
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
|
|
2
|
-
const
|
|
3
|
-
function
|
|
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
|
|
6
|
+
function b(r) {
|
|
7
7
|
return r === "__proto__" || r === "constructor" || r === "prototype";
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
return
|
|
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
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
};
|
package/dist/range.d.ts
ADDED
|
@@ -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
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
|
package/dist/reflect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reflect.d.ts","sourceRoot":"","sources":["../src/reflect.ts"],"names":[],"mappings":"
|
|
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,
|
|
2
|
-
function
|
|
3
|
-
return n(r) ? "object" :
|
|
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
|
|
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
|
-
|
|
10
|
-
|
|
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"}
|
package/dist/sorting.js
ADDED
|
@@ -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
|
package/dist/string.d.ts.map
CHANGED
|
@@ -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"}
|