@tolki/utils 1.1.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 +106 -0
- package/dist/cast.d.ts.map +1 -0
- package/dist/cast.js +46 -0
- package/dist/equality.d.ts +59 -0
- package/dist/equality.d.ts.map +1 -0
- package/dist/equality.js +147 -0
- package/dist/guards.d.ts +429 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/guards.js +165 -0
- package/dist/index.js +66 -44
- package/dist/keys.d.ts +62 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +40 -0
- 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 +33 -0
- package/dist/reflect.d.ts.map +1 -0
- package/dist/reflect.js +15 -0
- 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 +27 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js +25 -0
- package/dist/utils.d.ts +8 -540
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +64 -244
- package/package.json +2 -2
package/dist/utils.js
CHANGED
|
@@ -1,250 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
function J(r) {
|
|
11
|
-
return !o(r) && !p(r) && h(r);
|
|
12
|
-
}
|
|
13
|
-
function A(r) {
|
|
14
|
-
return typeof r == "string";
|
|
15
|
-
}
|
|
16
|
-
function d(r) {
|
|
17
|
-
return r.toLowerCase();
|
|
18
|
-
}
|
|
19
|
-
function z(r) {
|
|
20
|
-
return r.toUpperCase();
|
|
21
|
-
}
|
|
22
|
-
function T(r) {
|
|
23
|
-
const t = [...r];
|
|
24
|
-
return t.length === 0 ? r : (t[0] = t[0].toLowerCase(), t.join(""));
|
|
25
|
-
}
|
|
26
|
-
function B(r) {
|
|
27
|
-
const t = [...r];
|
|
28
|
-
return t.length === 0 ? r : (t[0] = t[0].toUpperCase(), t.join(""));
|
|
29
|
-
}
|
|
30
|
-
function P(r) {
|
|
31
|
-
return !!(A(r) || f(r) || j(r));
|
|
32
|
-
}
|
|
33
|
-
function j(r) {
|
|
34
|
-
return !!(y(r) && c(r.toString));
|
|
35
|
-
}
|
|
36
|
-
function f(r) {
|
|
37
|
-
return typeof r == "number" && !isNaN(r);
|
|
38
|
-
}
|
|
39
|
-
function U(r) {
|
|
40
|
-
return f(r) && Number.isInteger(r);
|
|
41
|
-
}
|
|
42
|
-
function w(r) {
|
|
43
|
-
return f(r) && !Number.isInteger(r);
|
|
44
|
-
}
|
|
45
|
-
function C(r) {
|
|
46
|
-
return f(r) && r >= 0;
|
|
47
|
-
}
|
|
48
|
-
function I(r) {
|
|
49
|
-
return f(r) && r < 0;
|
|
50
|
-
}
|
|
51
|
-
function N(r) {
|
|
52
|
-
return typeof r == "boolean";
|
|
53
|
-
}
|
|
54
|
-
function c(r) {
|
|
55
|
-
return typeof r == "function";
|
|
56
|
-
}
|
|
57
|
-
function p(r) {
|
|
58
|
-
return typeof r > "u";
|
|
59
|
-
}
|
|
60
|
-
function m(r) {
|
|
61
|
-
return typeof r == "symbol";
|
|
62
|
-
}
|
|
63
|
-
function o(r) {
|
|
64
|
-
return r === null;
|
|
65
|
-
}
|
|
66
|
-
function S(r) {
|
|
67
|
-
return r instanceof Map;
|
|
68
|
-
}
|
|
69
|
-
function b(r) {
|
|
70
|
-
return r instanceof Set;
|
|
71
|
-
}
|
|
72
|
-
function M(r) {
|
|
73
|
-
return o(r) || p(r) || A(r) ? !1 : c(
|
|
74
|
-
r[Symbol.iterator]
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
function W(r) {
|
|
78
|
-
return r instanceof WeakMap;
|
|
79
|
-
}
|
|
80
|
-
function _(r) {
|
|
81
|
-
return r instanceof WeakSet;
|
|
82
|
-
}
|
|
83
|
-
function L(r) {
|
|
84
|
-
return y(r) && !o(r) && c(r.toArray);
|
|
85
|
-
}
|
|
86
|
-
function q(r) {
|
|
87
|
-
if (!y(r) || o(r))
|
|
88
|
-
return !1;
|
|
89
|
-
const t = c(r.toJson), e = c(r.toJSON);
|
|
90
|
-
return t || e;
|
|
91
|
-
}
|
|
92
|
-
function D(r) {
|
|
93
|
-
return y(r) && !o(r) && c(r.jsonSerialize);
|
|
94
|
-
}
|
|
95
|
-
function O(r) {
|
|
96
|
-
return Number.isNaN(r) ? !0 : f(r) ? r === 0 : p(r) || o(r) ? !0 : N(r) ? r === !1 : A(r) ? r.trim() === "" : S(r) || b(r) ? r.size === 0 : l(r) ? r.length === 0 : y(r) ? Object.keys(r).length === 0 : !1;
|
|
97
|
-
}
|
|
98
|
-
function E(r) {
|
|
99
|
-
return !O(r);
|
|
100
|
-
}
|
|
101
|
-
function K(r) {
|
|
102
|
-
return o(r) ? "object" : l(r) ? "array" : typeof r;
|
|
103
|
-
}
|
|
104
|
-
function k(r) {
|
|
105
|
-
return o(r) || N(r) || f(r) || A(r) || m(r) || p(r);
|
|
106
|
-
}
|
|
107
|
-
function V(r) {
|
|
108
|
-
return !k(r);
|
|
109
|
-
}
|
|
110
|
-
function x(r) {
|
|
111
|
-
return f(r) && Number.isFinite(r);
|
|
112
|
-
}
|
|
113
|
-
function G(r) {
|
|
114
|
-
return l(r) ? r : null;
|
|
115
|
-
}
|
|
116
|
-
function H(r, t) {
|
|
117
|
-
if (r == null && t == null) return 0;
|
|
118
|
-
if (r == null) return -1;
|
|
119
|
-
if (t == null) return 1;
|
|
120
|
-
if (typeof r == "object" && typeof t == "object") {
|
|
121
|
-
const e = JSON.stringify(r), u = JSON.stringify(t);
|
|
122
|
-
return e < u ? -1 : e > u ? 1 : 0;
|
|
123
|
-
}
|
|
124
|
-
return r < t ? -1 : r > t ? 1 : 0;
|
|
125
|
-
}
|
|
126
|
-
function Q(r) {
|
|
127
|
-
return r === void 0 ? null : typeof r == "function" ? r() : r;
|
|
128
|
-
}
|
|
129
|
-
function F(r) {
|
|
130
|
-
return Array.isArray(r) ? r.slice() : null;
|
|
131
|
-
}
|
|
132
|
-
function R(r) {
|
|
133
|
-
return Array.isArray(r);
|
|
134
|
-
}
|
|
135
|
-
function X(r) {
|
|
136
|
-
return F(r) || [];
|
|
137
|
-
}
|
|
138
|
-
function g(r, t) {
|
|
139
|
-
if (r == t)
|
|
140
|
-
return !0;
|
|
141
|
-
if (typeof r == "boolean" || typeof t == "boolean") {
|
|
142
|
-
const i = typeof r == "boolean" ? r : t, n = typeof r == "boolean" ? t : r;
|
|
143
|
-
return i === !0 ? !(n === null || n === !1 || n === 0 || n === "" || Array.isArray(n) && n.length === 0) : n === null || n === 0 || n === "";
|
|
144
|
-
}
|
|
145
|
-
const e = r === null || r === !1 || r === 0 || r === "" || Array.isArray(r) && r.length === 0, u = t === null || t === !1 || t === 0 || t === "" || Array.isArray(t) && t.length === 0;
|
|
146
|
-
if (e && u)
|
|
147
|
-
return !0;
|
|
148
|
-
if (Array.isArray(r) && Array.isArray(t)) {
|
|
149
|
-
if (r.length !== t.length)
|
|
150
|
-
return !1;
|
|
151
|
-
for (let i = 0; i < r.length; i++)
|
|
152
|
-
if (!g(r[i], t[i]))
|
|
153
|
-
return !1;
|
|
154
|
-
return !0;
|
|
155
|
-
}
|
|
156
|
-
if (r !== null && t !== null && typeof r == "object" && typeof t == "object" && !Array.isArray(r) && !Array.isArray(t)) {
|
|
157
|
-
const i = Object.keys(r), n = Object.keys(t);
|
|
158
|
-
if (i.length !== n.length)
|
|
159
|
-
return !1;
|
|
160
|
-
for (const s of i)
|
|
161
|
-
if (!n.includes(s) || !g(
|
|
162
|
-
r[s],
|
|
163
|
-
t[s]
|
|
164
|
-
))
|
|
165
|
-
return !1;
|
|
166
|
-
return !0;
|
|
167
|
-
}
|
|
168
|
-
return !1;
|
|
169
|
-
}
|
|
170
|
-
function a(r, t) {
|
|
171
|
-
if (r === t)
|
|
172
|
-
return !0;
|
|
173
|
-
if (Array.isArray(r) && Array.isArray(t)) {
|
|
174
|
-
if (r.length !== t.length)
|
|
175
|
-
return !1;
|
|
176
|
-
for (let e = 0; e < r.length; e++)
|
|
177
|
-
if (!a(r[e], t[e]))
|
|
178
|
-
return !1;
|
|
179
|
-
return !0;
|
|
180
|
-
}
|
|
181
|
-
if (r !== null && t !== null && typeof r == "object" && typeof t == "object" && !Array.isArray(r) && !Array.isArray(t)) {
|
|
182
|
-
const e = r.constructor === Object || r.constructor === void 0, u = t.constructor === Object || t.constructor === void 0;
|
|
183
|
-
if (!e || !u)
|
|
184
|
-
return !1;
|
|
185
|
-
const i = Object.keys(r), n = Object.keys(t);
|
|
186
|
-
if (i.length !== n.length)
|
|
187
|
-
return !1;
|
|
188
|
-
for (const s of i)
|
|
189
|
-
if (!n.includes(s) || !a(
|
|
190
|
-
r[s],
|
|
191
|
-
t[s]
|
|
192
|
-
))
|
|
193
|
-
return !1;
|
|
194
|
-
return !0;
|
|
195
|
-
}
|
|
196
|
-
return !1;
|
|
197
|
-
}
|
|
198
|
-
function Y(r) {
|
|
199
|
-
return !isNaN(Number(r)) && !isNaN(parseFloat(String(r))) ? Number(r) : r;
|
|
200
|
-
}
|
|
201
|
-
function Z(r) {
|
|
202
|
-
return r === "__proto__" || r === "constructor" || r === "prototype";
|
|
203
|
-
}
|
|
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";
|
|
204
9
|
export {
|
|
205
|
-
|
|
206
|
-
|
|
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,
|
|
207
17
|
Y as entriesKeyValue,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
18
|
+
a as getAccessibleValues,
|
|
19
|
+
f as isAccessibleData,
|
|
20
|
+
g as isArray,
|
|
21
|
+
S as isBoolean,
|
|
22
|
+
h as isFalsy,
|
|
213
23
|
x as isFiniteNumber,
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
V as
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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,
|
|
32
|
+
K as isNull,
|
|
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,
|
|
231
46
|
E as isTruthy,
|
|
232
47
|
J as isTruthyObject,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
|
250
70
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolki/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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.
|
|
18
|
+
"@tolki/types": "^1.6.0"
|
|
19
19
|
},
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"files": [
|