@tolki/data 1.0.1 → 1.0.3
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 +13 -3
- package/dist/data.d.ts +94 -98
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +414 -462
- package/dist/dispatch.d.ts +27 -4
- package/dist/dispatch.d.ts.map +1 -1
- package/dist/dispatch.js +37 -39
- package/dist/index.js +1 -96
- package/package.json +7 -6
package/dist/dispatch.d.ts
CHANGED
|
@@ -6,6 +6,14 @@ type AnyFn = (...args: never[]) => unknown;
|
|
|
6
6
|
* keyed by booleans or objects cannot fall through to a delegate row describing a result the helper never returns.
|
|
7
7
|
*/
|
|
8
8
|
type KeyedMapRow<TObjFn extends AnyFn> = TObjFn extends (data: never, ...rest: infer TRest) => infer TReturn ? (data: ReadonlyMap<unknown, unknown>, ...rest: TRest) => TReturn : never;
|
|
9
|
+
/**
|
|
10
|
+
* The type of a `data*` helper that forwards to an array helper and an object helper, keeping both signatures.
|
|
11
|
+
*
|
|
12
|
+
* The intersection is the point: it re-runs overload resolution per call site, which is the only construct that
|
|
13
|
+
* forwards an overloaded delegate's return type. `TArrFn` must come before `TObjFn`: arr's rows are array-shaped,
|
|
14
|
+
* so keyed data falls through them to `TObjFn`.
|
|
15
|
+
*/
|
|
16
|
+
export type Dispatched<TArrFn extends AnyFn, TObjFn extends AnyFn> = KeyedMapRow<TObjFn> & TArrFn & TObjFn;
|
|
9
17
|
/**
|
|
10
18
|
* Determine whether the given data carries its own keys.
|
|
11
19
|
*
|
|
@@ -28,7 +36,7 @@ export declare function isKeyedData(data: unknown): boolean;
|
|
|
28
36
|
*/
|
|
29
37
|
export declare function toKeyedData<TKey extends PropertyKey, TValue>(data: unknown): Record<TKey, TValue>;
|
|
30
38
|
/**
|
|
31
|
-
* Hand keyed data to the object helper exactly as it arrived. This is
|
|
39
|
+
* Hand keyed data to the object helper exactly as it arrived. This is forwardData's default.
|
|
32
40
|
*
|
|
33
41
|
* Only a Map keeps a PHP array's out-of-sequence integer keys in order: `{2: "c", 0: "a"}` iterates `0` first,
|
|
34
42
|
* while PHP's `[2 => 'c', 0 => 'a']` iterates as written.
|
|
@@ -70,16 +78,31 @@ export declare function streamPositionalData<TValue>(data: unknown): Iterable<TV
|
|
|
70
78
|
* @returns The elements of a materializable iterable, otherwise the data wrapped in a list.
|
|
71
79
|
*/
|
|
72
80
|
export declare function toPositionalBacking(data: unknown): unknown;
|
|
81
|
+
/**
|
|
82
|
+
* Forward data to the array helper or the object helper, by whether the data carries its own keys.
|
|
83
|
+
*
|
|
84
|
+
* @sideEffects mutates - Writes through the data when the delegate does, as `pop` does.
|
|
85
|
+
* @param arrFn - The `@tolki/arr` helper, used for a list backing.
|
|
86
|
+
* @param objFn - The `@tolki/obj` helper, used for a keyed backing.
|
|
87
|
+
* @param data - The data the helper was called with.
|
|
88
|
+
* @param rest - The helper's other arguments, passed on untouched.
|
|
89
|
+
* @param toPositional - How a non-keyed backing reaches `arrFn`.
|
|
90
|
+
* @param toKeyed - How a keyed backing reaches `objFn`.
|
|
91
|
+
* @returns The delegate's own result.
|
|
92
|
+
*/
|
|
93
|
+
export declare function forwardData(arrFn: AnyFn, objFn: AnyFn, data: unknown, rest: readonly unknown[], toPositional?: (data: unknown) => unknown, toKeyed?: (data: unknown) => unknown): unknown;
|
|
73
94
|
/**
|
|
74
95
|
* Build a function that forwards to an array helper or an object helper, keeping both signatures.
|
|
75
96
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
97
|
+
* The `data*` helpers are function declarations that call `forwardData` instead, so bundlers can drop an unused call.
|
|
98
|
+
* This builds the same forwarder in one call, for the type sweeps that measure a delegate pair the way `data` types it.
|
|
99
|
+
*
|
|
100
|
+
* @param arrFn - The `@tolki/arr` helper, used for a list backing.
|
|
78
101
|
* @param objFn - The `@tolki/obj` helper, used for a keyed backing.
|
|
79
102
|
* @param toPositional - How a non-keyed backing reaches `arrFn`.
|
|
80
103
|
* @param toKeyed - How a keyed backing reaches `objFn`.
|
|
81
104
|
* @returns A function carrying both helpers' overloads, behind the Map row.
|
|
82
105
|
*/
|
|
83
|
-
export declare function dispatch<TArrFn extends AnyFn, TObjFn extends AnyFn>(arrFn: TArrFn, objFn: TObjFn, toPositional?: (data: unknown) => unknown, toKeyed?: (data: unknown) => unknown):
|
|
106
|
+
export declare function dispatch<TArrFn extends AnyFn, TObjFn extends AnyFn>(arrFn: TArrFn, objFn: TObjFn, toPositional?: (data: unknown) => unknown, toKeyed?: (data: unknown) => unknown): Dispatched<TArrFn, TObjFn>;
|
|
84
107
|
export {};
|
|
85
108
|
//# sourceMappingURL=dispatch.d.ts.map
|
package/dist/dispatch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../src/dispatch.ts"],"names":[],"mappings":"AAUA,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAE3C;;;;;GAKG;AACH,KAAK,WAAW,CAAC,MAAM,SAAS,KAAK,IAAI,MAAM,SAAS,CACpD,IAAI,EAAE,KAAK,EACX,GAAG,IAAI,EAAE,MAAM,KAAK,KACnB,MAAM,OAAO,GACZ,CAAC,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,GAChE,KAAK,CAAC;AAEZ;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../src/dispatch.ts"],"names":[],"mappings":"AAUA,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAE3C;;;;;GAKG;AACH,KAAK,WAAW,CAAC,MAAM,SAAS,KAAK,IAAI,MAAM,SAAS,CACpD,IAAI,EAAE,KAAK,EACX,GAAG,IAAI,EAAE,MAAM,KAAK,KACnB,MAAM,OAAO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,MAAM,SAAS,KAAK,EAC/D,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,YAAY,GAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAA6B,EAC9D,OAAO,GAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAuB,GACpD,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAK5B"}
|
package/dist/dispatch.js
CHANGED
|
@@ -1,39 +1,37 @@
|
|
|
1
|
-
import { wrap as
|
|
2
|
-
import { from as
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
g as toPositionalBacking
|
|
39
|
-
};
|
|
1
|
+
import { wrap as e } from "@tolki/arr";
|
|
2
|
+
import { from as t } from "@tolki/obj";
|
|
3
|
+
import { isArray as n, isIterable as r, isMap as i, isObject as a, isUndefined as o } from "@tolki/utils";
|
|
4
|
+
// src/dispatch.ts
|
|
5
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
6
|
+
function s(e) {
|
|
7
|
+
return i(e) ? !0 : a(e) && !r(e);
|
|
8
|
+
}
|
|
9
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
10
|
+
function c(e) {
|
|
11
|
+
return i(e) ? t(e) : e;
|
|
12
|
+
}
|
|
13
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
14
|
+
function l(e) {
|
|
15
|
+
return e;
|
|
16
|
+
}
|
|
17
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
18
|
+
function u(e) {
|
|
19
|
+
return i(e) ? new Map(e) : e;
|
|
20
|
+
}
|
|
21
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
22
|
+
function d(t) {
|
|
23
|
+
return r(t) ? t : o(t) ? [] : e(t);
|
|
24
|
+
}
|
|
25
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
26
|
+
function f(t) {
|
|
27
|
+
return r(t) && !n(t) && !i(t) ? [...t] : e(t);
|
|
28
|
+
}
|
|
29
|
+
function p(e, t, n, r, i = f, a = l) {
|
|
30
|
+
let o = /* @__PURE__ */ s(n);
|
|
31
|
+
return (o ? t : e)(o ? a(n) : i(n), ...r);
|
|
32
|
+
}
|
|
33
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
34
|
+
function m(e, t, n = f, r = l) {
|
|
35
|
+
return (i, ...a) => p(e, t, i, a, n, r);
|
|
36
|
+
}
|
|
37
|
+
export { u as copyKeyedData, m as dispatch, p as forwardData, s as isKeyedData, l as keepKeyedData, d as streamPositionalData, c as toKeyedData, f as toPositionalBacking };
|
package/dist/index.js
CHANGED
|
@@ -1,96 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
d as dataAdd,
|
|
4
|
-
e as dataAfter,
|
|
5
|
-
s as dataBefore,
|
|
6
|
-
i as dataBoolean,
|
|
7
|
-
n as dataChunk,
|
|
8
|
-
o as dataChunkBy,
|
|
9
|
-
r as dataChunkWhile,
|
|
10
|
-
l as dataCollapse,
|
|
11
|
-
c as dataCombine,
|
|
12
|
-
f as dataContains,
|
|
13
|
-
S as dataContainsStrict,
|
|
14
|
-
p as dataCount,
|
|
15
|
-
u as dataCrossJoin,
|
|
16
|
-
y as dataDiff,
|
|
17
|
-
h as dataDiffAssoc,
|
|
18
|
-
C as dataDiffAssocUsing,
|
|
19
|
-
D as dataDiffKeys,
|
|
20
|
-
U as dataDiffKeysUsing,
|
|
21
|
-
k as dataDiffUsing,
|
|
22
|
-
g as dataDivide,
|
|
23
|
-
A as dataDot,
|
|
24
|
-
P as dataEvery,
|
|
25
|
-
R as dataExcept,
|
|
26
|
-
F as dataExceptValues,
|
|
27
|
-
I as dataExists,
|
|
28
|
-
K as dataFilter,
|
|
29
|
-
W as dataFirst,
|
|
30
|
-
m as dataFlatten,
|
|
31
|
-
v as dataFlip,
|
|
32
|
-
B as dataFloat,
|
|
33
|
-
T as dataForget,
|
|
34
|
-
x as dataFrom,
|
|
35
|
-
E as dataGet,
|
|
36
|
-
H as dataHas,
|
|
37
|
-
M as dataHasAll,
|
|
38
|
-
V as dataHasAny,
|
|
39
|
-
J as dataInteger,
|
|
40
|
-
N as dataIntersect,
|
|
41
|
-
O as dataIntersectAssoc,
|
|
42
|
-
b as dataIntersectAssocUsing,
|
|
43
|
-
j as dataIntersectByKeys,
|
|
44
|
-
G as dataIntersectUsing,
|
|
45
|
-
L as dataItem,
|
|
46
|
-
Q as dataJoin,
|
|
47
|
-
q as dataKeyBy,
|
|
48
|
-
w as dataKeys,
|
|
49
|
-
z as dataLast,
|
|
50
|
-
X as dataMap,
|
|
51
|
-
Y as dataMapSpread,
|
|
52
|
-
Z as dataMapWithKeys,
|
|
53
|
-
_ as dataOnly,
|
|
54
|
-
$ as dataOnlyValues,
|
|
55
|
-
aa as dataPad,
|
|
56
|
-
ta as dataPartition,
|
|
57
|
-
da as dataPluck,
|
|
58
|
-
ea as dataPop,
|
|
59
|
-
sa as dataPrepend,
|
|
60
|
-
ia as dataPrependKeysWith,
|
|
61
|
-
na as dataPull,
|
|
62
|
-
oa as dataPush,
|
|
63
|
-
ra as dataQuery,
|
|
64
|
-
la as dataRandom,
|
|
65
|
-
ca as dataReject,
|
|
66
|
-
fa as dataReplace,
|
|
67
|
-
Sa as dataReplaceRecursive,
|
|
68
|
-
pa as dataReverse,
|
|
69
|
-
ua as dataSearch,
|
|
70
|
-
ya as dataSelect,
|
|
71
|
-
ha as dataSet,
|
|
72
|
-
Ca as dataShift,
|
|
73
|
-
Da as dataShuffle,
|
|
74
|
-
Ua as dataSkipUntil,
|
|
75
|
-
ka as dataSkipWhile,
|
|
76
|
-
ga as dataSlice,
|
|
77
|
-
Aa as dataSole,
|
|
78
|
-
Pa as dataSome,
|
|
79
|
-
Ra as dataSort,
|
|
80
|
-
Fa as dataSortDesc,
|
|
81
|
-
Ia as dataSortRecursive,
|
|
82
|
-
Ka as dataSortRecursiveDesc,
|
|
83
|
-
Wa as dataSplice,
|
|
84
|
-
ma as dataString,
|
|
85
|
-
va as dataTake,
|
|
86
|
-
Ba as dataTakeUntil,
|
|
87
|
-
Ta as dataTakeWhile,
|
|
88
|
-
xa as dataToCssClasses,
|
|
89
|
-
Ea as dataToCssStyles,
|
|
90
|
-
Ha as dataUndot,
|
|
91
|
-
Ma as dataUnion,
|
|
92
|
-
Va as dataUnshift,
|
|
93
|
-
Ja as dataValues,
|
|
94
|
-
Na as dataWhere,
|
|
95
|
-
Oa as dataWhereNotNull
|
|
96
|
-
};
|
|
1
|
+
export { dataAdd, dataAfter, dataBefore, dataBoolean, dataChunk, dataChunkBy, dataChunkWhile, dataCollapse, dataCombine, dataContains, dataContainsStrict, dataCount, dataCrossJoin, dataDiff, dataDiffAssoc, dataDiffAssocUsing, dataDiffKeys, dataDiffKeysUsing, dataDiffUsing, dataDivide, dataDot, dataEvery, dataExcept, dataExceptValues, dataExists, dataFilter, dataFirst, dataFlatten, dataFlip, dataFloat, dataForget, dataFrom, dataGet, dataHas, dataHasAll, dataHasAny, dataInteger, dataIntersect, dataIntersectAssoc, dataIntersectAssocUsing, dataIntersectByKeys, dataIntersectUsing, dataItem, dataJoin, dataKeyBy, dataKeys, dataLast, dataMap, dataMapSpread, dataMapWithKeys, dataOnly, dataOnlyValues, dataPad, dataPartition, dataPluck, dataPop, dataPrepend, dataPrependKeysWith, dataPull, dataPush, dataQuery, dataRandom, dataReject, dataReplace, dataReplaceRecursive, dataReverse, dataSearch, dataSelect, dataSet, dataShift, dataShuffle, dataSkipUntil, dataSkipWhile, dataSlice, dataSole, dataSome, dataSort, dataSortDesc, dataSortRecursive, dataSortRecursiveDesc, dataSplice, dataString, dataTake, dataTakeUntil, dataTakeWhile, dataToCssClasses, dataToCssStyles, dataUndot, dataUnion, dataUnshift, dataValues, dataWhere, dataWhereNotNull } from "./data.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolki/data",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Utilities for working with various data structures in JavaScript.",
|
|
5
5
|
"author": "Abraham Arango <https://github.com/abetwothree>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"utilities"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@tolki/
|
|
27
|
-
"@tolki/
|
|
28
|
-
"@tolki/
|
|
29
|
-
"@tolki/
|
|
26
|
+
"@tolki/obj": "^1.0.2",
|
|
27
|
+
"@tolki/arr": "^1.0.2",
|
|
28
|
+
"@tolki/types": "^1.12.0",
|
|
29
|
+
"@tolki/utils": "^1.6.4"
|
|
30
30
|
},
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"files": [
|
|
@@ -53,8 +53,9 @@
|
|
|
53
53
|
"types": "./dist/index.d.ts"
|
|
54
54
|
},
|
|
55
55
|
"./data": {
|
|
56
|
+
"types": "./dist/data.d.ts",
|
|
56
57
|
"import": "./dist/data.js",
|
|
57
|
-
"
|
|
58
|
+
"default": "./dist/data.js"
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
}
|