@tolki/utils 1.3.0 → 1.5.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 +75 -3
- package/dist/cast.d.ts.map +1 -1
- package/dist/cast.js +117 -33
- package/dist/equality.d.ts +49 -2
- package/dist/equality.d.ts.map +1 -1
- package/dist/equality.js +148 -86
- package/dist/exceptions.d.ts +60 -0
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/exceptions.js +54 -0
- package/dist/guards.d.ts +66 -2
- package/dist/guards.d.ts.map +1 -1
- package/dist/guards.js +110 -91
- package/dist/index.js +94 -66
- package/dist/keys.d.ts +93 -0
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +89 -22
- package/dist/range.d.ts +70 -0
- package/dist/range.d.ts.map +1 -1
- package/dist/range.js +103 -5
- package/dist/reflect.d.ts +16 -2
- package/dist/reflect.d.ts.map +1 -1
- package/dist/reflect.js +19 -9
- package/dist/sorting.d.ts +16 -2
- package/dist/sorting.d.ts.map +1 -1
- package/dist/sorting.js +27 -13
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +94 -66
- package/package.json +2 -2
package/dist/reflect.js
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import { isNull as
|
|
2
|
-
function
|
|
3
|
-
return
|
|
1
|
+
import { isNull as i, isUndefined as f, isPhpInt as s, isString as u, isBoolean as c, isArray as e, isPlainObject as p, isFunction as n, isObject as b, isNumber as m, isInteger as y } from "./guards.js";
|
|
2
|
+
function o(r) {
|
|
3
|
+
return i(r) ? "object" : e(r) ? "array" : typeof r;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function j(r) {
|
|
6
6
|
return r === void 0 ? null : typeof r == "function" ? r() : r;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
return
|
|
8
|
+
function O(r) {
|
|
9
|
+
return i(r) ? "NULL" : m(r) ? y(r) ? "integer" : "double" : e(r) ? "array" : Number.isNaN(r) ? "double" : n(r) ? "object" : f(r) ? "NULL" : typeof r;
|
|
10
|
+
}
|
|
11
|
+
function L(r) {
|
|
12
|
+
return i(r) || f(r) ? "null" : o(r) === "number" ? s(r) ? "int" : "float" : u(r) ? "string" : c(r) ? "bool" : e(r) || p(r) ? "array" : n(r) ? "Closure" : b(r) && n(r.constructor) ? N(r.constructor) : o(r);
|
|
13
|
+
}
|
|
14
|
+
function N(r) {
|
|
15
|
+
if (r.name)
|
|
16
|
+
return r.name;
|
|
17
|
+
const t = Object.getPrototypeOf(r);
|
|
18
|
+
return `${n(t) && t.name ? t.name : "class"}@anonymous`;
|
|
10
19
|
}
|
|
11
20
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
L as phpDebugType,
|
|
22
|
+
O as phpTypeName,
|
|
23
|
+
j as resolveDefault,
|
|
24
|
+
o as typeOf
|
|
15
25
|
};
|
package/dist/sorting.d.ts
CHANGED
|
@@ -11,10 +11,24 @@ export type SortValueResolver = (item: unknown, key: PathKey) => unknown;
|
|
|
11
11
|
* Build the sort-descriptor comparator factory for one path resolver.
|
|
12
12
|
*
|
|
13
13
|
* `@tolki/utils` sits below every path package, so the caller supplies the
|
|
14
|
-
* resolver: `getNestedValue` for `Arr`/`Obj`, `
|
|
14
|
+
* resolver: `getNestedValue` for `Arr`/`Obj`, a `data_get` reader for `Collection`.
|
|
15
15
|
*
|
|
16
16
|
* @param resolve - Reads a descriptor's key off an item.
|
|
17
17
|
* @returns A function building the comparator one sort descriptor implies.
|
|
18
18
|
*/
|
|
19
|
-
export declare function createSortSpecComparator(resolve: SortValueResolver): <TValue>(spec: SortSpec<TValue>, forceDescending: boolean) => (a: TValue, b: TValue) => number;
|
|
19
|
+
export declare function createSortSpecComparator(resolve: SortValueResolver): <TValue>(spec: SortSpec<TValue>, forceDescending: boolean) => (a: TValue, b: TValue) => number | boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Read a comparator's answers as PHP's `usort()`, `uasort()` and `uksort()` read them, for `Array.prototype.sort`.
|
|
22
|
+
*
|
|
23
|
+
* A number is cast to an int, so a fraction below 1 ties. A bool is deprecated in PHP 8 but still sorts: `true` is 1,
|
|
24
|
+
* and `false` asks again with the operands swapped, where `true` is -1.
|
|
25
|
+
*
|
|
26
|
+
* @param compare - A comparator of two items, answering a number or a bool
|
|
27
|
+
* @returns A comparator answering -1, 0 or 1
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* [3, 1, 2].sort(phpSortComparator((a, b) => a > b)); -> [1, 2, 3]
|
|
31
|
+
* [3, 1, 2].sort(phpSortComparator((a, b) => (a - b) / 10)); -> [3, 1, 2]
|
|
32
|
+
*/
|
|
33
|
+
export declare function phpSortComparator<TValue>(compare: (a: TValue, b: TValue) => unknown): (a: TValue, b: TValue) => number;
|
|
20
34
|
//# sourceMappingURL=sorting.d.ts.map
|
package/dist/sorting.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;AAYtD;;;;;;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,GAAG,OAAO,CAkChD;AAcD;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EACpC,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,GAC3C,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAUlC"}
|
package/dist/sorting.js
CHANGED
|
@@ -1,18 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { phpIntCast as g } from "./cast.js";
|
|
2
|
+
import { compareValues as C } from "./equality.js";
|
|
3
|
+
import { isArray as a, isFunction as S, isUndefined as h, isBoolean as A, isNumber as l } from "./guards.js";
|
|
4
|
+
function B(r) {
|
|
5
|
+
return function(n, t) {
|
|
6
|
+
if (c(n))
|
|
7
|
+
return n;
|
|
8
|
+
if (a(n) && c(n[0]))
|
|
9
|
+
return n[0];
|
|
10
|
+
const [u, o] = a(n) ? n : [n, void 0], m = h(o) || o === !0 || o === "asc" || o === "Ascending", s = t || !m;
|
|
11
|
+
return (p, d) => {
|
|
12
|
+
const e = C(r(p, u), r(d, u));
|
|
13
|
+
return s ? -e : e;
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
}
|
|
17
|
+
function c(r) {
|
|
18
|
+
return S(r);
|
|
19
|
+
}
|
|
20
|
+
function D(r) {
|
|
21
|
+
return (i, n) => {
|
|
22
|
+
const t = r(i, n);
|
|
23
|
+
return t === !1 ? -f(r(n, i)) : f(t);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function f(r) {
|
|
27
|
+
return A(r) ? r ? 1 : 0 : l(r) ? Math.sign(g(r)) : 0;
|
|
28
|
+
}
|
|
16
29
|
export {
|
|
17
|
-
|
|
30
|
+
B as createSortSpecComparator,
|
|
31
|
+
D as phpSortComparator
|
|
18
32
|
};
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
package/dist/utils.js
CHANGED
|
@@ -1,70 +1,98 @@
|
|
|
1
|
-
import { arrayableValues as i, castableToArray as s, cssListItemToString as
|
|
2
|
-
import { compareValues as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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";
|
|
9
10
|
export {
|
|
10
|
-
|
|
11
|
+
P as InvalidArgumentException,
|
|
12
|
+
A as ItemNotFoundException,
|
|
13
|
+
d as MultipleItemsFoundException,
|
|
14
|
+
v as UnexpectedValueException,
|
|
15
|
+
ye as arrayKeyExistsError,
|
|
16
|
+
we as arrayValueMessage,
|
|
17
|
+
t as arrayableItems,
|
|
11
18
|
i as arrayableValues,
|
|
12
19
|
s as castableToArray,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
20
|
+
g as compareValues,
|
|
21
|
+
ke as createSortSpecComparator,
|
|
22
|
+
a as cssListItemToString,
|
|
23
|
+
me as defineKey,
|
|
24
|
+
ue as entriesKeyValue,
|
|
25
|
+
o as getAccessibleValues,
|
|
26
|
+
ce as hasOwnToString,
|
|
27
|
+
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,
|
|
36
|
+
j as isInteger,
|
|
37
|
+
he as isIntegerLikeKey,
|
|
38
|
+
k as isIterable,
|
|
39
|
+
L as isMap,
|
|
40
|
+
U as isNegativeNumber,
|
|
41
|
+
w as isNonPrimitive,
|
|
42
|
+
z as isNull,
|
|
43
|
+
D as isNumber,
|
|
44
|
+
R as isObject,
|
|
45
|
+
q as isObjectAny,
|
|
46
|
+
J as isPhpAccessible,
|
|
47
|
+
ge as isPhpArrayKey,
|
|
48
|
+
W as isPhpFalsy,
|
|
49
|
+
B as isPhpInt,
|
|
50
|
+
G as isPhpNumeric,
|
|
51
|
+
H as isPlainObject,
|
|
52
|
+
Q as isPositiveNumber,
|
|
53
|
+
X as isPrimitive,
|
|
54
|
+
Y as isPrototypeObject,
|
|
55
|
+
Z as isSet,
|
|
56
|
+
_ as isString,
|
|
57
|
+
$ as isStringable,
|
|
58
|
+
ee as isSymbol,
|
|
59
|
+
re as isTruthy,
|
|
60
|
+
te as isTruthyObject,
|
|
61
|
+
ie as isUndefined,
|
|
62
|
+
Se as isUnsafeKey,
|
|
63
|
+
se as isWeakMap,
|
|
64
|
+
ae as isWeakSet,
|
|
65
|
+
fe as keyedEntries,
|
|
66
|
+
S as looseEqual,
|
|
67
|
+
ze as lowerFirst,
|
|
68
|
+
p as normalizeToArray,
|
|
69
|
+
oe as objectToString,
|
|
70
|
+
f as operatorMatch,
|
|
71
|
+
xe as phpArrayKey,
|
|
72
|
+
Ie as phpComputedKey,
|
|
73
|
+
Oe as phpDebugType,
|
|
74
|
+
n as phpIntArgument,
|
|
75
|
+
l as phpIntCast,
|
|
76
|
+
Le as phpSortComparator,
|
|
77
|
+
y as phpStringCast,
|
|
78
|
+
Ve as phpTypeName,
|
|
79
|
+
pe as phpValueMatch,
|
|
80
|
+
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,
|
|
90
|
+
m as toArrayable,
|
|
91
|
+
u as toJsonSerializable,
|
|
92
|
+
c as toJsonable,
|
|
93
|
+
De as toLower,
|
|
94
|
+
b as toPhpKeyString,
|
|
95
|
+
Re as toUpper,
|
|
96
|
+
Me as typeOf,
|
|
97
|
+
qe as upperFirst
|
|
70
98
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolki/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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.8.0"
|
|
19
19
|
},
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"files": [
|