@solid-primitives/utils 0.5.3 → 1.3.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 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,26 @@ 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 __reExport = (target, module2, copyDefault, desc) => {
11
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
12
- for (let key of __getOwnPropNames(module2))
13
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
14
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
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 target;
15
+ return to;
17
16
  };
18
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
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,
24
+ accessWith: () => accessWith,
30
25
  asAccessor: () => asAccessor,
31
26
  asArray: () => asArray,
32
27
  compare: () => compare,
@@ -35,85 +30,49 @@ __export(src_exports, {
35
30
  createProxy: () => createProxy,
36
31
  createTrigger: () => createTrigger,
37
32
  createTriggerCache: () => createTriggerCache,
38
- definite: () => definite,
39
- destore: () => destore,
40
33
  entries: () => entries,
41
- forEach: () => forEach,
42
34
  forEachEntry: () => forEachEntry,
43
- includes: () => includes,
44
- isArray: () => isArray,
45
- isBoolean: () => isBoolean,
46
35
  isClient: () => isClient,
47
- isDefined: () => isDefined,
48
36
  isDev: () => isDev,
49
- isFunction: () => isFunction,
50
- isNumber: () => isNumber,
51
37
  isObject: () => isObject,
52
38
  isProd: () => isProd,
53
39
  isServer: () => import_web.isServer,
54
- isString: () => isString,
55
40
  keys: () => keys,
56
41
  noop: () => noop,
57
42
  ofClass: () => ofClass,
58
- onAccess: () => onAccess,
59
43
  onRootCleanup: () => onRootCleanup,
60
44
  promiseTimeout: () => promiseTimeout,
61
45
  raceTimeout: () => raceTimeout,
62
- tuple: () => tuple,
63
46
  warn: () => warn,
64
- withAccess: () => withAccess,
65
- withFallback: () => withFallback,
66
- withFallbackFn: () => withFallbackFn
47
+ withAccess: () => withAccess
67
48
  });
49
+ module.exports = __toCommonJS(src_exports);
68
50
  var import_solid_js = require("solid-js");
69
51
  var import_web = require("solid-js/web");
70
52
  var noop = () => void 0;
71
53
  var isClient = !import_web.isServer;
72
- var isDev = import_solid_js.DEV && import_solid_js.DEV.hasOwnProperty("writeSignal");
54
+ var isDev = import_solid_js.DEV && isClient;
73
55
  var isProd = !isDev;
74
56
  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
57
  var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
83
- var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
84
- var tuple = (input) => input;
85
- var definite = (v) => v;
86
- function withFallback(v, fallback) {
87
- return isDefined(v) ? v : fallback;
58
+ function isObject(value) {
59
+ return value !== null && (typeof value === "object" || typeof value === "function");
88
60
  }
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));
61
+ var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
62
+ var access = (v) => typeof v === "function" && !v.length ? v() : v;
101
63
  var asArray = (value) => Array.isArray(value) ? value : [value];
102
64
  var accessArray = (list) => list.map((v) => access(v));
103
65
  var withAccess = (value, fn) => {
104
66
  const _value = access(value);
105
- isDefined(_value) && fn(_value);
67
+ typeof _value !== "undefined" && _value !== null && fn(_value);
106
68
  };
107
- var asAccessor = (v) => isFunction(v) ? v : () => v;
108
- function onAccess(deps, fn, options) {
109
- const source = deps.map(asAccessor);
110
- return (0, import_solid_js.on)(source, fn, options);
69
+ var asAccessor = (v) => typeof v === "function" ? v : () => v;
70
+ function accessWith(valueOrFn, ...args) {
71
+ return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
72
+ }
73
+ function forEachEntry(object, iterator) {
74
+ Object.entries(object).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, object));
111
75
  }
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
76
  var entries = (object) => Object.entries(access(object));
118
77
  var keys = Object.keys;
119
78
  var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
@@ -126,14 +85,6 @@ function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
126
85
  return race;
127
86
  }
128
87
  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
