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