@solid-primitives/utils 1.2.0 → 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/dist/index.cjs CHANGED
@@ -21,6 +21,7 @@ var src_exports = {};
21
21
  __export(src_exports, {
22
22
  access: () => access,
23
23
  accessArray: () => accessArray,
24
+ accessWith: () => accessWith,
24
25
  asAccessor: () => asAccessor,
25
26
  asArray: () => asArray,
26
27
  compare: () => compare,
@@ -33,6 +34,7 @@ __export(src_exports, {
33
34
  forEachEntry: () => forEachEntry,
34
35
  isClient: () => isClient,
35
36
  isDev: () => isDev,
37
+ isObject: () => isObject,
36
38
  isProd: () => isProd,
37
39
  isServer: () => import_web.isServer,
38
40
  keys: () => keys,
@@ -53,6 +55,9 @@ var isDev = import_solid_js.DEV && isClient;
53
55
  var isProd = !isDev;
54
56
  var warn = (...a) => isDev && console.warn(...a);
55
57
  var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
58
+ function isObject(value) {
59
+ return value !== null && (typeof value === "object" || typeof value === "function");
60
+ }
56
61
  var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
57
62
  var access = (v) => typeof v === "function" && !v.length ? v() : v;
58
63
  var asArray = (value) => Array.isArray(value) ? value : [value];
@@ -62,6 +67,9 @@ var withAccess = (value, fn) => {
62
67
  typeof _value !== "undefined" && _value !== null && fn(_value);
63
68
  };
64
69
  var asAccessor = (v) => typeof v === "function" ? v : () => v;
70
+ function accessWith(valueOrFn, ...args) {
71
+ return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
72
+ }
65
73
  function forEachEntry(object, iterator) {
66
74
  Object.entries(object).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, object));
67
75
  }
@@ -132,6 +140,7 @@ function createTriggerCache(options) {
132
140
  0 && (module.exports = {
133
141
  access,
134
142
  accessArray,
143
+ accessWith,
135
144
  asAccessor,
136
145
  asArray,
137
146
  compare,
@@ -144,6 +153,7 @@ function createTriggerCache(options) {
144
153
  forEachEntry,
145
154
  isClient,
146
155
  isDev,
156
+ isObject,
147
157
  isProd,
148
158
  isServer,
149
159
  keys,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Accessor, onCleanup } from 'solid-js';
1
+ import { Accessor, Setter, onCleanup } from 'solid-js';
2
2
  import { BaseOptions } from 'solid-js/types/reactive/signal';
3
3
  export { isServer } from 'solid-js/web';
4
4
 
@@ -14,6 +14,7 @@ declare type Directive<P = true> = (el: Element, props: Accessor<P>) => void;
14
14
  */
15
15
  declare type ItemsOf<T> = T extends (infer E)[] ? E : never;
16
16
  declare type ItemsOfMany<T> = T extends any[] ? ItemsOf<T> : T;
17
+ declare type SetterValue<T> = Parameters<Setter<T>>[0];
17
18
  /**
18
19
  * T or a reactive/non-reactive function returning T
19
20
  */
@@ -56,21 +57,14 @@ declare type Definite<T> = {
56
57
  /** `A | B => A & B` */
57
58
  declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
58
59
  declare type ExtractIfPossible<T, U> = Extract<T, U> extends never ? U : Extract<T, U>;
59
- declare type AnyObject = Record<string | symbol | number, any>;
60
+ declare type AnyObject = Record<PropertyKey, any>;
61
+ declare type AnyStatic = [] | any[] | AnyObject;
60
62
  declare type AnyFunction = (...args: any[]) => any;
61
63
  declare type AnyClass = abstract new (...args: any) => any;
62
- declare type LiteralKey = string | number | symbol;
63
- declare type PrimitiveValue = string | boolean | number | bigint | symbol | null | undefined;
64
+ declare type PrimitiveValue = PropertyKey | boolean | bigint | null | undefined;
64
65
  declare type FalsyValue = false | 0 | "" | null | undefined;
65
66
  declare type Truthy<T> = Exclude<T, FalsyValue>;
66
67
  declare type Falsy<T> = Extract<T, FalsyValue>;
67
- declare type Fallback<T, F = NonNullable<T>> = NonNullable<T> | F;
68
- /**
69
- * Destructible store object, with values changed to accessors
70
- */
71
- declare type Destore<T extends Object> = {
72
- [K in keyof T]: T[K] extends Function ? T[K] : Accessor<T[K]>;
73
- };
74
68
  declare type TriggerCache<T> = {
75
69
  track: (v: T) => void;
76
70
  dirty: (v: T) => void;
@@ -96,6 +90,8 @@ declare const warn: typeof console.warn;
96
90
  * Check if the value is an instance of ___
97
91
  */
98
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;
99
95
  declare const compare: (a: any, b: any) => number;
100
96
  /**
101
97
  * Accesses the value of a MaybeAccessor
@@ -121,6 +117,8 @@ declare const accessArray: <A extends unknown>(list: readonly A[]) => MaybeAcces
121
117
  */
122
118
  declare const withAccess: <T, A extends MaybeAccessor<T>, V = MaybeAccessorValue<A>>(value: A, fn: (value: NonNullable<V>) => void) => void;
123
119
  declare const asAccessor: <A extends unknown>(v: A) => Accessor<MaybeAccessorValue<A>>;
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;
124
122
  /**
125
123
  * Iterate through object entries.
126
124
  */
@@ -223,4 +221,4 @@ declare function createTrigger(options?: BaseOptions): Trigger;
223
221
  */
224
222
  declare function createTriggerCache<T>(options?: BaseOptions): TriggerCache<T>;
225
223
 
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 };
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
@@ -7,6 +7,9 @@ var isDev = DEV && isClient;
7
7
  var isProd = !isDev;
8
8
  var warn = (...a) => isDev && console.warn(...a);
9
9
  var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
10
+ function isObject(value) {
11
+ return value !== null && (typeof value === "object" || typeof value === "function");
12
+ }
10
13
  var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
11
14
  var access = (v) => typeof v === "function" && !v.length ? v() : v;
12
15
  var asArray = (value) => Array.isArray(value) ? value : [value];
@@ -16,6 +19,9 @@ var withAccess = (value, fn) => {
16
19
  typeof _value !== "undefined" && _value !== null && fn(_value);
17
20
  };
18
21
  var asAccessor = (v) => typeof v === "function" ? v : () => v;
22
+ function accessWith(valueOrFn, ...args) {
23
+ return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
24
+ }
19
25
  function forEachEntry(object, iterator) {
20
26
  Object.entries(object).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, object));
21
27
  }
@@ -85,6 +91,7 @@ function createTriggerCache(options) {
85
91
  export {
86
92
  access,
87
93
  accessArray,
94
+ accessWith,
88
95
  asAccessor,
89
96
  asArray,
90
97
  compare,
@@ -97,6 +104,7 @@ export {
97
104
  forEachEntry,
98
105
  isClient,
99
106
  isDev,
107
+ isObject,
100
108
  isProd,
101
109
  isServer,
102
110
  keys,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solid-primitives/utils",
3
- "version": "1.2.0",
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",