88
  var createCallbackStack = () => {
138
89
  let stack = [];
139
90
  const clear = () => stack = [];
@@ -185,12 +136,11 @@ function createTriggerCache(options) {
185
136
  }
186
137
  };
187
138
  }
188
- module.exports = __toCommonJS(src_exports);
189
139
  // Annotate the CommonJS export names for ESM import in node:
190
140
  0 && (module.exports = {
191
141
  access,
192
142
  accessArray,
193
- accessAsArray,
143
+ accessWith,
194
144
  asAccessor,
195
145
  asArray,
196
146
  compare,
@@ -199,33 +149,19 @@ module.exports = __toCommonJS(src_exports);
199
149
  createProxy,
200
150
  createTrigger,
201
151
  createTriggerCache,
202
- definite,
203
- destore,
204
152
  entries,
205
- forEach,
206
153
  forEachEntry,
207
- includes,
208
- isArray,
209
- isBoolean,
210
154
  isClient,
211
- isDefined,
212
155
  isDev,
213
- isFunction,
214
- isNumber,
215
156
  isObject,
216
157
  isProd,
217
158
  isServer,
218
- isString,
219
159
  keys,
220
160
  noop,
221
161
  ofClass,
222
- onAccess,
223
162
  onRootCleanup,
224
163
  promiseTimeout,
225
164
  raceTimeout,
226
- tuple,
227
165
  warn,
228
- withAccess,
229
- withFallback,
230
- withFallbackFn
166
+ withAccess
231
167
  });
package/dist/index.d.ts CHANGED
@@ -1,20 +1,12 @@
1
- import { Accessor, onCleanup } from 'solid-js';
2
- import { OnOptions, EffectFunction, NoInfer, BaseOptions } from 'solid-js/types/reactive/signal';
3
- import { Store } from 'solid-js/store';
1
+ import { Accessor, Setter, onCleanup } from 'solid-js';
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 Keys<O extends Object> = keyof O;
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
  /**
@@ -22,6 +14,7 @@ declare type Directive<P = true> = (el: Element, props: Accessor<P>) => void;
22
14
  */
23
15
  declare type ItemsOf<T> = T extends (infer E)[] ? E : never;
24
16
  declare type ItemsOfMany<T> = T extends any[] ? ItemsOf<T> : T;
17
+ declare type SetterValue<T> = Parameters<Setter<T>>[0];
25
18
  /**
26
19
  * T or a reactive/non-reactive function returning T
27
20
  */
