@solid-primitives/utils 0.5.3 → 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 +14 -87
- package/dist/index.d.ts +10 -97
- package/dist/index.js +6 -58
- package/package.json +7 -7
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,81 +29,39 @@ __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.length ? 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));
|
|
@@ -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
|
/**
|
|
@@ -80,11 +72,11 @@ declare type Destore<T extends Object> = {
|
|
|
80
72
|
[K in keyof T]: T[K] extends Function ? T[K] : Accessor<T[K]>;
|
|
81
73
|
};
|
|
82
74
|
declare type TriggerCache<T> = {
|
|
83
|
-
track:
|
|
84
|
-
dirty:
|
|
85
|
-
dirtyAll:
|
|
75
|
+
track: (v: T) => void;
|
|
76
|
+
dirty: (v: T) => void;
|
|
77
|
+
dirtyAll: VoidFunction;
|
|
86
78
|
};
|
|
87
|
-
declare type Trigger = [track:
|
|
79
|
+
declare type Trigger = [track: VoidFunction, dirty: VoidFunction];
|
|
88
80
|
declare type Position = {
|
|
89
81
|
x: number;
|
|
90
82
|
y: number;
|
|
@@ -95,54 +87,16 @@ declare const noop: Noop;
|
|
|
95
87
|
declare const isClient = true;
|
|
96
88
|
|
|
97
89
|
/** development environment */
|
|
98
|
-
declare const isDev
|
|
90
|
+
declare const isDev = true;
|
|
99
91
|
/** production environment */
|
|
100
|
-
declare const isProd
|
|
92
|
+
declare const isProd = false;
|
|
101
93
|
/** `console.warn` only during development */
|
|
102
94
|
declare const warn: typeof console.warn;
|
|
103
|
-
/**
|
|
104
|
-
* `if (typeof value !== "undefined" && value !== null)`
|
|
105
|
-
*/
|
|
106
|
-
declare const isDefined: <T>(value: T | null | undefined) => value is T;
|
|
107
|
-
declare const isFunction: <T>(value: Function | T) => value is Function;
|
|
108
|
-
declare const isBoolean: (val: any) => val is boolean;
|
|
109
|
-
declare const isNumber: (val: any) => val is number;
|
|
110
|
-
declare const isString: (val: unknown) => val is string;
|
|
111
|
-
declare const isObject: (val: any) => val is object;
|
|
112
|
-
declare const isArray: (val: any) => val is any[];
|
|
113
95
|
/**
|
|
114
96
|
* Check if the value is an instance of ___
|
|
115
97
|
*/
|
|
116
98
|
declare const ofClass: (v: any, c: AnyClass) => boolean;
|
|
117
99
|
declare const compare: (a: any, b: any) => number;
|
|
118
|
-
/**
|
|
119
|
-
* for creating tuples by inferring type
|
|
120
|
-
* @example
|
|
121
|
-
* const users = tuple(["John", "Jeff", "Joe"]);
|
|
122
|
-
* users // T: [string, string, string]
|
|
123
|
-
*/
|
|
124
|
-
declare const tuple: <T extends any[] | []>(input: T) => T;
|
|
125
|
-
/**
|
|
126
|
-
* Removes the `null` and `undefined` from the type.
|
|
127
|
-
* @warning **Obviously use with caution**
|
|
128
|
-
*/
|
|
129
|
-
declare const definite: <T>(v: T) => NonNullable<T>;
|
|
130
|
-
/**
|
|
131
|
-
* Get the value if it is defined, or get the fallback otherwise
|
|
132
|
-
* @param v the value to check
|
|
133
|
-
* @param fallback the fallback value
|
|
134
|
-
*/
|
|
135
|
-
declare function withFallback<T>(v: T, fallback: NonNullable<T>): Fallback<T>;
|
|
136
|
-
declare function withFallback<T, F>(v: T, fallback: F): Fallback<T, F>;
|
|
137
|
-
/**
|
|
138
|
-
* Get the value if it is defined, or get the fallback otherwise
|
|
139
|
-
* @param v the value to check
|
|
140
|
-
* @param fallback function returning a fallback value
|
|
141
|
-
*/
|
|
142
|
-
declare function withFallbackFn<T>(v: T, fallback: () => NonNullable<T>): Fallback<T>;
|
|
143
|
-
declare function withFallbackFn<T, F>(v: T, fallback: () => F): Fallback<T, F>;
|
|
144
|
-
/** `Array.prototype.includes()` without so strict types. Also allows for checking for multiple items */
|
|
145
|
-
declare const includes: (arr: any[], ...items: any) => boolean;
|
|
146
100
|
/**
|
|
147
101
|
* Accesses the value of a MaybeAccessor
|
|
148
102
|
* @example
|
|
@@ -152,17 +106,6 @@ declare const includes: (arr: any[], ...items: any) => boolean;
|
|
|
152
106
|
* ```
|
|
153
107
|
*/
|
|
154
108
|
declare const access: <T extends unknown>(v: T) => MaybeAccessorValue<T>;
|
|
155
|
-
/**
|
|
156
|
-
* Accesses the value of a MaybeAccessor, but always returns an array
|
|
157
|
-
* @example
|
|
158
|
-
* ```ts
|
|
159
|
-
* accessAsArray('abc') // => ['abc']
|
|
160
|
-
* accessAsArray(() => 'abc') // => ['abc']
|
|
161
|
-
* accessAsArray([1,2,3]) // => [1,2,3]
|
|
162
|
-
* accessAsArray(() => [1,2,3]) // => [1,2,3]
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
declare const accessAsArray: <T extends unknown, V = MaybeAccessorValue<T>>(value: T) => V extends any[] ? V : V[];
|
|
166
109
|
declare const asArray: <T>(value: T) => T extends any[] ? T : T[];
|
|
167
110
|
/**
|
|
168
111
|
* Access an array of MaybeAccessors
|
|
@@ -178,18 +121,6 @@ declare const accessArray: <A extends unknown>(list: readonly A[]) => MaybeAcces
|
|
|
178
121
|
*/
|
|
179
122
|
declare const withAccess: <T, A extends MaybeAccessor<T>, V = MaybeAccessorValue<A>>(value: A, fn: (value: NonNullable<V>) => void) => void;
|
|
180
123
|
declare const asAccessor: <A extends unknown>(v: A) => Accessor<MaybeAccessorValue<A>>;
|
|
181
|
-
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>>;
|
|
182
|
-
/**
|
|
183
|
-
* Quickly iterate over an MaybeAccessor<any>
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* ```ts
|
|
187
|
-
* const myFunc = (source: MaybeAccessor<string[]>) => {
|
|
188
|
-
* forEach(source, item => console.log(item))
|
|
189
|
-
* }
|
|
190
|
-
* ```
|
|
191
|
-
*/
|
|
192
|
-
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;
|
|
193
124
|
/**
|
|
194
125
|
* Iterate through object entries.
|
|
195
126
|
*/
|
|
@@ -242,28 +173,10 @@ declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolea
|
|
|
242
173
|
* Solid's `onCleanup` that is registered only if there is a root.
|
|
243
174
|
*/
|
|
244
175
|
declare const onRootCleanup: typeof onCleanup;
|
|
245
|
-
/**
|
|
246
|
-
* Allows the Solid's store to be destructured
|
|
247
|
-
*
|
|
248
|
-
* @param store
|
|
249
|
-
* @returns Destructible object, with values changed to accessors
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* ```ts
|
|
253
|
-
* const [state, setState] = createStore({
|
|
254
|
-
* count: 0,
|
|
255
|
-
* get double() { return this.count * 2 },
|
|
256
|
-
* })
|
|
257
|
-
* const { count, double } = destore(state)
|
|
258
|
-
* // use it like a signal:
|
|
259
|
-
* count()
|
|
260
|
-
* ```
|
|
261
|
-
*/
|
|
262
|
-
declare function destore<T extends Object>(store: Store<T>): Destore<T>;
|
|
263
176
|
declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {
|
|
264
177
|
push: (...callbacks: ((arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void)[]) => void;
|
|
265
178
|
execute: (arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void;
|
|
266
|
-
clear:
|
|
179
|
+
clear: VoidFunction;
|
|
267
180
|
};
|
|
268
181
|
/**
|
|
269
182
|
* Group synchronous function calls.
|
|
@@ -310,4 +223,4 @@ declare function createTrigger(options?: BaseOptions): Trigger;
|
|
|
310
223
|
*/
|
|
311
224
|
declare function createTriggerCache<T>(options?: BaseOptions): TriggerCache<T>;
|
|
312
225
|
|
|
313
|
-
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,49 +1,21 @@
|
|
|
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.length ? 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));
|
|
@@ -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",
|
|
@@ -44,4 +44,4 @@
|
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"solid-js": "^1.3.1"
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|