@solid-primitives/utils 0.5.1 → 1.1.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 +4 -0
- package/dist/index.cjs +15 -88
- package/dist/index.d.ts +22 -101
- package/dist/index.js +7 -59
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<p>
|
|
2
|
+
<img width="100%" src="https://assets.solidjs.com/banner?type=Primitives&background=tiles&project=Utils" alt="Solid Primitives Utils">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# @solid-primitives/utils
|
|
2
6
|
|
|
3
7
|
Solid Primitives Utilities is a support and helper package for a number of primitives in our library. Please free to augment or centralize useful utilities and methods in this package for sharing.
|
package/dist/index.cjs
CHANGED
|
@@ -2,31 +2,25 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
6
5
|
var __export = (target, all) => {
|
|
7
6
|
for (var name in all)
|
|
8
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
8
|
};
|
|
10
|
-
var
|
|
11
|
-
if (
|
|
12
|
-
for (let key of __getOwnPropNames(
|
|
13
|
-
if (!__hasOwnProp.call(
|
|
14
|
-
__defProp(
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
14
|
}
|
|
16
|
-
return
|
|
15
|
+
return to;
|
|
17
16
|
};
|
|
18
|
-
var __toCommonJS =
|
|
19
|
-
return (module2, temp) => {
|
|
20
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
21
|
-
};
|
|
22
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
18
|
|
|
24
19
|
// src/index.ts
|
|
25
20
|
var src_exports = {};
|
|
26
21
|
__export(src_exports, {
|
|
27
22
|
access: () => access,
|
|
28
23
|
accessArray: () => accessArray,
|
|
29
|
-
accessAsArray: () => accessAsArray,
|
|
30
24
|
asAccessor: () => asAccessor,
|
|
31
25
|
asArray: () => asArray,
|
|
32
26
|
compare: () => compare,
|
|
@@ -35,87 +29,45 @@ __export(src_exports, {
|
|
|
35
29
|
createProxy: () => createProxy,
|
|
36
30
|
createTrigger: () => createTrigger,
|
|
37
31
|
createTriggerCache: () => createTriggerCache,
|
|
38
|
-
definite: () => definite,
|
|
39
|
-
destore: () => destore,
|
|
40
32
|
entries: () => entries,
|
|
41
|
-
forEach: () => forEach,
|
|
42
33
|
forEachEntry: () => forEachEntry,
|
|
43
|
-
includes: () => includes,
|
|
44
|
-
isArray: () => isArray,
|
|
45
|
-
isBoolean: () => isBoolean,
|
|
46
34
|
isClient: () => isClient,
|
|
47
|
-
isDefined: () => isDefined,
|
|
48
35
|
isDev: () => isDev,
|
|
49
|
-
isFunction: () => isFunction,
|
|
50
|
-
isNumber: () => isNumber,
|
|
51
|
-
isObject: () => isObject,
|
|
52
36
|
isProd: () => isProd,
|
|
53
37
|
isServer: () => import_web.isServer,
|
|
54
|
-
isString: () => isString,
|
|
55
38
|
keys: () => keys,
|
|
56
39
|
noop: () => noop,
|
|
57
40
|
ofClass: () => ofClass,
|
|
58
|
-
onAccess: () => onAccess,
|
|
59
41
|
onRootCleanup: () => onRootCleanup,
|
|
60
42
|
promiseTimeout: () => promiseTimeout,
|
|
61
43
|
raceTimeout: () => raceTimeout,
|
|
62
|
-
tuple: () => tuple,
|
|
63
44
|
warn: () => warn,
|
|
64
|
-
withAccess: () => withAccess
|
|
65
|
-
withFallback: () => withFallback,
|
|
66
|
-
withFallbackFn: () => withFallbackFn
|
|
45
|
+
withAccess: () => withAccess
|
|
67
46
|
});
|
|
47
|
+
module.exports = __toCommonJS(src_exports);
|
|
68
48
|
var import_solid_js = require("solid-js");
|
|
69
49
|
var import_web = require("solid-js/web");
|
|
70
50
|
var noop = () => void 0;
|
|
71
51
|
var isClient = !import_web.isServer;
|
|
72
|
-
var isDev = import_solid_js.DEV &&
|
|
52
|
+
var isDev = import_solid_js.DEV && isClient;
|
|
73
53
|
var isProd = !isDev;
|
|
74
54
|
var warn = (...a) => isDev && console.warn(...a);
|
|
75
|
-
var isDefined = (value) => typeof value !== "undefined" && value !== null;
|
|
76
|
-
var isFunction = (value) => typeof value === "function";
|
|
77
|
-
var isBoolean = (val) => typeof val === "boolean";
|
|
78
|
-
var isNumber = (val) => typeof val === "number";
|
|
79
|
-
var isString = (val) => typeof val === "string";
|
|
80
|
-
var isObject = (val) => toString.call(val) === "[object Object]";
|
|
81
|
-
var isArray = Array.isArray;
|
|
82
55
|
var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
|
|
83
56
|
var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
84
|
-
var
|
|
85
|
-
var definite = (v) => v;
|
|
86
|
-
function withFallback(v, fallback) {
|
|
87
|
-
return isDefined(v) ? v : fallback;
|
|
88
|
-
}
|
|
89
|
-
function withFallbackFn(v, fallback) {
|
|
90
|
-
return isDefined(v) ? v : fallback();
|
|
91
|
-
}
|
|
92
|
-
var includes = (arr, ...items) => {
|
|
93
|
-
for (const item of arr) {
|
|
94
|
-
if (items.includes(item))
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
return false;
|
|
98
|
-
};
|
|
99
|
-
var access = (v) => isFunction(v) ? v() : v;
|
|
100
|
-
var accessAsArray = (value) => asArray(access(value));
|
|
57
|
+
var access = (v) => typeof v === "function" && !v.length ? v() : v;
|
|
101
58
|
var asArray = (value) => Array.isArray(value) ? value : [value];
|
|
102
59
|
var accessArray = (list) => list.map((v) => access(v));
|
|
103
60
|
var withAccess = (value, fn) => {
|
|
104
61
|
const _value = access(value);
|
|
105
|
-
|
|
62
|
+
typeof _value !== "undefined" && _value !== null && fn(_value);
|
|
106
63
|
};
|
|
107
|
-
var asAccessor = (v) =>
|
|
108
|
-
function onAccess(deps, fn, options) {
|
|
109
|
-
const source = deps.map(asAccessor);
|
|
110
|
-
return (0, import_solid_js.on)(source, fn, options);
|
|
111
|
-
}
|
|
112
|
-
var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
|
|
64
|
+
var asAccessor = (v) => typeof v === "function" ? v : () => v;
|
|
113
65
|
var forEachEntry = (object, iterator) => {
|
|
114
66
|
const obj = access(object);
|
|
115
67
|
Object.entries(obj).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, obj));
|
|
116
68
|
};
|
|
117
69
|
var entries = (object) => Object.entries(access(object));
|
|
118
|
-
var keys =
|
|
70
|
+
var keys = Object.keys;
|
|
119
71
|
var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
|
|
120
72
|
function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
|
|
121
73
|
const promises = asArray(input);
|
|
@@ -126,14 +78,6 @@ function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
|
|
|
126
78
|
return race;
|
|
127
79
|
}
|
|
128
80
|
var onRootCleanup = (fn) => (0, import_solid_js.getOwner)() ? (0, import_solid_js.onCleanup)(fn) : fn;
|
|
129
|
-
function destore(store) {
|
|
130
|
-
const _store = store;
|
|
131
|
-
const result = {};
|
|
132
|
-
Object.keys(_store).forEach((key) => {
|
|
133
|
-
result[key] = isFunction(_store[key]) ? _store[key].bind(_store) : () => _store[key];
|
|
134
|
-
});
|
|
135
|
-
return result;
|
|
136
|
-
}
|
|
137
81
|
var createCallbackStack = () => {
|
|
138
82
|
let stack = [];
|
|
139
83
|
const clear = () => stack = [];
|
|
@@ -185,12 +129,10 @@ function createTriggerCache(options) {
|
|
|
185
129
|
}
|
|
186
130
|
};
|
|
187
131
|
}
|
|
188
|
-
module.exports = __toCommonJS(src_exports);
|
|
189
132
|
// Annotate the CommonJS export names for ESM import in node:
|
|
190
133
|
0 && (module.exports = {
|
|
191
134
|
access,
|
|
192
135
|
accessArray,
|
|
193
|
-
accessAsArray,
|
|
194
136
|
asAccessor,
|
|
195
137
|
asArray,
|
|
196
138
|
compare,
|
|
@@ -199,33 +141,18 @@ module.exports = __toCommonJS(src_exports);
|
|
|
199
141
|
createProxy,
|
|
200
142
|
createTrigger,
|
|
201
143
|
createTriggerCache,
|
|
202
|
-
definite,
|
|
203
|
-
destore,
|
|
204
144
|
entries,
|
|
205
|
-
forEach,
|
|
206
145
|
forEachEntry,
|
|
207
|
-
includes,
|
|
208
|
-
isArray,
|
|
209
|
-
isBoolean,
|
|
210
146
|
isClient,
|
|
211
|
-
isDefined,
|
|
212
147
|
isDev,
|
|
213
|
-
isFunction,
|
|
214
|
-
isNumber,
|
|
215
|
-
isObject,
|
|
216
148
|
isProd,
|
|
217
149
|
isServer,
|
|
218
|
-
isString,
|
|
219
150
|
keys,
|
|
220
151
|
noop,
|
|
221
152
|
ofClass,
|
|
222
|
-
onAccess,
|
|
223
153
|
onRootCleanup,
|
|
224
154
|
promiseTimeout,
|
|
225
155
|
raceTimeout,
|
|
226
|
-
tuple,
|
|
227
156
|
warn,
|
|
228
|
-
withAccess
|
|
229
|
-
withFallback,
|
|
230
|
-
withFallbackFn
|
|
157
|
+
withAccess
|
|
231
158
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { Accessor, onCleanup } from 'solid-js';
|
|
2
|
-
import {
|
|
3
|
-
import { Store } from 'solid-js/store';
|
|
2
|
+
import { BaseOptions } from 'solid-js/types/reactive/signal';
|
|
4
3
|
export { isServer } from 'solid-js/web';
|
|
5
4
|
|
|
6
|
-
/**
|
|
7
|
-
* A function
|
|
8
|
-
*/
|
|
9
|
-
declare type Fn<R = void> = () => R;
|
|
10
|
-
declare type Get<T> = (v: T) => void;
|
|
11
|
-
declare type Clear = () => void;
|
|
12
5
|
/**
|
|
13
6
|
* Can be single or in an array
|
|
14
7
|
*/
|
|
15
8
|
declare type Many<T> = T | T[];
|
|
16
|
-
declare type
|
|
17
|
-
declare type Values<O extends Object> = O[Keys<O>];
|
|
9
|
+
declare type Values<O extends Object> = O[keyof O];
|
|
18
10
|
declare type Noop = (...a: any[]) => void;
|
|
19
11
|
declare type Directive<P = true> = (el: Element, props: Accessor<P>) => void;
|
|
20
12
|
/**
|
|
@@ -38,7 +30,7 @@ declare type MaybeAccessor<T> = T | Accessor<T>;
|
|
|
38
30
|
* // => string | void
|
|
39
31
|
* ```
|
|
40
32
|
*/
|
|
41
|
-
declare type MaybeAccessorValue<T extends MaybeAccessor<any>> = T extends
|
|
33
|
+
declare type MaybeAccessorValue<T extends MaybeAccessor<any>> = T extends () => any ? ReturnType<T> : T;
|
|
42
34
|
declare type OnAccessEffectFunction<S, Prev, Next extends Prev = Prev> = (input: AccessReturnTypes<S>, prevInput: AccessReturnTypes<S>, v: Prev) => Next;
|
|
43
35
|
declare type AccessReturnTypes<S> = S extends MaybeAccessor<any>[] ? {
|
|
44
36
|
[I in keyof S]: AccessReturnTypes<S[I]>;
|
|
@@ -53,10 +45,18 @@ declare type ModifyDeep<A extends AnyObject, B extends DeepPartialAny<A>> = {
|
|
|
53
45
|
declare type DeepPartialAny<T> = {
|
|
54
46
|
[P in keyof T]?: T[P] extends AnyObject ? DeepPartialAny<T[P]> : any;
|
|
55
47
|
};
|
|
48
|
+
/** Removes the `[...list]` functionality */
|
|
49
|
+
declare type NonIterable<T> = T & {
|
|
50
|
+
[Symbol.iterator]: never;
|
|
51
|
+
};
|
|
52
|
+
/** An opposite of `Partial`. Makes all the keys required. */
|
|
53
|
+
declare type Definite<T> = {
|
|
54
|
+
[K in keyof T]-?: T[K];
|
|
55
|
+
};
|
|
56
56
|
/** `A | B => A & B` */
|
|
57
57
|
declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
58
58
|
declare type ExtractIfPossible<T, U> = Extract<T, U> extends never ? U : Extract<T, U>;
|
|
59
|
-
declare type AnyObject = Record<string, any>;
|
|
59
|
+
declare type AnyObject = Record<string | symbol | number, any>;
|
|
60
60
|
declare type AnyFunction = (...args: any[]) => any;
|
|
61
61
|
declare type AnyClass = abstract new (...args: any) => any;
|
|
62
62
|
declare type LiteralKey = string | number | symbol;
|
|
@@ -72,11 +72,11 @@ declare type Destore<T extends Object> = {
|
|
|
72
72
|
[K in keyof T]: T[K] extends Function ? T[K] : Accessor<T[K]>;
|
|
73
73
|
};
|
|
74
74
|
declare type TriggerCache<T> = {
|
|
75
|
-
track:
|
|
76
|
-
dirty:
|
|
77
|
-
dirtyAll:
|
|
75
|
+
track: (v: T) => void;
|
|
76
|
+
dirty: (v: T) => void;
|
|
77
|
+
dirtyAll: VoidFunction;
|
|
78
78
|
};
|
|
79
|
-
declare type Trigger = [track:
|
|
79
|
+
declare type Trigger = [track: VoidFunction, dirty: VoidFunction];
|
|
80
80
|
declare type Position = {
|
|
81
81
|
x: number;
|
|
82
82
|
y: number;
|
|
@@ -87,54 +87,16 @@ declare const noop: Noop;
|
|
|
87
87
|
declare const isClient = true;
|
|
88
88
|
|
|
89
89
|
/** development environment */
|
|
90
|
-
declare const isDev
|
|
90
|
+
declare const isDev = true;
|
|
91
91
|
/** production environment */
|
|
92
|
-
declare const isProd
|
|
92
|
+
declare const isProd = false;
|
|
93
93
|
/** `console.warn` only during development */
|
|
94
94
|
declare const warn: typeof console.warn;
|
|
95
|
-
/**
|
|
96
|
-
* `if (typeof value !== "undefined" && value !== null)`
|
|
97
|
-
*/
|
|
98
|
-
declare const isDefined: <T>(value: T | null | undefined) => value is T;
|
|
99
|
-
declare const isFunction: <T>(value: Function | T) => value is Function;
|
|
100
|
-
declare const isBoolean: (val: any) => val is boolean;
|
|
101
|
-
declare const isNumber: (val: any) => val is number;
|
|
102
|
-
declare const isString: (val: unknown) => val is string;
|
|
103
|
-
declare const isObject: (val: any) => val is object;
|
|
104
|
-
declare const isArray: (val: any) => val is any[];
|
|
105
95
|
/**
|
|
106
96
|
* Check if the value is an instance of ___
|
|
107
97
|
*/
|
|
108
98
|
declare const ofClass: (v: any, c: AnyClass) => boolean;
|
|
109
99
|
declare const compare: (a: any, b: any) => number;
|
|
110
|
-
/**
|
|
111
|
-
* for creating tuples by inferring type
|
|
112
|
-
* @example
|
|
113
|
-
* const users = tuple(["John", "Jeff", "Joe"]);
|
|
114
|
-
* users // T: [string, string, string]
|
|
115
|
-
*/
|
|
116
|
-
declare const tuple: <T extends any[] | []>(input: T) => T;
|
|
117
|
-
/**
|
|
118
|
-
* Removes the `null` and `undefined` from the type.
|
|
119
|
-
* @warning **Obviously use with caution**
|
|
120
|
-
*/
|
|
121
|
-
declare const definite: <T>(v: T) => NonNullable<T>;
|
|
122
|
-
/**
|
|
123
|
-
* Get the value if it is defined, or get the fallback otherwise
|
|
124
|
-
* @param v the value to check
|
|
125
|
-
* @param fallback the fallback value
|
|
126
|
-
*/
|
|
127
|
-
declare function withFallback<T>(v: T, fallback: NonNullable<T>): Fallback<T>;
|
|
128
|
-
declare function withFallback<T, F>(v: T, fallback: F): Fallback<T, F>;
|
|
129
|
-
/**
|
|
130
|
-
* Get the value if it is defined, or get the fallback otherwise
|
|
131
|
-
* @param v the value to check
|
|
132
|
-
* @param fallback function returning a fallback value
|
|
133
|
-
*/
|
|
134
|
-
declare function withFallbackFn<T>(v: T, fallback: () => NonNullable<T>): Fallback<T>;
|
|
135
|
-
declare function withFallbackFn<T, F>(v: T, fallback: () => F): Fallback<T, F>;
|
|
136
|
-
/** `Array.prototype.includes()` without so strict types. Also allows for checking for multiple items */
|
|
137
|
-
declare const includes: (arr: any[], ...items: any) => boolean;
|
|
138
100
|
/**
|
|
139
101
|
* Accesses the value of a MaybeAccessor
|
|
140
102
|
* @example
|
|
@@ -144,17 +106,6 @@ declare const includes: (arr: any[], ...items: any) => boolean;
|
|
|
144
106
|
* ```
|
|
145
107
|
*/
|
|
146
108
|
declare const access: <T extends unknown>(v: T) => MaybeAccessorValue<T>;
|
|
147
|
-
/**
|
|
148
|
-
* Accesses the value of a MaybeAccessor, but always returns an array
|
|
149
|
-
* @example
|
|
150
|
-
* ```ts
|
|
151
|
-
* accessAsArray('abc') // => ['abc']
|
|
152
|
-
* accessAsArray(() => 'abc') // => ['abc']
|
|
153
|
-
* accessAsArray([1,2,3]) // => [1,2,3]
|
|
154
|
-
* accessAsArray(() => [1,2,3]) // => [1,2,3]
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
declare const accessAsArray: <T extends unknown, V = MaybeAccessorValue<T>>(value: T) => V extends any[] ? V : V[];
|
|
158
109
|
declare const asArray: <T>(value: T) => T extends any[] ? T : T[];
|
|
159
110
|
/**
|
|
160
111
|
* Access an array of MaybeAccessors
|
|
@@ -170,18 +121,6 @@ declare const accessArray: <A extends unknown>(list: readonly A[]) => MaybeAcces
|
|
|
170
121
|
*/
|
|
171
122
|
declare const withAccess: <T, A extends MaybeAccessor<T>, V = MaybeAccessorValue<A>>(value: A, fn: (value: NonNullable<V>) => void) => void;
|
|
172
123
|
declare const asAccessor: <A extends unknown>(v: A) => Accessor<MaybeAccessorValue<A>>;
|
|
173
|
-
declare function onAccess<S extends MaybeAccessor<unknown>[] | [], Next, Init = unknown>(deps: S, fn: OnAccessEffectFunction<S, Init | Next, Next>, options?: OnOptions): EffectFunction<NoInfer<Init> | NoInfer<Next>, NoInfer<Next>>;
|
|
174
|
-
/**
|
|
175
|
-
* Quickly iterate over an MaybeAccessor<any>
|
|
176
|
-
*
|
|
177
|
-
* @example
|
|
178
|
-
* ```ts
|
|
179
|
-
* const myFunc = (source: MaybeAccessor<string[]>) => {
|
|
180
|
-
* forEach(source, item => console.log(item))
|
|
181
|
-
* }
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
|
-
declare const forEach: <A extends unknown, V = MaybeAccessorValue<A>>(array: A, iterator: (item: V extends any[] ? ItemsOf<V> : V, index: number, array: V extends any[] ? V : V[]) => void) => void;
|
|
185
124
|
/**
|
|
186
125
|
* Iterate through object entries.
|
|
187
126
|
*/
|
|
@@ -191,9 +130,9 @@ declare const forEachEntry: <A extends MaybeAccessor<object>, O = MaybeAccessorV
|
|
|
191
130
|
*/
|
|
192
131
|
declare const entries: <A extends MaybeAccessor<object>, O = MaybeAccessorValue<A>>(object: A) => [keyof O, Values<O>][];
|
|
193
132
|
/**
|
|
194
|
-
* Get
|
|
133
|
+
* Get keys of an object
|
|
195
134
|
*/
|
|
196
|
-
declare const keys: <
|
|
135
|
+
declare const keys: <T extends object>(object: T) => (keyof T)[];
|
|
197
136
|
/**
|
|
198
137
|
* Creates a promise that resolves *(or rejects)* after given time.
|
|
199
138
|
*
|
|
@@ -234,28 +173,10 @@ declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolea
|
|
|
234
173
|
* Solid's `onCleanup` that is registered only if there is a root.
|
|
235
174
|
*/
|
|
236
175
|
declare const onRootCleanup: typeof onCleanup;
|
|
237
|
-
/**
|
|
238
|
-
* Allows the Solid's store to be destructured
|
|
239
|
-
*
|
|
240
|
-
* @param store
|
|
241
|
-
* @returns Destructible object, with values changed to accessors
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* ```ts
|
|
245
|
-
* const [state, setState] = createStore({
|
|
246
|
-
* count: 0,
|
|
247
|
-
* get double() { return this.count * 2 },
|
|
248
|
-
* })
|
|
249
|
-
* const { count, double } = destore(state)
|
|
250
|
-
* // use it like a signal:
|
|
251
|
-
* count()
|
|
252
|
-
* ```
|
|
253
|
-
*/
|
|
254
|
-
declare function destore<T extends Object>(store: Store<T>): Destore<T>;
|
|
255
176
|
declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {
|
|
256
177
|
push: (...callbacks: ((arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void)[]) => void;
|
|
257
178
|
execute: (arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void;
|
|
258
|
-
clear:
|
|
179
|
+
clear: VoidFunction;
|
|
259
180
|
};
|
|
260
181
|
/**
|
|
261
182
|
* Group synchronous function calls.
|
|
@@ -302,4 +223,4 @@ declare function createTrigger(options?: BaseOptions): Trigger;
|
|
|
302
223
|
*/
|
|
303
224
|
declare function createTriggerCache<T>(options?: BaseOptions): TriggerCache<T>;
|
|
304
225
|
|
|
305
|
-
export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject,
|
|
226
|
+
export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, DeepPartialAny, Definite, Destore, Directive, ExtractIfPossible, Fallback, Falsy, FalsyValue, ItemsOf, ItemsOfMany, LiteralKey, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, Trigger, TriggerCache, Truthy, UnionToIntersection, Values, access, accessArray, asAccessor, asArray, compare, createCallbackStack, createMicrotask, createProxy, createTrigger, createTriggerCache, entries, forEachEntry, isClient, isDev, isProd, keys, noop, ofClass, onRootCleanup, promiseTimeout, raceTimeout, warn, withAccess };
|
package/dist/index.js
CHANGED
|
@@ -1,55 +1,27 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { getOwner, onCleanup,
|
|
2
|
+
import { getOwner, onCleanup, createSignal, DEV } from "solid-js";
|
|
3
3
|
import { isServer } from "solid-js/web";
|
|
4
4
|
var noop = () => void 0;
|
|
5
5
|
var isClient = !isServer;
|
|
6
|
-
var isDev = DEV &&
|
|
6
|
+
var isDev = DEV && isClient;
|
|
7
7
|
var isProd = !isDev;
|
|
8
8
|
var warn = (...a) => isDev && console.warn(...a);
|
|
9
|
-
var isDefined = (value) => typeof value !== "undefined" && value !== null;
|
|
10
|
-
var isFunction = (value) => typeof value === "function";
|
|
11
|
-
var isBoolean = (val) => typeof val === "boolean";
|
|
12
|
-
var isNumber = (val) => typeof val === "number";
|
|
13
|
-
var isString = (val) => typeof val === "string";
|
|
14
|
-
var isObject = (val) => toString.call(val) === "[object Object]";
|
|
15
|
-
var isArray = Array.isArray;
|
|
16
9
|
var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
|
|
17
10
|
var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
18
|
-
var
|
|
19
|
-
var definite = (v) => v;
|
|
20
|
-
function withFallback(v, fallback) {
|
|
21
|
-
return isDefined(v) ? v : fallback;
|
|
22
|
-
}
|
|
23
|
-
function withFallbackFn(v, fallback) {
|
|
24
|
-
return isDefined(v) ? v : fallback();
|
|
25
|
-
}
|
|
26
|
-
var includes = (arr, ...items) => {
|
|
27
|
-
for (const item of arr) {
|
|
28
|
-
if (items.includes(item))
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
};
|
|
33
|
-
var access = (v) => isFunction(v) ? v() : v;
|
|
34
|
-
var accessAsArray = (value) => asArray(access(value));
|
|
11
|
+
var access = (v) => typeof v === "function" && !v.length ? v() : v;
|
|
35
12
|
var asArray = (value) => Array.isArray(value) ? value : [value];
|
|
36
13
|
var accessArray = (list) => list.map((v) => access(v));
|
|
37
14
|
var withAccess = (value, fn) => {
|
|
38
15
|
const _value = access(value);
|
|
39
|
-
|
|
16
|
+
typeof _value !== "undefined" && _value !== null && fn(_value);
|
|
40
17
|
};
|
|
41
|
-
var asAccessor = (v) =>
|
|
42
|
-
function onAccess(deps, fn, options) {
|
|
43
|
-
const source = deps.map(asAccessor);
|
|
44
|
-
return on(source, fn, options);
|
|
45
|
-
}
|
|
46
|
-
var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
|
|
18
|
+
var asAccessor = (v) => typeof v === "function" ? v : () => v;
|
|
47
19
|
var forEachEntry = (object, iterator) => {
|
|
48
20
|
const obj = access(object);
|
|
49
21
|
Object.entries(obj).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, obj));
|
|
50
22
|
};
|
|
51
23
|
var entries = (object) => Object.entries(access(object));
|
|
52
|
-
var keys =
|
|
24
|
+
var keys = Object.keys;
|
|
53
25
|
var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
|
|
54
26
|
function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
|
|
55
27
|
const promises = asArray(input);
|
|
@@ -60,14 +32,6 @@ function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
|
|
|
60
32
|
return race;
|
|
61
33
|
}
|
|
62
34
|
var onRootCleanup = (fn) => getOwner() ? onCleanup(fn) : fn;
|
|
63
|
-
function destore(store) {
|
|
64
|
-
const _store = store;
|
|
65
|
-
const result = {};
|
|
66
|
-
Object.keys(_store).forEach((key) => {
|
|
67
|
-
result[key] = isFunction(_store[key]) ? _store[key].bind(_store) : () => _store[key];
|
|
68
|
-
});
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
35
|
var createCallbackStack = () => {
|
|
72
36
|
let stack = [];
|
|
73
37
|
const clear = () => stack = [];
|
|
@@ -122,7 +86,6 @@ function createTriggerCache(options) {
|
|
|
122
86
|
export {
|
|
123
87
|
access,
|
|
124
88
|
accessArray,
|
|
125
|
-
accessAsArray,
|
|
126
89
|
asAccessor,
|
|
127
90
|
asArray,
|
|
128
91
|
compare,
|
|
@@ -131,33 +94,18 @@ export {
|
|
|
131
94
|
createProxy,
|
|
132
95
|
createTrigger,
|
|
133
96
|
createTriggerCache,
|
|
134
|
-
definite,
|
|
135
|
-
destore,
|
|
136
97
|
entries,
|
|
137
|
-
forEach,
|
|
138
98
|
forEachEntry,
|
|
139
|
-
includes,
|
|
140
|
-
isArray,
|
|
141
|
-
isBoolean,
|
|
142
99
|
isClient,
|
|
143
|
-
isDefined,
|
|
144
100
|
isDev,
|
|
145
|
-
isFunction,
|
|
146
|
-
isNumber,
|
|
147
|
-
isObject,
|
|
148
101
|
isProd,
|
|
149
102
|
isServer,
|
|
150
|
-
isString,
|
|
151
103
|
keys,
|
|
152
104
|
noop,
|
|
153
105
|
ofClass,
|
|
154
|
-
onAccess,
|
|
155
106
|
onRootCleanup,
|
|
156
107
|
promiseTimeout,
|
|
157
108
|
raceTimeout,
|
|
158
|
-
tuple,
|
|
159
109
|
warn,
|
|
160
|
-
withAccess
|
|
161
|
-
withFallback,
|
|
162
|
-
withFallbackFn
|
|
110
|
+
withAccess
|
|
163
111
|
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solid-primitives/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
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
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://github.com/
|
|
7
|
+
"homepage": "https://github.com/solidjs-community/solid-primitives/tree/main/packages/utils#readme",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/
|
|
10
|
+
"url": "git+https://github.com/solidjs-community/solid-primitives.git"
|
|
11
11
|
},
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/solidjs-community/solid-primitives/issues"
|
|
14
14
|
},
|
|
15
15
|
"private": false,
|
|
16
16
|
"sideEffects": false,
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"primitives"
|
|
34
34
|
],
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"jsdom": "
|
|
36
|
+
"jsdom": "^19.0.0",
|
|
37
37
|
"prettier": "^2.5.1",
|
|
38
|
-
"solid-register": "^0.1.
|
|
38
|
+
"solid-register": "^0.1.5",
|
|
39
39
|
"tslib": "^2.3.1",
|
|
40
40
|
"tsup": "^5.11.0",
|
|
41
41
|
"uvu": "^0.5.2",
|