@@ -64,27 +57,20 @@ declare type Definite<T> = {
64
57
  /** `A | B => A & B` */
65
58
  declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
66
59
  declare type ExtractIfPossible<T, U> = Extract<T, U> extends never ? U : Extract<T, U>;
67
- declare type AnyObject = Record<string | symbol | number, any>;
60
+ declare type AnyObject = Record<PropertyKey, any>;
61
+ declare type AnyStatic = [] | any[] | AnyObject;
68
62
  declare type AnyFunction = (...args: any[]) => any;
69
63
  declare type AnyClass = abstract new (...args: any) => any;
70
- declare type LiteralKey = string | number | symbol;
71
- declare type PrimitiveValue = string | boolean | number | bigint | symbol | null | undefined;
64
+ declare type PrimitiveValue = PropertyKey | boolean | bigint | null | undefined;
72
65
  declare type FalsyValue = false | 0 | "" | null | undefined;
73
66
  declare type Truthy<T> = Exclude<T, FalsyValue>;
74
67
  declare type Falsy<T> = Extract<T, FalsyValue>;
75
- declare type Fallback<T, F = NonNullable<T>> = NonNullable<T> | F;
76
- /**
77
- * Destructible store object, with values changed to accessors
78
- */
79
- declare type Destore<T extends Object> = {
80
- [K in keyof T]: T[K] extends Function ? T[K] : Accessor<T[K]>;
81
- };
82
68
  declare type TriggerCache<T> = {
83
- track: Get<T>;
84
- dirty: Get<T>;
85
- dirtyAll: Fn;
69
+ track: (v: T) => void;
70
+ dirty: (v: T) => void;
71
+ dirtyAll: VoidFunction;
86
72
  };
87
- declare type Trigger = [track: Fn, dirty: Fn];
73
+ declare type Trigger = [track: VoidFunction, dirty: VoidFunction];
88
74
  declare type Position = {
89
75
  x: number;
90
76
  y: number;
@@ -95,54 +81,18 @@ declare const noop: Noop;
95
81
  declare const isClient = true;
96
82
 
97
83
  /** development environment */
98
- declare const isDev: boolean;
84
+ declare const isDev = true;
99
85
  /** production environment */
100
- declare const isProd: boolean;
86
+ declare const isProd = false;
101
87
  /** `console.warn` only during development */
102
88
  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
89
  /**
114
90
  * Check if the value is an instance of ___
115
91
  */
116
92
  declare const ofClass: (v: any, c: AnyClass) => boolean;
93
+ /** Check if value is typeof "object" or "function" */
94
+ declare function isObject(value: any): value is AnyObject;
117
95
  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
96
  /**
147
97
  * Accesses the value of a MaybeAccessor
148
98
  * @example
@@ -152,17 +102,6 @@ declare const includes: (arr: any[], ...items: any) => boolean;
152
102
  * ```
153
103
  */
154
104
  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
105
  declare const asArray: <T>(value: T) => T extends any[] ? T : T[];
167
106
  /**
168
107
  * Access an array of MaybeAccessors
@@ -178,22 +117,12 @@ declare const accessArray: <A extends unknown>(list: readonly A[]) => MaybeAcces
178
117
  */
179
118
  declare const withAccess: <T, A extends MaybeAccessor<T>, V = MaybeAccessorValue<A>>(value: A, fn: (value: NonNullable<V>) => void) => void;
180
119
  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;
120
+ /** If value is a function – call it with a given arguments – otherwise get the value as is */
121
+ declare function accessWith<T>(valueOrFn: T, ...args: T extends AnyFunction ? Parameters<T> : never): T extends AnyFunction ? ReturnType<T> : T;
193
122
  /**
194
123
  * Iterate through object entries.
195
124
  */
196
- declare const forEachEntry: <A extends MaybeAccessor<object>, O = MaybeAccessorValue<A>>(object: A, iterator: (key: keyof O, item: Values<O>, index: number, pairs: [keyof O, Values<O>][], object: O) => void) => void;
125
+ 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;
197
126
  /**
198
127
  * Get `Object.entries()` of an MaybeAccessor<object>
199
128
  */
@@ -242,28 +171,10 @@ declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolea
242
171
  * Solid's `onCleanup` that is registered only if there is a root.
243
172
  */
244
173
  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
174
  declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {
264
175
  push: (...callbacks: ((arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void)[]) => void;
265
176
  execute: (arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void;
266
- clear: Fn;
177
+ clear: VoidFunction;
267
178
  };
268
179
  /**
269
180
  * Group synchronous function calls.
@@ -310,4 +221,4 @@ declare function createTrigger(options?: BaseOptions): Trigger;
310
221
  */
311
222
  declare function createTriggerCache<T>(options?: BaseOptions): TriggerCache<T>;
312
223
 
313
- export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, Clear, DeepPartialAny, Definite, Destore, Directive, ExtractIfPossible, Fallback, Falsy, FalsyValue, Fn, Get, ItemsOf, ItemsOfMany, Keys, LiteralKey, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, Trigger, TriggerCache, Truthy, UnionToIntersection, Values, access, accessArray, accessAsArray, asAccessor, asArray, compare, createCallbackStack, createMicrotask, createProxy, createTrigger, createTriggerCache, definite, destore, entries, forEach, forEachEntry, includes, isArray, isBoolean, isClient, isDefined, isDev, isFunction, isNumber, isObject, isProd, isString, keys, noop, ofClass, onAccess, onRootCleanup, promiseTimeout, raceTimeout, tuple, warn, withAccess, withFallback, withFallbackFn };
224
+ export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Definite, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, SetterValue, Trigger, TriggerCache, Truthy, UnionToIntersection, Values, access, accessArray, accessWith, asAccessor, asArray, compare, createCallbackStack, createMicrotask, createProxy, createTrigger, createTriggerCache, entries, forEachEntry, isClient, isDev, isObject, isProd, keys, noop, ofClass, onRootCleanup, promiseTimeout, raceTimeout, warn, withAccess };
package/dist/index.js CHANGED
@@ -1,53 +1,30 @@
1
1
  // src/index.ts
2
- import { getOwner, onCleanup, on, createSignal, DEV } from "solid-js";
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 && DEV.hasOwnProperty("writeSignal");
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
- var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
18
- var tuple = (input) => input;
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();
10
+ function isObject(value) {
11
+ return value !== null && (typeof value === "object" || typeof value === "function");
25
12
  }
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));
13
+ var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
14
+ var access = (v) => typeof v === "function" && !v.length ? v() : v;
35
15
  var asArray = (value) => Array.isArray(value) ? value : [value];
