@solid-primitives/utils 6.2.1 → 6.2.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/dist/immutable/index.cjs +8 -5
- package/dist/immutable/index.d.cts +257 -0
- package/dist/immutable/index.d.ts +1 -1
- package/dist/immutable/index.js +8 -5
- package/dist/index/index.d.cts +130 -0
- package/dist/index/index.d.ts +4 -3
- package/dist/{types-38269011.d.ts → types-d58cbe2f.d.ts} +1 -1
- package/package.json +12 -6
package/dist/immutable/index.cjs
CHANGED
|
@@ -65,11 +65,14 @@ exports.update = (...args) => exports.withCopy(args[0], (obj) => {
|
|
|
65
65
|
|
|
66
66
|
// src/immutable/object.ts
|
|
67
67
|
exports.omit = (object, ...keys) => exports.withObjectCopy(object, (object2) => keys.forEach((key) => delete object2[key]));
|
|
68
|
-
exports.pick = (object, ...keys) => keys.reduce(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
exports.pick = (object, ...keys) => keys.reduce(
|
|
69
|
+
(n, k) => {
|
|
70
|
+
if (k in object)
|
|
71
|
+
n[k] = object[k];
|
|
72
|
+
return n;
|
|
73
|
+
},
|
|
74
|
+
{}
|
|
75
|
+
);
|
|
73
76
|
function get(obj, ...keys) {
|
|
74
77
|
let res = obj;
|
|
75
78
|
for (const key of keys) {
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { I as ItemsOf, g as Modify, d as Many, A as AnyClass } from '../types-d58cbe2f.js';
|
|
2
|
+
import 'solid-js';
|
|
3
|
+
|
|
4
|
+
/** make shallow copy of an array */
|
|
5
|
+
declare const shallowArrayCopy: <T>(array: readonly T[]) => T[];
|
|
6
|
+
/** make shallow copy of an object */
|
|
7
|
+
declare const shallowObjectCopy: <T extends object>(object: T) => T;
|
|
8
|
+
/** make shallow copy of an array/object */
|
|
9
|
+
declare const shallowCopy: <T extends object>(source: T) => T;
|
|
10
|
+
/**
|
|
11
|
+
* apply mutations to the an array without changing the original
|
|
12
|
+
* @param array original array
|
|
13
|
+
* @param mutator function applying mutations to the copy of source
|
|
14
|
+
* @returns changed array copy
|
|
15
|
+
*/
|
|
16
|
+
declare const withArrayCopy: <T>(array: readonly T[], mutator: (copy: T[]) => void) => T[];
|
|
17
|
+
/**
|
|
18
|
+
* apply mutations to the an object without changing the original
|
|
19
|
+
* @param object original object
|
|
20
|
+
* @param mutator function applying mutations to the copy of source
|
|
21
|
+
* @returns changed object copy
|
|
22
|
+
*/
|
|
23
|
+
declare const withObjectCopy: <T extends object>(object: T, mutator: (copy: T) => void) => T;
|
|
24
|
+
/**
|
|
25
|
+
* apply mutations to the an object/array without changing the original
|
|
26
|
+
* @param source original object
|
|
27
|
+
* @param mutator function applying mutations to the copy of source
|
|
28
|
+
* @returns changed object copy
|
|
29
|
+
*/
|
|
30
|
+
declare const withCopy: <T extends object>(source: T, mutator: (copy: T) => void) => T;
|
|
31
|
+
|
|
32
|
+
/** `a + b + c + ...` */
|
|
33
|
+
declare function add(...a: number[]): number;
|
|
34
|
+
declare function add(...a: string[]): string;
|
|
35
|
+
/** `a - b - c - ...` */
|
|
36
|
+
declare const substract: (a: number, ...b: number[]) => number;
|
|
37
|
+
/** `a * b * c * ...` */
|
|
38
|
+
declare const multiply: (a: number, ...b: number[]) => number;
|
|
39
|
+
/** `a / b / c / ...` */
|
|
40
|
+
declare const divide: (a: number, ...b: number[]) => number;
|
|
41
|
+
/** `a ** b ** c ** ...` */
|
|
42
|
+
declare const power: (a: number, ...b: number[]) => number;
|
|
43
|
+
/** clamp a number value between two other values */
|
|
44
|
+
declare const clamp: (n: number, min: number, max: number) => number;
|
|
45
|
+
|
|
46
|
+
type Predicate<T> = (item: T, index: number, array: readonly T[]) => boolean;
|
|
47
|
+
type MappingFn<T, V> = (item: T, index: number, array: readonly T[]) => V;
|
|
48
|
+
type FlattenArray<T> = T extends any[] ? FlattenArray<ItemsOf<T>> : T;
|
|
49
|
+
type ModifyValue<O, K extends keyof O, V> = Omit<O, K> & {
|
|
50
|
+
[key in K]: V;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type UpdateSetter<O, K extends keyof O, V> = V | ((prev: O[K]) => V);
|
|
54
|
+
type Update = {
|
|
55
|
+
<O extends object, K0 extends keyof O, K1 extends keyof O[K0], K2 extends keyof O[K0][K1], K3 extends keyof O[K0][K1][K2], K4 extends keyof O[K0][K1][K2][K3], V>(object: O, k0: K0, k1: K1, k2: K2, k3: K3, k4: K4, setter: UpdateSetter<O[K0][K1][K2][K3], K4, V>): ModifyValue<O, K0, ModifyValue<O[K0], K1, ModifyValue<O[K0][K1], K2, ModifyValue<O[K0][K1][K2], K3, ModifyValue<O[K0][K1][K2][K3], K4, V>>>>>;
|
|
56
|
+
<O extends object, K0 extends keyof O, K1 extends keyof O[K0], K2 extends keyof O[K0][K1], K3 extends keyof O[K0][K1][K2], V>(object: O, k0: K0, k1: K1, k2: K2, k3: K3, setter: UpdateSetter<O[K0][K1][K2], K3, V>): ModifyValue<O, K0, ModifyValue<O[K0], K1, ModifyValue<O[K0][K1], K2, ModifyValue<O[K0][K1][K2], K3, V>>>>;
|
|
57
|
+
<O extends object, K0 extends keyof O, K1 extends keyof O[K0], K2 extends keyof O[K0][K1], V>(object: O, k0: K0, k1: K1, k2: K2, setter: UpdateSetter<O[K0][K1], K2, V>): ModifyValue<O, K0, ModifyValue<O[K0], K1, ModifyValue<O[K0][K1], K2, V>>>;
|
|
58
|
+
<O extends object, K0 extends keyof O, K1 extends keyof O[K0], V>(object: O, k0: K0, k1: K1, setter: UpdateSetter<O[K0], K1, V>): ModifyValue<O, K0, ModifyValue<O[K0], K1, V>>;
|
|
59
|
+
<O extends object, K extends keyof O, V>(object: O, key: K, setter: UpdateSetter<O, K, V>): ModifyValue<O, K, V>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Change single value in an object by key. Allows accessign nested objects by passing multiple keys.
|
|
63
|
+
*
|
|
64
|
+
* Performs a shallow copy of each accessed object.
|
|
65
|
+
*
|
|
66
|
+
* @param object original source
|
|
67
|
+
* @param ...keys keys of sequential accessed objects
|
|
68
|
+
* @param value a value to set in place of a previous one, or a setter function.
|
|
69
|
+
* ```ts
|
|
70
|
+
* V | ((prev: O[K]) => V)
|
|
71
|
+
* ```
|
|
72
|
+
* a new value doesn't have to have the same type as the original
|
|
73
|
+
* @returns changed copy of the original object
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* const original = { foo: { bar: { baz: 123 }}};
|
|
77
|
+
* const newObj = update(original, "foo", "bar", "baz", prev => prev + 1)
|
|
78
|
+
* original // { foo: { bar: { baz: 123 }}}
|
|
79
|
+
* newObj // { foo: { bar: { baz: 124 }}}
|
|
80
|
+
*/
|
|
81
|
+
declare const update: Update;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Create a new subset object without the provided keys
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const newObject = omit({ a:"foo", b:"bar", c: "baz" }, 'a', 'b')
|
|
89
|
+
* newObject // => { c: "baz" }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare const omit: <O extends object, K extends keyof O>(object: O, ...keys: K[]) => Omit<O, K>;
|
|
93
|
+
/**
|
|
94
|
+
* Create a new subset object with only the provided keys
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* const newObject = pick({ a:"foo", b:"bar", c: "baz" }, 'a', 'b')
|
|
99
|
+
* newObject // => { a:"foo", b:"bar" }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare const pick: <O extends object, K extends keyof O>(object: O, ...keys: K[]) => Pick<O, K>;
|
|
103
|
+
/**
|
|
104
|
+
* Get a single property value of an object by specifying a path to it.
|
|
105
|
+
*/
|
|
106
|
+
declare function get<O extends object, K extends keyof O>(obj: O, key: K): O[K];
|
|
107
|
+
declare function get<O extends object, K1 extends keyof O, K2 extends keyof O[K1]>(obj: O, k1: K1, k2: K2): O[K1][K2];
|
|
108
|
+
declare function get<O extends object, K1 extends keyof O, K2 extends keyof O[K1], K3 extends keyof O[K1][K2]>(obj: O, k1: K1, k2: K2, k3: K3): O[K1][K2][K3];
|
|
109
|
+
declare function get<O extends object, K1 extends keyof O, K2 extends keyof O[K1], K3 extends keyof O[K1][K2], K4 extends keyof O[K1][K2][K3]>(obj: O, k1: K1, k2: K2, k3: K3, k4: K4): O[K1][K2][K3][K4];
|
|
110
|
+
declare function get<O extends object, K1 extends keyof O, K2 extends keyof O[K1], K3 extends keyof O[K1][K2], K4 extends keyof O[K1][K2][K3], K5 extends keyof O[K1][K2][K3][K4]>(obj: O, k1: K1, k2: K2, k3: K3, k4: K4, k5: K5): O[K1][K2][K3][K4][K5];
|
|
111
|
+
declare function get<O extends object, K1 extends keyof O, K2 extends keyof O[K1], K3 extends keyof O[K1][K2], K4 extends keyof O[K1][K2][K3], K5 extends keyof O[K1][K2][K3][K4], K6 extends keyof O[K1][K2][K3][K4][K5]>(obj: O, k1: K1, k2: K2, k3: K3, k4: K4, k5: K5, k6: K6): O[K1][K2][K3][K4][K5][K6];
|
|
112
|
+
/**
|
|
113
|
+
* Split object properties by keys into multiple object copies with a subset of selected properties.
|
|
114
|
+
*
|
|
115
|
+
* @param object original object
|
|
116
|
+
* @param ...keys keys to pick from the source, or multiple arrays of keys *(for splitting into more than 2 objects)*
|
|
117
|
+
* ```ts
|
|
118
|
+
* (keyof object)[][] | (keyof object)[]
|
|
119
|
+
* ```
|
|
120
|
+
* @returns array of subset objects
|
|
121
|
+
*/
|
|
122
|
+
declare function split<T extends object, K extends keyof T>(object: T, ...keys: K[]): [Pick<T, K>, Omit<T, K>];
|
|
123
|
+
declare function split<T extends object, K1 extends keyof T, K2 extends keyof T>(object: T, ...keys: [K1[], K2[]]): [Pick<T, K1>, Pick<T, K2>, Omit<T, K1 | K2>];
|
|
124
|
+
declare function split<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T>(object: T, ...keys: [K1[], K2[], K3[]]): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Omit<T, K1 | K2 | K3>];
|
|
125
|
+
declare function split<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T, K4 extends keyof T>(object: T, ...keys: [K1[], K2[], K3[], K4[]]): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Pick<T, K4>, Omit<T, K1 | K2 | K3 | K4>];
|
|
126
|
+
declare function split<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T, K4 extends keyof T, K5 extends keyof T>(object: T, ...keys: [K1[], K2[], K3[], K4[], K5[]]): [
|
|
127
|
+
Pick<T, K1>,
|
|
128
|
+
Pick<T, K2>,
|
|
129
|
+
Pick<T, K3>,
|
|
130
|
+
Pick<T, K4>,
|
|
131
|
+
Pick<T, K5>,
|
|
132
|
+
Omit<T, K1 | K2 | K3 | K4 | K5>
|
|
133
|
+
];
|
|
134
|
+
/**
|
|
135
|
+
* Merges multiple objects into a single one. Only the first level of properties is merged. An alternative to `{ ...a, ...b, ...c }`.
|
|
136
|
+
* @param ...objects objects to merge
|
|
137
|
+
* @example
|
|
138
|
+
* const d = merge(a, b, c)
|
|
139
|
+
*/
|
|
140
|
+
declare function merge<A extends object, B extends object>(a: A, b: B): Modify<A, B>;
|
|
141
|
+
declare function merge<A extends object, B extends object, C extends object>(a: A, b: B, c: C): Modify<Modify<A, B>, C>;
|
|
142
|
+
declare function merge<A extends object, B extends object, C extends object, D extends object>(a: A, b: B, c: C, d: D): Modify<Modify<Modify<A, B>, C>, D>;
|
|
143
|
+
declare function merge<A extends object, B extends object, C extends object, D extends object, E extends object>(a: A, b: B, c: C, d: D, e: E): Modify<Modify<Modify<Modify<A, B>, C>, D>, E>;
|
|
144
|
+
declare function merge<A extends object, B extends object, C extends object, D extends object, E extends object, F extends object>(a: A, b: B, c: C, d: D, e: E, f: F): Modify<Modify<Modify<Modify<Modify<A, B>, C>, D>, E>, F>;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* non-mutating `Array.prototype.push()`
|
|
148
|
+
* @returns changed array copy
|
|
149
|
+
*/
|
|
150
|
+
declare const push: <T>(list: readonly T[], ...items: T[]) => T[];
|
|
151
|
+
/**
|
|
152
|
+
* non-mutating function that drops n items from the array start.
|
|
153
|
+
* @returns changed array copy
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* const newList = drop([1,2,3])
|
|
158
|
+
* newList // => [2,3]
|
|
159
|
+
*
|
|
160
|
+
* const newList = drop([1,2,3], 2)
|
|
161
|
+
* newList // => [3]
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare const drop: <T>(list: T[], n?: number) => T[];
|
|
165
|
+
/**
|
|
166
|
+
* non-mutating function that drops n items from the array end.
|
|
167
|
+
* @returns changed array copy
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* const newList = dropRight([1,2,3])
|
|
172
|
+
* newList // => [1,2]
|
|
173
|
+
*
|
|
174
|
+
* const newList = dropRight([1,2,3], 2)
|
|
175
|
+
* newList // => [1]
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
declare const dropRight: <T>(list: T[], n?: number) => T[];
|
|
179
|
+
/**
|
|
180
|
+
* standalone `Array.prototype.filter()` that filters out passed item
|
|
181
|
+
* @returns changed array copy
|
|
182
|
+
*/
|
|
183
|
+
declare const filterOut: <T>(list: readonly T[], item: T) => T[] & {
|
|
184
|
+
removed: number;
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* standalone `Array.prototype.filter()`
|
|
188
|
+
* @returns changed array copy
|
|
189
|
+
*/
|
|
190
|
+
declare function filter<T>(list: readonly T[], predicate: Predicate<T>): T[] & {
|
|
191
|
+
removed: number;
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* non-mutating `Array.prototype.sort()` as a standalone function
|
|
195
|
+
* @returns changed array copy
|
|
196
|
+
*/
|
|
197
|
+
declare const sort: <T>(list: T[], compareFn?: ((a: T, b: T) => number) | undefined) => T[];
|
|
198
|
+
/**
|
|
199
|
+
* standalone `Array.prototype.map()` function
|
|
200
|
+
*/
|
|
201
|
+
declare const map: <T, V>(list: readonly T[], mapFn: MappingFn<T, V>) => V[];
|
|
202
|
+
/**
|
|
203
|
+
* standalone `Array.prototype.slice()` function
|
|
204
|
+
*/
|
|
205
|
+
declare const slice: <T>(list: readonly T[], start?: number, end?: number) => T[];
|
|
206
|
+
/**
|
|
207
|
+
* non-mutating `Array.prototype.splice()` as a standalone function
|
|
208
|
+
* @returns changed array copy
|
|
209
|
+
*/
|
|
210
|
+
declare const splice: <T>(list: readonly T[], start: number, deleteCount?: number, ...items: T[]) => T[];
|
|
211
|
+
/**
|
|
212
|
+
* non-mutating `Array.prototype.fill()` as a standalone function
|
|
213
|
+
* @returns changed array copy
|
|
214
|
+
*/
|
|
215
|
+
declare const fill: <T>(list: readonly T[], value: T, start?: number, end?: number) => T[];
|
|
216
|
+
/**
|
|
217
|
+
* Creates a new array concatenating array with any additional arrays and/or values.
|
|
218
|
+
* @param ...a values or arrays
|
|
219
|
+
* @returns new concatenated array
|
|
220
|
+
*/
|
|
221
|
+
declare function concat<A extends any[], V extends ItemsOf<A>>(...a: A): Array<V extends any[] ? ItemsOf<V> : V>;
|
|
222
|
+
/**
|
|
223
|
+
* Remove item from array
|
|
224
|
+
* @returns changed array copy
|
|
225
|
+
*/
|
|
226
|
+
declare const remove: <T>(list: readonly T[], item: T, ...insertItems: T[]) => T[];
|
|
227
|
+
/**
|
|
228
|
+
* Remove multiple items from an array
|
|
229
|
+
* @returns changed array copy
|
|
230
|
+
*/
|
|
231
|
+
declare const removeItems: <T>(list: readonly T[], ...items: T[]) => T[];
|
|
232
|
+
/**
|
|
233
|
+
* Flattens a nested array into a one-level array
|
|
234
|
+
* @returns changed array copy
|
|
235
|
+
*/
|
|
236
|
+
declare const flatten: <T extends any[]>(arr: T) => FlattenArray<T>[];
|
|
237
|
+
/**
|
|
238
|
+
* Sort an array by object key, or multiple keys
|
|
239
|
+
* @returns changed array copy
|
|
240
|
+
*/
|
|
241
|
+
declare const sortBy: <T>(arr: T[], ...paths: T extends object ? (Many<keyof T> | Many<(item: T) => any>)[] : Many<(item: T) => any>[]) => T[];
|
|
242
|
+
/**
|
|
243
|
+
* Returns a subset of items that are instances of provided Classes
|
|
244
|
+
* @param list list of original items
|
|
245
|
+
* @param ...classes list or classes
|
|
246
|
+
* @returns changed array copy
|
|
247
|
+
*/
|
|
248
|
+
declare const filterInstance: <T, I extends AnyClass[]>(list: readonly T[], ...classes: I) => Extract<T, InstanceType<ItemsOf<I>>>[];
|
|
249
|
+
/**
|
|
250
|
+
* Returns a subset of items that aren't instances of provided Classes
|
|
251
|
+
* @param list list of original items
|
|
252
|
+
* @param ...classes list or classes
|
|
253
|
+
* @returns changed array copy
|
|
254
|
+
*/
|
|
255
|
+
declare const filterOutInstance: <T, I extends AnyClass[]>(list: readonly T[], ...classes: I) => Exclude<T, InstanceType<ItemsOf<I>>>[];
|
|
256
|
+
|
|
257
|
+
export { FlattenArray, MappingFn, ModifyValue, Predicate, Update, UpdateSetter, add, clamp, concat, divide, drop, dropRight, fill, filter, filterInstance, filterOut, filterOutInstance, flatten, get, map, merge, multiply, omit, pick, power, push, remove, removeItems, shallowArrayCopy, shallowCopy, shallowObjectCopy, slice, sort, sortBy, splice, split, substract, update, withArrayCopy, withCopy, withObjectCopy };
|
package/dist/immutable/index.js
CHANGED
|
@@ -62,11 +62,14 @@ var update = (...args) => withCopy(args[0], (obj) => {
|
|
|
62
62
|
|
|
63
63
|
// src/immutable/object.ts
|
|
64
64
|
var omit = (object, ...keys) => withObjectCopy(object, (object2) => keys.forEach((key) => delete object2[key]));
|
|
65
|
-
var pick = (object, ...keys) => keys.reduce(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
var pick = (object, ...keys) => keys.reduce(
|
|
66
|
+
(n, k) => {
|
|
67
|
+
if (k in object)
|
|
68
|
+
n[k] = object[k];
|
|
69
|
+
return n;
|
|
70
|
+
},
|
|
71
|
+
{}
|
|
72
|
+
);
|
|
70
73
|
function get(obj, ...keys) {
|
|
71
74
|
let res = obj;
|
|
72
75
|
for (const key of keys) {
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Accessor, AccessorArray, NoInfer, EffectFunction, onCleanup, SignalOptions, createSignal } from 'solid-js';
|
|
2
|
+
export { EffectOptions, OnOptions } from 'solid-js';
|
|
3
|
+
export { isServer } from 'solid-js/web';
|
|
4
|
+
import { N as Noop, A as AnyClass, a as AnyObject, M as MaybeAccessorValue, b as MaybeAccessor, c as AnyFunction } from '../types-d58cbe2f.js';
|
|
5
|
+
export { f as AccessReturnTypes, k as AnyStatic, i as DeepPartialAny, D as Directive, E as ExtractIfPossible, m as Falsy, F as FalsyValue, I as ItemsOf, e as ItemsOfMany, d as Many, g as Modify, h as ModifyDeep, r as Narrow, s as NoInfer, j as NonIterable, O as OnAccessEffectFunction, n as Position, P as PrimitiveValue, R as RequiredKeys, S as SetterParam, p as Simplify, o as Size, T as Tail, l as Truthy, q as UnboxLazy, U as UnionToIntersection, V as Values } from '../types-d58cbe2f.js';
|
|
6
|
+
export { ResolvedChildren, ResolvedJSXElement } from 'solid-js/types/reactive/signal.js';
|
|
7
|
+
|
|
8
|
+
declare const isClient: boolean;
|
|
9
|
+
declare const isDev: boolean;
|
|
10
|
+
declare const isProd: boolean;
|
|
11
|
+
/** no operation */
|
|
12
|
+
declare const noop: Noop;
|
|
13
|
+
declare const trueFn: () => boolean;
|
|
14
|
+
declare const falseFn: () => boolean;
|
|
15
|
+
/** @deprecated use {@link equalFn} from "solid-js" */
|
|
16
|
+
declare const defaultEquals: <T>(a: T, b: T) => boolean;
|
|
17
|
+
declare const EQUALS_FALSE_OPTIONS: {
|
|
18
|
+
readonly equals: false;
|
|
19
|
+
};
|
|
20
|
+
declare const INTERNAL_OPTIONS: {
|
|
21
|
+
readonly internal: true;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Check if the value is an instance of ___
|
|
25
|
+
*/
|
|
26
|
+
declare const ofClass: (v: any, c: AnyClass) => boolean;
|
|
27
|
+
/** Check if value is typeof "object" or "function" */
|
|
28
|
+
declare function isObject(value: any): value is AnyObject;
|
|
29
|
+
declare const isNonNullable: <T>(i: T) => i is NonNullable<T>;
|
|
30
|
+
declare const filterNonNullable: <T extends readonly unknown[]>(arr: T) => NonNullable<T[number]>[];
|
|
31
|
+
declare const compare: (a: any, b: any) => number;
|
|
32
|
+
/**
|
|
33
|
+
* Check shallow array equality
|
|
34
|
+
*/
|
|
35
|
+
declare const arrayEquals: (a: readonly unknown[], b: readonly unknown[]) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Returns a function that will call all functions in the order they were chained with the same arguments.
|
|
38
|
+
*/
|
|
39
|
+
declare function chain<Args extends [] | any[]>(callbacks: {
|
|
40
|
+
[Symbol.iterator](): IterableIterator<((...args: Args) => any) | undefined>;
|
|
41
|
+
}): (...args: Args) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Returns a function that will call all functions in the reversed order with the same arguments.
|
|
44
|
+
*/
|
|
45
|
+
declare function reverseChain<Args extends [] | any[]>(callbacks: (((...args: Args) => any) | undefined)[]): (...args: Args) => void;
|
|
46
|
+
declare const clamp: (n: number, min: number, max: number) => number;
|
|
47
|
+
/**
|
|
48
|
+
* Accesses the value of a MaybeAccessor
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* access("foo") // => "foo"
|
|
52
|
+
* access(() => "foo") // => "foo"
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare const access: <T extends unknown>(v: T) => MaybeAccessorValue<T>;
|
|
56
|
+
declare const asArray: <T>(value: T) => (T extends any[] ? T[number] : NonNullable<T>)[];
|
|
57
|
+
/**
|
|
58
|
+
* Access an array of MaybeAccessors
|
|
59
|
+
* @example
|
|
60
|
+
* const list = [1, 2, () => 3)] // T: MaybeAccessor<number>[]
|
|
61
|
+
* const newList = accessArray(list) // T: number[]
|
|
62
|
+
*/
|
|
63
|
+
declare const accessArray: <A extends unknown>(list: readonly A[]) => MaybeAccessorValue<A>[];
|
|
64
|
+
/**
|
|
65
|
+
* Run the function if the accessed value is not `undefined` nor `null`
|
|
66
|
+
* @param value
|
|
67
|
+
* @param fn
|
|
68
|
+
*/
|
|
69
|
+
declare const withAccess: <T, A extends MaybeAccessor<T>, V = MaybeAccessorValue<A>>(value: A, fn: (value: NonNullable<V>) => void) => void;
|
|
70
|
+
declare const asAccessor: <A extends unknown>(v: A) => Accessor<MaybeAccessorValue<A>>;
|
|
71
|
+
/** If value is a function – call it with a given arguments – otherwise get the value as is */
|
|
72
|
+
declare function accessWith<T>(valueOrFn: T, ...args: T extends AnyFunction ? Parameters<T> : never): T extends AnyFunction ? ReturnType<T> : T;
|
|
73
|
+
/**
|
|
74
|
+
* Solid's `on` helper, but always defers and returns a provided initial value when if does instead of `undefined`.
|
|
75
|
+
*
|
|
76
|
+
* @param deps
|
|
77
|
+
* @param fn
|
|
78
|
+
* @param initialValue
|
|
79
|
+
*/
|
|
80
|
+
declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: (input: S, prevInput: S, prev: undefined | NoInfer<Prev>) => Next, initialValue: Next): EffectFunction<undefined | NoInfer<Next>, NoInfer<Next>>;
|
|
81
|
+
declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: (input: S, prevInput: S, prev: undefined | NoInfer<Prev>) => Next, initialValue?: undefined): EffectFunction<undefined | NoInfer<Next>>;
|
|
82
|
+
/**
|
|
83
|
+
* Get entries of an object
|
|
84
|
+
*/
|
|
85
|
+
declare const entries: <T extends object>(obj: T) => [keyof T, T[keyof T]][];
|
|
86
|
+
/**
|
|
87
|
+
* Get keys of an object
|
|
88
|
+
*/
|
|
89
|
+
declare const keys: <T extends object>(object: T) => (keyof T)[];
|
|
90
|
+
/**
|
|
91
|
+
* Solid's `onCleanup` that doesn't warn in development if used outside of a component.
|
|
92
|
+
*/
|
|
93
|
+
declare const tryOnCleanup: typeof onCleanup;
|
|
94
|
+
declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {
|
|
95
|
+
push: (...callbacks: ((arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void)[]) => void;
|
|
96
|
+
execute: (arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void;
|
|
97
|
+
clear: VoidFunction;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Group synchronous function calls.
|
|
101
|
+
* @param fn
|
|
102
|
+
* @returns `fn`
|
|
103
|
+
*/
|
|
104
|
+
declare function createMicrotask<A extends any[] | []>(fn: (...a: A) => void): (...a: A) => void;
|
|
105
|
+
/**
|
|
106
|
+
* A hydratable version of the {@link createSignal}. It will use the serverValue on the server and the update function on the client. If initialized during hydration it will use serverValue as the initial value and update it once hydration is complete.
|
|
107
|
+
*
|
|
108
|
+
* @param serverValue initial value of the state on the server
|
|
109
|
+
* @param update called once on the client or on hydration to initialize the value
|
|
110
|
+
* @param options {@link SignalOptions}
|
|
111
|
+
* @returns
|
|
112
|
+
* ```ts
|
|
113
|
+
* [state: Accessor<T>, setState: Setter<T>]
|
|
114
|
+
* ```
|
|
115
|
+
* @see {@link createSignal}
|
|
116
|
+
*/
|
|
117
|
+
declare function createHydratableSignal<T>(serverValue: T, update: () => T, options?: SignalOptions<T>): ReturnType<typeof createSignal<T>>;
|
|
118
|
+
/** @deprecated use {@link createHydratableSignal} instead */
|
|
119
|
+
declare const createHydrateSignal: typeof createHydratableSignal;
|
|
120
|
+
/**
|
|
121
|
+
* Handle items removed and added to the array by diffing it by refference.
|
|
122
|
+
*
|
|
123
|
+
* @param current new array instance
|
|
124
|
+
* @param prev previous array copy
|
|
125
|
+
* @param handleAdded called once for every added item to array
|
|
126
|
+
* @param handleRemoved called once for every removed from array
|
|
127
|
+
*/
|
|
128
|
+
declare function handleDiffArray<T>(current: readonly T[], prev: readonly T[], handleAdded: (item: T) => void, handleRemoved: (item: T) => void): void;
|
|
129
|
+
|
|
130
|
+
export { AnyClass, AnyFunction, AnyObject, EQUALS_FALSE_OPTIONS, INTERNAL_OPTIONS, MaybeAccessor, MaybeAccessorValue, Noop, access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createHydratableSignal, createHydrateSignal, createMicrotask, defaultEquals, defer, entries, falseFn, filterNonNullable, handleDiffArray, isClient, isDev, isNonNullable, isObject, isProd, keys, noop, ofClass, reverseChain, trueFn, tryOnCleanup, withAccess };
|
package/dist/index/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Accessor, AccessorArray, NoInfer, EffectFunction, onCleanup, SignalOptions, createSignal } from 'solid-js';
|
|
2
|
+
export { EffectOptions, OnOptions } from 'solid-js';
|
|
2
3
|
export { isServer } from 'solid-js/web';
|
|
3
|
-
import { N as Noop, A as AnyClass, a as AnyObject, M as MaybeAccessorValue, b as MaybeAccessor, c as AnyFunction } from '../types-
|
|
4
|
-
export { f as AccessReturnTypes, k as AnyStatic, i as DeepPartialAny, D as Directive, E as ExtractIfPossible, m as Falsy, F as FalsyValue, I as ItemsOf, e as ItemsOfMany, d as Many, g as Modify, h as ModifyDeep, r as Narrow, s as NoInfer, j as NonIterable, O as OnAccessEffectFunction, n as Position, P as PrimitiveValue, R as RequiredKeys, S as SetterParam, p as Simplify, o as Size, T as Tail, l as Truthy, q as UnboxLazy, U as UnionToIntersection, V as Values } from '../types-
|
|
5
|
-
export {
|
|
4
|
+
import { N as Noop, A as AnyClass, a as AnyObject, M as MaybeAccessorValue, b as MaybeAccessor, c as AnyFunction } from '../types-d58cbe2f.js';
|
|
5
|
+
export { f as AccessReturnTypes, k as AnyStatic, i as DeepPartialAny, D as Directive, E as ExtractIfPossible, m as Falsy, F as FalsyValue, I as ItemsOf, e as ItemsOfMany, d as Many, g as Modify, h as ModifyDeep, r as Narrow, s as NoInfer, j as NonIterable, O as OnAccessEffectFunction, n as Position, P as PrimitiveValue, R as RequiredKeys, S as SetterParam, p as Simplify, o as Size, T as Tail, l as Truthy, q as UnboxLazy, U as UnionToIntersection, V as Values } from '../types-d58cbe2f.js';
|
|
6
|
+
export { ResolvedChildren, ResolvedJSXElement } from 'solid-js/types/reactive/signal.js';
|
|
6
7
|
|
|
7
8
|
declare const isClient: boolean;
|
|
8
9
|
declare const isDev: boolean;
|
|
@@ -84,7 +84,7 @@ type UnboxLazy<T> = T extends () => infer U ? U : T;
|
|
|
84
84
|
type RawNarrow<T> = (T extends [] ? [] : never) | (T extends string | number | bigint | boolean ? T : never) | {
|
|
85
85
|
[K in keyof T]: T[K] extends Function ? T[K] : RawNarrow<T[K]>;
|
|
86
86
|
};
|
|
87
|
-
type Narrow<T
|
|
87
|
+
type Narrow<T> = T extends [] ? T : RawNarrow<T>;
|
|
88
88
|
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
89
89
|
|
|
90
90
|
export { AnyClass as A, Directive as D, ExtractIfPossible as E, FalsyValue as F, ItemsOf as I, MaybeAccessorValue as M, Noop as N, OnAccessEffectFunction as O, PrimitiveValue as P, RequiredKeys as R, SetterParam as S, Tail as T, UnionToIntersection as U, Values as V, AnyObject as a, MaybeAccessor as b, AnyFunction as c, Many as d, ItemsOfMany as e, AccessReturnTypes as f, Modify as g, ModifyDeep as h, DeepPartialAny as i, NonIterable as j, AnyStatic as k, Truthy as l, Falsy as m, Position as n, Size as o, Simplify as p, UnboxLazy as q, Narrow as r, NoInfer as s };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solid-primitives/utils",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.3",
|
|
4
4
|
"description": "A bunch of reactive utility types and functions, for building primitives with Solid.js",
|
|
5
5
|
"author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",
|
|
6
6
|
"contributors": [
|
|
@@ -31,14 +31,20 @@
|
|
|
31
31
|
"types": "./dist/index/index.d.ts",
|
|
32
32
|
"default": "./dist/index/index.js"
|
|
33
33
|
},
|
|
34
|
-
"require":
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/index/index.d.cts",
|
|
36
|
+
"default": "./dist/index/index.cjs"
|
|
37
|
+
}
|
|
35
38
|
},
|
|
36
39
|
"./immutable": {
|
|
37
40
|
"import": {
|
|
38
41
|
"types": "./dist/immutable/index.d.ts",
|
|
39
42
|
"default": "./dist/immutable/index.js"
|
|
40
43
|
},
|
|
41
|
-
"require":
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/immutable/index.d.cts",
|
|
46
|
+
"default": "./dist/immutable/index.cjs"
|
|
47
|
+
}
|
|
42
48
|
}
|
|
43
49
|
},
|
|
44
50
|
"typesVersions": {
|
|
@@ -58,11 +64,11 @@
|
|
|
58
64
|
"solid-js": "^1.6.12"
|
|
59
65
|
},
|
|
60
66
|
"devDependencies": {
|
|
61
|
-
"solid-js": "1.7
|
|
67
|
+
"solid-js": "^1.8.7"
|
|
62
68
|
},
|
|
63
69
|
"scripts": {
|
|
64
|
-
"dev": "
|
|
65
|
-
"build": "
|
|
70
|
+
"dev": "tsx ../../scripts/dev.ts",
|
|
71
|
+
"build": "tsx ../../scripts/build.ts",
|
|
66
72
|
"vitest": "vitest -c ../../configs/vitest.config.ts",
|
|
67
73
|
"test": "pnpm run vitest",
|
|
68
74
|
"test:ssr": "pnpm run vitest --mode ssr"
|