@solid-primitives/utils 0.5.2 → 1.2.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 +16 -90
- package/dist/index.d.ts +20 -99
- package/dist/index.js +8 -61
- 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,85 +29,42 @@ __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
|
|
109
|
-
|
|
110
|
-
return (0, import_solid_js.on)(source, fn, options);
|
|
64
|
+
var asAccessor = (v) => typeof v === "function" ? v : () => v;
|
|
65
|
+
function forEachEntry(object, iterator) {
|
|
66
|
+
Object.entries(object).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, object));
|
|
111
67
|
}
|
|
112
|
-
var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
|
|
113
|
-
var forEachEntry = (object, iterator) => {
|
|
114
|
-
const obj = access(object);
|
|
115
|
-
Object.entries(obj).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, obj));
|
|
116
|
-
};
|
|
117
68
|
var entries = (object) => Object.entries(access(object));
|
|
118
69
|
var keys = Object.keys;
|
|
119
70
|
var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
|
|
@@ -126,14 +77,6 @@ function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
|
|
|
126
77
|
return race;
|
|
127
78
|
}
|
|
128
79
|
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
80
|
var createCallbackStack = () => {
|
|
138
81
|
let stack = [];
|
|
139
82
|
const clear = () => stack = [];
|
|
@@ -185,12 +128,10 @@ function createTriggerCache(options) {
|
|
|
185
128
|
}
|
|
186
129
|
};
|
|
187
130
|
}
|
|
188
|
-
module.exports = __toCommonJS(src_exports);
|
|
189
131
|
// Annotate the CommonJS export names for ESM import in node:
|
|
190
132
|
0 && (module.exports = {
|
|
191
133
|
access,
|
|
192
134
|
accessArray,
|
|
193
|
-
accessAsArray,
|
|
194
135
|
asAccessor,
|
|
195
136
|
asArray,
|
|
196
137
|
compare,
|
|
@@ -199,33 +140,18 @@ module.exports = __toCommonJS(src_exports);
|
|
|
199
140
|
createProxy,
|
|
200
141
|
createTrigger,
|
|
201
142
|
createTriggerCache,
|
|
202
|
-
definite,
|
|
203
|
-
destore,
|
|
204
143
|
entries,
|
|
205
|
-
forEach,
|
|
206
144
|
forEachEntry,
|
|
207
|
-
includes,
|
|
208
|
-
isArray,
|
|
209
|
-
isBoolean,
|
|
210
145
|
isClient,
|
|
211
|
-
isDefined,
|
|
212
146
|
isDev,
|
|
213
|
-
isFunction,
|
|
214
|
-
isNumber,
|
|
215
|
-
isObject,
|
|
216
147
|
isProd,
|
|
217
148
|
isServer,
|
|
218
|
-
isString,
|
|
219
149
|
keys,
|
|
220
150
|
noop,
|
|
221
151
|
ofClass,
|
|
222
|
-
onAccess,
|
|
223
152
|
onRootCleanup,
|
|
224
153
|
promiseTimeout,
|
|
225
154
|
raceTimeout,
|
|
226
|
-
tuple,
|
|
227
155
|
warn,
|
|
228
|
-
withAccess
|
|
229
|
-
withFallback,
|
|
230
|
-
withFallbackFn
|
|
156
|
+
withAccess
|
|
231
157
|
});
|
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
|
/**
|
|
@@ -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,22 +121,10 @@ 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
|
*/
|
|
188
|
-
declare
|
|
127
|
+
declare function forEachEntry<O extends AnyObject>(object: O, iterator: (key: keyof O, item: Values<O>, index: number, pairs: [keyof O, Values<O>][], object: O) => void): void;
|
|
189
128
|
/**
|
|
190
129
|
* Get `Object.entries()` of an MaybeAccessor<object>
|
|
191
130
|
*/
|
|
@@ -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,53 +1,24 @@
|
|
|
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
|
|
43
|
-
|
|
44
|
-
return on(source, fn, options);
|
|
18
|
+
var asAccessor = (v) => typeof v === "function" ? v : () => v;
|
|
19
|
+
function forEachEntry(object, iterator) {
|
|
20
|
+
Object.entries(object).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, object));
|
|
45
21
|
}
|
|
46
|
-
var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
|
|
47
|
-
var forEachEntry = (object, iterator) => {
|
|
48
|
-
const obj = access(object);
|
|
49
|
-
Object.entries(obj).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, obj));
|
|
50
|
-
};
|
|
51
22
|
var entries = (object) => Object.entries(access(object));
|
|
52
23
|
var keys = Object.keys;
|
|
53
24
|
var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
|
|
@@ -60,14 +31,6 @@ function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
|
|
|
60
31
|
return race;
|
|
61
32
|
}
|
|
62
33
|
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
34
|
var createCallbackStack = () => {
|
|
72
35
|
let stack = [];
|
|
73
36
|
const clear = () => stack = [];
|
|
@@ -122,7 +85,6 @@ function createTriggerCache(options) {
|
|
|
122
85
|
export {
|
|
123
86
|
access,
|
|
124
87
|
accessArray,
|
|
125
|
-
accessAsArray,
|
|
126
88
|
asAccessor,
|
|
127
89
|
asArray,
|
|
128
90
|
compare,
|
|
@@ -131,33 +93,18 @@ export {
|
|
|
131
93
|
createProxy,
|
|
132
94
|
createTrigger,
|
|
133
95
|
createTriggerCache,
|
|
134
|
-
definite,
|
|
135
|
-
destore,
|
|
136
96
|
entries,
|
|
137
|
-
forEach,
|
|
138
97
|
forEachEntry,
|
|
139
|
-
includes,
|
|
140
|
-
isArray,
|
|
141
|
-
isBoolean,
|
|
142
98
|
isClient,
|
|
143
|
-
isDefined,
|
|
144
99
|
isDev,
|
|
145
|
-
isFunction,
|
|
146
|
-
isNumber,
|
|
147
|
-
isObject,
|
|
148
100
|
isProd,
|
|
149
101
|
isServer,
|
|
150
|
-
isString,
|
|
151
102
|
keys,
|
|
152
103
|
noop,
|
|
153
104
|
ofClass,
|
|
154
|
-
onAccess,
|
|
155
105
|
onRootCleanup,
|
|
156
106
|
promiseTimeout,
|
|
157
107
|
raceTimeout,
|
|
158
|
-
tuple,
|
|
159
108
|
warn,
|
|
160
|
-
withAccess
|
|
161
|
-
withFallback,
|
|
162
|
-
withFallbackFn
|
|
109
|
+
withAccess
|
|
163
110
|
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solid-primitives/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.2.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",
|