36
16
  var accessArray = (list) => list.map((v) => access(v));
37
17
  var withAccess = (value, fn) => {
38
18
  const _value = access(value);
39
- isDefined(_value) && fn(_value);
19
+ typeof _value !== "undefined" && _value !== null && fn(_value);
40
20
  };
41
- var asAccessor = (v) => isFunction(v) ? v : () => v;
42
- function onAccess(deps, fn, options) {
43
- const source = deps.map(asAccessor);
44
- return on(source, fn, options);
21
+ var asAccessor = (v) => typeof v === "function" ? v : () => v;
22
+ function accessWith(valueOrFn, ...args) {
23
+ return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
24
+ }
25
+ function forEachEntry(object, iterator) {
26
+ Object.entries(object).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, object));
45
27
  }
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
28
  var entries = (object) => Object.entries(access(object));
52
29
  var keys = Object.keys;
53
30
  var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
@@ -60,14 +37,6 @@ function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
60
37
  return race;
61
38
  }
62
39
  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
40
  var createCallbackStack = () => {
72
41
  let stack = [];
73
42
  const clear = () => stack = [];
@@ -122,7 +91,7 @@ function createTriggerCache(options) {
122
91
  export {
123
92
  access,
124
93
  accessArray,
125
- accessAsArray,
94
+ accessWith,
126
95
  asAccessor,
127
96
  asArray,
128
97
  compare,
@@ -131,33 +100,19 @@ export {
131
100
  createProxy,
132
101
  createTrigger,
133
102
  createTriggerCache,
134
- definite,
135
- destore,
136
103
  entries,
137
- forEach,
138
104
  forEachEntry,
139
- includes,
140
- isArray,
141
- isBoolean,
142
105
  isClient,
143
- isDefined,
144
106
  isDev,
145
- isFunction,
146
- isNumber,
147
107
  isObject,
148
108
  isProd,
149
109
  isServer,
150
- isString,
151
110
  keys,
152
111
  noop,
153
112
  ofClass,
154
- onAccess,
155
113
  onRootCleanup,
156
114
  promiseTimeout,
157
115
  raceTimeout,
158
- tuple,
159
116
  warn,
160
- withAccess,
161
- withFallback,
162
- withFallbackFn
117
+ withAccess
163
118
  };
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@solid-primitives/utils",
3
- "version": "0.5.3",
3
+ "version": "1.3.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/davedbase/solid-primitives/tree/main/packages/utils#readme",
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/davedbase/solid-primitives.git"
10
+ "url": "git+https://github.com/solidjs-community/solid-primitives.git"
11
11
  },
12
12
  "bugs": {
13
- "url": "https://github.com/davedbase/solid-primitives/issues"
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": "18.1.1",
36
+ "jsdom": "^19.0.0",
37
37
  "prettier": "^2.5.1",
38
- "solid-register": "^0.1.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",