@solid-primitives/utils 0.1.3 → 0.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
@@ -10,26 +10,6 @@ npm install @solid-primitives/utils
10
10
  yarn add @solid-primitives/utils
11
11
  ```
12
12
 
13
- ## Package Entries
14
-
15
- - [`*` - `@solid-primitives/utils`](https://github.com/davedbase/solid-primitives/blob/main/packages/utils/docs/modules/index.md) - General utility functions and types for authoring primitives.
16
- - [`/fp` - `@solid-primitives/utils/fp`](https://github.com/davedbase/solid-primitives/blob/main/packages/utils/docs/modules/fp.md) - Helpers for making changes to immutable data.
17
- - [`/setter` - `@solid-primitives/utils/setter`](https://github.com/davedbase/solid-primitives/blob/main/packages/utils/docs/modules/setter.md) - Modified helpers from the `/fp`, but optimized for usage with signal setters.
18
-
19
- Import accordingly.
20
-
21
- ```ts
22
- import { access, promiseTimeout, MaybeAccessor } from "@solid-primitives/utils";
23
-
24
- // between these two some function names will overlap.
25
- import { pick, omit, filter } from "@solid-primitives/utils/fp";
26
- import { push, filter, drop } from "@solid-primitives/utils/setter";
27
- ```
28
-
29
- ## >>> [Modules documentation](https://github.com/davedbase/solid-primitives/blob/main/packages/utils/docs/README.md) <<<
30
-
31
- Documentation auto-generated from the [Typescript source files](https://github.com/davedbase/solid-primitives/blob/main/packages/utils/src) using [typedoc](https://typedoc.org) + [markdown plugin](https://www.npmjs.com/package/typedoc-plugin-markdown).
32
-
33
13
  ## Changelog
34
14
 
35
15
  <details>
package/dist/index.cjs CHANGED
@@ -25,35 +25,78 @@ var __toCommonJS = /* @__PURE__ */ ((cache) => {
25
25
  var src_exports = {};
26
26
  __export(src_exports, {
27
27
  access: () => access,
28
+ accessArray: () => accessArray,
28
29
  accessAsArray: () => accessAsArray,
29
30
  asAccessor: () => asAccessor,
30
31
  asArray: () => asArray,
32
+ compare: () => compare,
31
33
  createCallbackStack: () => createCallbackStack,
32
- createSubRoot: () => createSubRoot,
33
- createSubRootFunction: () => createSubRootFunction,
34
+ createProxy: () => createProxy,
35
+ definite: () => definite,
34
36
  destore: () => destore,
35
37
  entries: () => entries,
36
38
  forEach: () => forEach,
39
+ forEachEntry: () => forEachEntry,
40
+ includes: () => includes,
41
+ isArray: () => isArray,
42
+ isBoolean: () => isBoolean,
37
43
  isClient: () => isClient,
38
44
  isDefined: () => isDefined,
45
+ isDev: () => isDev,
39
46
  isFunction: () => isFunction,
47
+ isNumber: () => isNumber,
48
+ isObject: () => isObject,
49
+ isProd: () => isProd,
40
50
  isServer: () => import_web.isServer,
51
+ isString: () => isString,
52
+ keys: () => keys,
41
53
  noop: () => noop,
54
+ ofClass: () => ofClass,
42
55
  onAccess: () => onAccess,
43
56
  onRootCleanup: () => onRootCleanup,
44
57
  promiseTimeout: () => promiseTimeout,
45
58
  raceTimeout: () => raceTimeout,
46
- withAccess: () => withAccess
59
+ tuple: () => tuple,
60
+ warn: () => warn,
61
+ withAccess: () => withAccess,
62
+ withFallback: () => withFallback,
63
+ withFallbackFn: () => withFallbackFn
47
64
  });
48
65
  var import_solid_js = require("solid-js");
49
66
  var import_web = require("solid-js/web");
50
67
  var noop = () => void 0;
51
68
  var isClient = !import_web.isServer;
69
+ var isDev = import_solid_js.DEV && import_solid_js.DEV.hasOwnProperty("writeSignal");
70
+ var isProd = !isDev;
71
+ var warn = (...a) => isDev && console.warn(...a);
52
72
  var isDefined = (value) => typeof value !== "undefined" && value !== null;
53
73
  var isFunction = (value) => typeof value === "function";
74
+ var isBoolean = (val) => typeof val === "boolean";
75
+ var isNumber = (val) => typeof val === "number";
76
+ var isString = (val) => typeof val === "string";
77
+ var isObject = (val) => toString.call(val) === "[object Object]";
78
+ var isArray = Array.isArray;
79
+ var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
80
+ var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
81
+ var tuple = (input) => input;
82
+ var definite = (v) => v;
83
+ function withFallback(v, fallback) {
84
+ return isDefined(v) ? v : fallback;
85
+ }
86
+ function withFallbackFn(v, fallback) {
87
+ return isDefined(v) ? v : fallback();
88
+ }
89
+ var includes = (arr, ...items) => {
90
+ for (const item of arr) {
91
+ if (items.includes(item))
92
+ return true;
93
+ }
94
+ return false;
95
+ };
54
96
  var access = (v) => isFunction(v) ? v() : v;
55
97
  var accessAsArray = (value) => asArray(access(value));
56
98
  var asArray = (value) => Array.isArray(value) ? value : [value];
99
+ var accessArray = (list) => list.map((v) => access(v));
57
100
  var withAccess = (value, fn) => {
58
101
  const _value = access(value);
59
102
  isDefined(_value) && fn(_value);
@@ -64,7 +107,12 @@ function onAccess(deps, fn, options) {
64
107
  return (0, import_solid_js.on)(source, fn, options);
65
108
  }
66
109
  var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
110
+ var forEachEntry = (object, iterator) => {
111
+ const obj = access(object);
112
+ Object.entries(obj).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, obj));
113
+ };
67
114
  var entries = (object) => Object.entries(access(object));
115
+ var keys = (object) => Object.keys(access(object));
68
116
  var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
69
117
  function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
70
118
  const promises = asArray(input);
@@ -74,6 +122,7 @@ function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
74
122
  });
75
123
  return race;
76
124
  }
125
+ var onRootCleanup = (fn) => (0, import_solid_js.getOwner)() ? (0, import_solid_js.onCleanup)(fn) : fn;
77
126
  function destore(store) {
78
127
  const _store = store;
79
128
  const result = {};
@@ -82,48 +131,66 @@ function destore(store) {
82
131
  });
83
132
  return result;
84
133
  }
85
- var onRootCleanup = (fn) => (0, import_solid_js.getOwner)() ? (0, import_solid_js.onCleanup)(fn) : fn;
86
- function createSubRoot(fn, owner = (0, import_solid_js.getOwner)()) {
87
- const [dispose, returns] = (0, import_solid_js.createRoot)((dispose2) => [dispose2, fn(dispose2)], owner != null ? owner : void 0);
88
- owner && (0, import_solid_js.runWithOwner)(owner, () => (0, import_solid_js.onCleanup)(dispose));
89
- return returns;
90
- }
91
- function createSubRootFunction(callback, owner) {
92
- return (...args) => createSubRoot(() => callback(...args), owner);
93
- }
94
134
  var createCallbackStack = () => {
95
135
  let stack = [];
96
136
  const clear = () => stack = [];
97
137
  return {
98
138
  push: (...callbacks) => stack.push(...callbacks),
99
- execute: (arg0, arg1, arg2, arg3) => {
139
+ execute(arg0, arg1, arg2, arg3) {
100
140
  stack.forEach((cb) => cb(arg0, arg1, arg2, arg3));
101
141
  clear();
102
142
  },
103
143
  clear
104
144
  };
105
145
  };
146
+ function createProxy(traps) {
147
+ return new Proxy({}, {
148
+ get: (_, k) => traps.get(k),
149
+ set: (_, k, v) => {
150
+ var _a;
151
+ (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
152
+ return false;
153
+ }
154
+ });
155
+ }
106
156
  module.exports = __toCommonJS(src_exports);
107
157
  // Annotate the CommonJS export names for ESM import in node:
108
158
  0 && (module.exports = {
109
159
  access,
160
+ accessArray,
110
161
  accessAsArray,
111
162
  asAccessor,
112
163
  asArray,
164
+ compare,
113
165
  createCallbackStack,
114
- createSubRoot,
115
- createSubRootFunction,
166
+ createProxy,
167
+ definite,
116
168
  destore,
117
169
  entries,
118
170
  forEach,
171
+ forEachEntry,
172
+ includes,
173
+ isArray,
174
+ isBoolean,
119
175
  isClient,
120
176
  isDefined,
177
+ isDev,
121
178
  isFunction,
179
+ isNumber,
180
+ isObject,
181
+ isProd,
122
182
  isServer,
183
+ isString,
184
+ keys,
123
185
  noop,
186
+ ofClass,
124
187
  onAccess,
125
188
  onRootCleanup,
126
189
  promiseTimeout,
127
190
  raceTimeout,
128
- withAccess
191
+ tuple,
192
+ warn,
193
+ withAccess,
194
+ withFallback,
195
+ withFallbackFn
129
196
  });
package/dist/index.d.ts CHANGED
@@ -1,19 +1,134 @@
1
1
  import { Accessor, onCleanup } from 'solid-js';
2
- import { OnOptions, EffectFunction, NoInfer, Owner } from 'solid-js/types/reactive/signal';
2
+ import { OnOptions, EffectFunction, NoInfer } from 'solid-js/types/reactive/signal';
3
3
  import { Store } from 'solid-js/store';
4
4
  export { isServer } from 'solid-js/web';
5
- import { N as Noop, M as MaybeAccessorValue, a as MaybeAccessor, O as OnAccessEffectFunction, I as ItemsOf, V as Values, D as Destore, F as Fn, A as AnyFunction } from './types-5d7b3b37';
6
- export { d as AccessReturnTypes, A as AnyFunction, h as AnyObject, g as DeepPartialAny, D as Destore, k as Falsy, j as FalsyValue, F as Fn, I as ItemsOf, K as Keys, b as Many, c as MappingFn, a as MaybeAccessor, M as MaybeAccessorValue, e as Modify, f as ModifyDeep, N as Noop, O as OnAccessEffectFunction, P as Predicate, i as PrimitiveValue, T as Truthy, V as Values } from './types-5d7b3b37';
5
+
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
+ /**
13
+ * Can be single or in an array
14
+ */
15
+ 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>];
18
+ declare type Noop = (...a: any[]) => void;
19
+ declare type Directive<P = true> = (el: Element, props: Accessor<P>) => void;
20
+ /**
21
+ * Infers the type of the array elements
22
+ */
23
+ declare type ItemsOf<T> = T extends (infer E)[] ? E : never;
24
+ declare type ItemsOfMany<T> = T extends any[] ? ItemsOf<T> : T;
25
+ /**
26
+ * T or a reactive/non-reactive function returning T
27
+ */
28
+ declare type MaybeAccessor<T> = T | Accessor<T>;
29
+ /**
30
+ * Accessed value of a MaybeAccessor
31
+ * @example
32
+ * ```ts
33
+ * MaybeAccessorValue<MaybeAccessor<string>>
34
+ * // => string
35
+ * MaybeAccessorValue<MaybeAccessor<() => string>>
36
+ * // => string | (() => string)
37
+ * MaybeAccessorValue<MaybeAccessor<string> | Function>
38
+ * // => string | void
39
+ * ```
40
+ */
41
+ declare type MaybeAccessorValue<T extends MaybeAccessor<any>> = T extends Fn ? ReturnType<T> : T;
42
+ declare type OnAccessEffectFunction<S, Prev, Next extends Prev = Prev> = (input: AccessReturnTypes<S>, prevInput: AccessReturnTypes<S>, v: Prev) => Next;
43
+ declare type AccessReturnTypes<S> = S extends MaybeAccessor<any>[] ? {
44
+ [I in keyof S]: AccessReturnTypes<S[I]>;
45
+ } : MaybeAccessorValue<S>;
46
+ /** Allows to make shallow overwrites to an interface */
47
+ declare type Modify<T, R> = Omit<T, keyof R> & R;
48
+ /** Allows to make nested overwrites to an interface */
49
+ declare type ModifyDeep<A extends AnyObject, B extends DeepPartialAny<A>> = {
50
+ [K in keyof A]: B[K] extends never ? A[K] : B[K] extends AnyObject ? ModifyDeep<A[K], B[K]> : B[K];
51
+ } & (A extends AnyObject ? Omit<B, keyof A> : A);
52
+ /** Makes each property optional and turns each leaf property into any, allowing for type overrides by narrowing any. */
53
+ declare type DeepPartialAny<T> = {
54
+ [P in keyof T]?: T[P] extends AnyObject ? DeepPartialAny<T[P]> : any;
55
+ };
56
+ /** `A | B => A & B` */
57
+ declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
58
+ declare type ExtractIfPossible<T, U> = Extract<T, U> extends never ? U : Extract<T, U>;
59
+ declare type AnyObject = Record<string, any>;
60
+ declare type AnyFunction = (...args: any[]) => any;
61
+ 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 FalsyValue = false | 0 | "" | null | undefined;
65
+ declare type Truthy<T> = Exclude<T, FalsyValue>;
66
+ 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
+ declare type Position = {
75
+ x: number;
76
+ y: number;
77
+ };
7
78
 
8
79
  /** no operation */
9
80
  declare const noop: Noop;
10
81
  declare const isClient = true;
11
82
 
83
+ /** development environment */
84
+ declare const isDev: boolean;
85
+ /** production environment */
86
+ declare const isProd: boolean;
87
+ /** `console.warn` only during development */
88
+ declare const warn: typeof console.warn;
12
89
  /**
13
90
  * `if (typeof value !== "undefined" && value !== null)`
14
91
  */
15
92
  declare const isDefined: <T>(value: T | null | undefined) => value is T;
16
93
  declare const isFunction: <T>(value: Function | T) => value is Function;
94
+ declare const isBoolean: (val: any) => val is boolean;
95
+ declare const isNumber: (val: any) => val is number;
96
+ declare const isString: (val: unknown) => val is string;
97
+ declare const isObject: (val: any) => val is object;
98
+ declare const isArray: (val: any) => val is any[];
99
+ /**
100
+ * Check if the value is an instance of ___
101
+ */
102
+ declare const ofClass: (v: any, c: AnyClass) => boolean;
103
+ declare const compare: (a: any, b: any) => number;
104
+ /**
105
+ * for creating tuples by inferring type
106
+ * @example
107
+ * const users = tuple(["John", "Jeff", "Joe"]);
108
+ * users // T: [string, string, string]
109
+ */
110
+ declare const tuple: <T extends any[] | []>(input: T) => T;
111
+ /**
112
+ * Removes the `null` and `undefined` from the type.
113
+ * @warning **Obviously use with caution**
114
+ */
115
+ declare const definite: <T>(v: T) => NonNullable<T>;
116
+ /**
117
+ * Get the value if it is defined, or get the fallback otherwise
118
+ * @param v the value to check
119
+ * @param fallback the fallback value
120
+ */
121
+ declare function withFallback<T>(v: T, fallback: NonNullable<T>): Fallback<T>;
122
+ declare function withFallback<T, F>(v: T, fallback: F): Fallback<T, F>;
123
+ /**
124
+ * Get the value if it is defined, or get the fallback otherwise
125
+ * @param v the value to check
126
+ * @param fallback function returning a fallback value
127
+ */
128
+ declare function withFallbackFn<T>(v: T, fallback: () => NonNullable<T>): Fallback<T>;
129
+ declare function withFallbackFn<T, F>(v: T, fallback: () => F): Fallback<T, F>;
130
+ /** `Array.prototype.includes()` without so strict types. Also allows for checking for multiple items */
131
+ declare const includes: (arr: any[], ...items: any) => boolean;
17
132
  /**
18
133
  * Accesses the value of a MaybeAccessor
19
134
  * @example
@@ -35,6 +150,13 @@ declare const access: <T extends unknown>(v: T) => MaybeAccessorValue<T>;
35
150
  */
36
151
  declare const accessAsArray: <T extends unknown, V = MaybeAccessorValue<T>>(value: T) => V extends any[] ? V : V[];
37
152
  declare const asArray: <T>(value: T) => T extends any[] ? T : T[];
153
+ /**
154
+ * Access an array of MaybeAccessors
155
+ * @example
156
+ * const list = [1, 2, () => 3)] // T: MaybeAccessor<number>[]
157
+ * const newList = accessArray(list) // T: number[]
158
+ */
159
+ declare const accessArray: <A extends unknown>(list: readonly A[]) => MaybeAccessorValue<A>[];
38
160
  /**
39
161
  * Run the function if the accessed value is not `undefined` nor `null`
40
162
  * @param value
@@ -55,11 +177,19 @@ declare function onAccess<S extends MaybeAccessor<unknown>[] | [], Next, Init =
55
177
  */
56
178
  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;
57
179
  /**
58
- * Get `Object.entries()` of an MaybeAccessor<Object>
180
+ * Iterate through object entries.
181
+ */
182
+ 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;
183
+ /**
184
+ * Get `Object.entries()` of an MaybeAccessor<object>
59
185
  */
60
- declare const entries: <A extends MaybeAccessor<Object>, V = MaybeAccessorValue<A>>(object: A) => [string, Values<V>][];
186
+ declare const entries: <A extends MaybeAccessor<object>, O = MaybeAccessorValue<A>>(object: A) => [keyof O, Values<O>][];
61
187
  /**
62
- * Creates a promise that resolves *(or rejects)* after gives time.
188
+ * Get `Object.keys()` of an MaybeAccessor<Object>
189
+ */
190
+ declare const keys: <A extends MaybeAccessor<object>>(object: A) => (keyof MaybeAccessorValue<A>)[];
191
+ /**
192
+ * Creates a promise that resolves *(or rejects)* after given time.
63
193
  *
64
194
  * @param ms timeout duration in ms
65
195
  * @param throwOnTimeout promise will be rejected on timeout if set to `true`
@@ -94,6 +224,10 @@ declare const promiseTimeout: (ms: number, throwOnTimeout?: boolean, reason?: st
94
224
  */
95
225
  declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout: true, reason?: string): T extends any[] ? Promise<Awaited<T[number]>> : Promise<Awaited<T>>;
96
226
  declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolean, reason?: string): T extends any[] ? Promise<Awaited<T[number]> | undefined> : Promise<Awaited<T> | undefined>;
227
+ /**
228
+ * Solid's `onCleanup` that is registered only if there is a root.
229
+ */
230
+ declare const onRootCleanup: typeof onCleanup;
97
231
  /**
98
232
  * Allows the Solid's store to be destructured
99
233
  *
@@ -112,41 +246,19 @@ declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolea
112
246
  * ```
113
247
  */
114
248
  declare function destore<T extends Object>(store: Store<T>): Destore<T>;
115
- /**
116
- * Solid's `onCleanup` that runs only if there is a root.
117
- */
118
- declare const onRootCleanup: typeof onCleanup;
119
- /**
120
- * Creates a reactive root, which will be disposed when the passed owner does.
121
- *
122
- * @param fn
123
- * @param owner a root that will trigger the cleanup
124
- * @returns whatever the "fn" returns
125
- *
126
- * @example
127
- * const owner = getOwner()
128
- * const handleClick = () => createSubRoot(owner, () => {
129
- * createEffect(() => {})
130
- * });
131
- */
132
- declare function createSubRoot<T>(fn: (dispose: Fn) => T, owner?: Owner | null): T;
133
- /**
134
- * A wrapper for creating functions with the `createSubRoot`
135
- *
136
- * @param callback
137
- * @param owner a root that will trigger the cleanup
138
- * @returns the callback function
139
- *
140
- * @example
141
- * const handleClick = createSubRootFunction(() => {
142
- * createEffect(() => {})
143
- * })
144
- */
145
- declare function createSubRootFunction<T extends AnyFunction>(callback: T, owner?: Owner | null): T;
146
249
  declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {
147
- push: (...callbacks: Fn[]) => void;
250
+ push: (...callbacks: ((arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void)[]) => void;
148
251
  execute: (arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void;
149
252
  clear: Fn;
150
253
  };
254
+ /** WIP: an easier to setup and type Proxy */
255
+ declare function createProxy<T extends Record<string | symbol, any>>(traps: {
256
+ get: <K extends keyof T>(key: K) => T[K];
257
+ set: <K extends keyof T>(key: K, value: T[K]) => void;
258
+ }): T;
259
+ declare function createProxy<T extends Record<string | symbol, any>>(traps: {
260
+ get: <K extends keyof T>(key: K) => T[K];
261
+ set?: undefined;
262
+ }): Readonly<T>;
151
263
 
152
- export { access, accessAsArray, asAccessor, asArray, createCallbackStack, createSubRoot, createSubRootFunction, destore, entries, forEach, isClient, isDefined, isFunction, noop, onAccess, onRootCleanup, promiseTimeout, raceTimeout, withAccess };
264
+ export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, Clear, DeepPartialAny, Destore, Directive, ExtractIfPossible, Fallback, Falsy, FalsyValue, Fn, Get, ItemsOf, ItemsOfMany, Keys, LiteralKey, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Noop, OnAccessEffectFunction, Position, PrimitiveValue, Truthy, UnionToIntersection, Values, access, accessArray, accessAsArray, asAccessor, asArray, compare, createCallbackStack, createProxy, 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 };
package/dist/index.js CHANGED
@@ -1,13 +1,39 @@
1
1
  // src/index.ts
2
- import { createRoot, getOwner, onCleanup, runWithOwner, on } from "solid-js";
2
+ import { getOwner, onCleanup, on, 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");
7
+ var isProd = !isDev;
8
+ var warn = (...a) => isDev && console.warn(...a);
6
9
  var isDefined = (value) => typeof value !== "undefined" && value !== null;
7
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
+ 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();
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
+ };
8
33
  var access = (v) => isFunction(v) ? v() : v;
9
34
  var accessAsArray = (value) => asArray(access(value));
10
35
  var asArray = (value) => Array.isArray(value) ? value : [value];
36
+ var accessArray = (list) => list.map((v) => access(v));
11
37
  var withAccess = (value, fn) => {
12
38
  const _value = access(value);
13
39
  isDefined(_value) && fn(_value);
@@ -18,7 +44,12 @@ function onAccess(deps, fn, options) {
18
44
  return on(source, fn, options);
19
45
  }
20
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
+ };
21
51
  var entries = (object) => Object.entries(access(object));
52
+ var keys = (object) => Object.keys(access(object));
22
53
  var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
23
54
  function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
24
55
  const promises = asArray(input);
@@ -28,6 +59,7 @@ function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
28
59
  });
29
60
  return race;
30
61
  }
62
+ var onRootCleanup = (fn) => getOwner() ? onCleanup(fn) : fn;
31
63
  function destore(store) {
32
64
  const _store = store;
33
65
  const result = {};
@@ -36,46 +68,64 @@ function destore(store) {
36
68
  });
37
69
  return result;
38
70
  }
39
- var onRootCleanup = (fn) => getOwner() ? onCleanup(fn) : fn;
40
- function createSubRoot(fn, owner = getOwner()) {
41
- const [dispose, returns] = createRoot((dispose2) => [dispose2, fn(dispose2)], owner != null ? owner : void 0);
42
- owner && runWithOwner(owner, () => onCleanup(dispose));
43
- return returns;
44
- }
45
- function createSubRootFunction(callback, owner) {
46
- return (...args) => createSubRoot(() => callback(...args), owner);
47
- }
48
71
  var createCallbackStack = () => {
49
72
  let stack = [];
50
73
  const clear = () => stack = [];
51
74
  return {
52
75
  push: (...callbacks) => stack.push(...callbacks),
53
- execute: (arg0, arg1, arg2, arg3) => {
76
+ execute(arg0, arg1, arg2, arg3) {
54
77
  stack.forEach((cb) => cb(arg0, arg1, arg2, arg3));
55
78
  clear();
56
79
  },
57
80
  clear
58
81
  };
59
82
  };
83
+ function createProxy(traps) {
84
+ return new Proxy({}, {
85
+ get: (_, k) => traps.get(k),
86
+ set: (_, k, v) => {
87
+ var _a;
88
+ (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
89
+ return false;
90
+ }
91
+ });
92
+ }
60
93
  export {
61
94
  access,
95
+ accessArray,
62
96
  accessAsArray,
63
97
  asAccessor,
64
98
  asArray,
99
+ compare,
65
100
  createCallbackStack,
66
- createSubRoot,
67
- createSubRootFunction,
101
+ createProxy,
102
+ definite,
68
103
  destore,
69
104
  entries,
70
105
  forEach,
106
+ forEachEntry,
107
+ includes,
108
+ isArray,
109
+ isBoolean,
71
110
  isClient,
72
111
  isDefined,
112
+ isDev,
73
113
  isFunction,
114
+ isNumber,
115
+ isObject,
116
+ isProd,
74
117
  isServer,
118
+ isString,
119
+ keys,
75
120
  noop,
121
+ ofClass,
76
122
  onAccess,
77
123
  onRootCleanup,
78
124
  promiseTimeout,
79
125
  raceTimeout,
80
- withAccess
126
+ tuple,
127
+ warn,
128
+ withAccess,
129
+ withFallback,
130
+ withFallbackFn
81
131
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solid-primitives/utils",
3
- "version": "0.1.3",
3
+ "version": "0.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",
@@ -9,6 +9,9 @@
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/davedbase/solid-primitives.git"
11
11
  },
12
+ "bugs": {
13
+ "url": "https://github.com/davedbase/solid-primitives/issues"
14
+ },
12
15
  "private": false,
13
16
  "sideEffects": false,
14
17
  "type": "module",
@@ -18,38 +21,10 @@
18
21
  "files": [
19
22
  "dist"
20
23
  ],
21
- "exports": {
22
- ".": {
23
- "types": "./dist/index.d.ts",
24
- "require": "./dist/index.cjs",
25
- "import": "./dist/index.js"
26
- },
27
- "./fp": {
28
- "types": "./dist/fp.d.ts",
29
- "require": "./dist/fp.cjs",
30
- "import": "./dist/fp.js"
31
- },
32
- "./setter": {
33
- "types": "./dist/setter.d.ts",
34
- "require": "./dist/setter.cjs",
35
- "import": "./dist/setter.js"
36
- }
37
- },
38
- "typesVersions": {
39
- "*": {
40
- "fp": [
41
- "./dist/fp.d.ts"
42
- ],
43
- "setter": [
44
- "./dist/setter.d.ts"
45
- ]
46
- }
47
- },
48
24
  "scripts": {
49
25
  "build": "tsup",
50
26
  "test": "uvu -r solid-register",
51
- "watch-test": "watchlist src test -- npm test",
52
- "docs": "typedoc"
27
+ "watch-test": "watchlist src test -- npm test"
53
28
  },
54
29
  "keywords": [
55
30
  "utilities",
@@ -63,8 +38,6 @@
63
38
  "solid-register": "^0.1.1",
64
39
  "tslib": "^2.3.1",
65
40
  "tsup": "^5.11.0",
66
- "typedoc": "^0.22.10",
67
- "typedoc-plugin-markdown": "^3.11.8",
68
41
  "uvu": "^0.5.2",
69
42
  "watchlist": "^0.3.1"
70
43
  },
@@ -1,49 +0,0 @@
1
- // src/fp.ts
2
- var withArrayCopy = (array, mutator) => {
3
- const copy = array.slice();
4
- mutator(copy);
5
- return copy;
6
- };
7
- var withObjectCopy = (object, mutator) => {
8
- const copy = Object.assign({}, object);
9
- mutator(copy);
10
- return copy;
11
- };
12
- var withCopy = (source, mutator) => Array.isArray(source) ? withArrayCopy(source, mutator) : withObjectCopy(source, mutator);
13
- var push = (list, item) => withArrayCopy(list, (list2) => list2.push(item));
14
- var drop = (list, n = 1) => list.slice(n);
15
- var filterOut = (list, item) => filter(list, (i) => i !== item);
16
- function filter(list, predicate) {
17
- const newList = list.filter(predicate);
18
- newList.removed = list.length - newList.length;
19
- return newList;
20
- }
21
- var map = (list, mapFn) => list.map(mapFn);
22
- var slice = (list, start, end) => list.slice(start, end);
23
- var splice = (list, start, deleteCount, ...items) => withArrayCopy(list, (list2) => list2.splice(start, deleteCount, ...items));
24
- var remove = (list, item) => {
25
- const index = list.indexOf(item);
26
- return splice(list, index, 1);
27
- };
28
- var omit = (object, ...keys) => withObjectCopy(object, (object2) => keys.forEach((key) => delete object2[key]));
29
- var pick = (object, ...keys) => keys.reduce((n, k) => {
30
- if (k in object)
31
- n[k] = object[k];
32
- return n;
33
- }, {});
34
-
35
- export {
36
- withArrayCopy,
37
- withObjectCopy,
38
- withCopy,
39
- push,
40
- drop,
41
- filterOut,
42
- filter,
43
- map,
44
- slice,
45
- splice,
46
- remove,
47
- omit,
48
- pick
49
- };
package/dist/fp.cjs DELETED
@@ -1,89 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
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 });
15
- }
16
- return target;
17
- };
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);
23
-
24
- // src/fp.ts
25
- var fp_exports = {};
26
- __export(fp_exports, {
27
- drop: () => drop,
28
- filter: () => filter,
29
- filterOut: () => filterOut,
30
- map: () => map,
31
- omit: () => omit,
32
- pick: () => pick,
33
- push: () => push,
34
- remove: () => remove,
35
- slice: () => slice,
36
- splice: () => splice,
37
- withArrayCopy: () => withArrayCopy,
38
- withCopy: () => withCopy,
39
- withObjectCopy: () => withObjectCopy
40
- });
41
- var withArrayCopy = (array, mutator) => {
42
- const copy = array.slice();
43
- mutator(copy);
44
- return copy;
45
- };
46
- var withObjectCopy = (object, mutator) => {
47
- const copy = Object.assign({}, object);
48
- mutator(copy);
49
- return copy;
50
- };
51
- var withCopy = (source, mutator) => Array.isArray(source) ? withArrayCopy(source, mutator) : withObjectCopy(source, mutator);
52
- var push = (list, item) => withArrayCopy(list, (list2) => list2.push(item));
53
- var drop = (list, n = 1) => list.slice(n);
54
- var filterOut = (list, item) => filter(list, (i) => i !== item);
55
- function filter(list, predicate) {
56
- const newList = list.filter(predicate);
57
- newList.removed = list.length - newList.length;
58
- return newList;
59
- }
60
- var map = (list, mapFn) => list.map(mapFn);
61
- var slice = (list, start, end) => list.slice(start, end);
62
- var splice = (list, start, deleteCount, ...items) => withArrayCopy(list, (list2) => list2.splice(start, deleteCount, ...items));
63
- var remove = (list, item) => {
64
- const index = list.indexOf(item);
65
- return splice(list, index, 1);
66
- };
67
- var omit = (object, ...keys) => withObjectCopy(object, (object2) => keys.forEach((key) => delete object2[key]));
68
- var pick = (object, ...keys) => keys.reduce((n, k) => {
69
- if (k in object)
70
- n[k] = object[k];
71
- return n;
72
- }, {});
73
- module.exports = __toCommonJS(fp_exports);
74
- // Annotate the CommonJS export names for ESM import in node:
75
- 0 && (module.exports = {
76
- drop,
77
- filter,
78
- filterOut,
79
- map,
80
- omit,
81
- pick,
82
- push,
83
- remove,
84
- slice,
85
- splice,
86
- withArrayCopy,
87
- withCopy,
88
- withObjectCopy
89
- });
package/dist/fp.d.ts DELETED
@@ -1,93 +0,0 @@
1
- import { P as Predicate, c as MappingFn } from './types-5d7b3b37';
2
- import 'solid-js';
3
-
4
- /**
5
- * apply mutations to the an array without changing the original
6
- * @param array original array
7
- * @param mutator function applying mutations to the copy of source
8
- * @returns changed array copy
9
- */
10
- declare const withArrayCopy: <T>(array: readonly T[], mutator: (copy: T[]) => void) => T[];
11
- /**
12
- * apply mutations to the an object without changing the original
13
- * @param object original object
14
- * @param mutator function applying mutations to the copy of source
15
- * @returns changed object copy
16
- */
17
- declare const withObjectCopy: <T extends object>(object: T, mutator: (copy: T) => void) => T;
18
- /**
19
- * apply mutations to the an object/array without changing the original
20
- * @param source original object
21
- * @param mutator function applying mutations to the copy of source
22
- * @returns changed object copy
23
- */
24
- declare const withCopy: <T extends object>(source: T, mutator: (copy: T) => void) => T;
25
- /**
26
- * non-mutating `Array.prototype.push()`
27
- * @returns changed array copy
28
- */
29
- declare const push: <T>(list: T[], item: T) => T[];
30
- /**
31
- * non-mutating function that drops n items from the array start.
32
- * @returns changed array copy
33
- *
34
- * @example
35
- * ```ts
36
- * const newList = drop([1,2,3])
37
- * newList // => [2,3]
38
- *
39
- * const newList = drop([1,2,3], 2)
40
- * newList // => [3]
41
- * ```
42
- */
43
- declare const drop: <T>(list: T[], n?: number) => T[];
44
- /**
45
- * non-mutating `Array.prototype.filter()` that filters out passed item
46
- * @returns changed array copy
47
- */
48
- declare const filterOut: <T>(list: readonly T[], item: T) => T[] & {
49
- removed: number;
50
- };
51
- /**
52
- * non-mutating `Array.prototype.filter()` as a standalone function
53
- * @returns changed array copy
54
- */
55
- declare function filter<T>(list: readonly T[], predicate: Predicate<T>): T[] & {
56
- removed: number;
57
- };
58
- /**
59
- * standalone `Array.prototype.map()` function
60
- */
61
- declare const map: <T, V>(list: readonly T[], mapFn: MappingFn<T, V>) => V[];
62
- /**
63
- * standalone `Array.prototype.slice()` function
64
- */
65
- declare const slice: <T>(list: readonly T[], start?: number | undefined, end?: number | undefined) => T[];
66
- /**
67
- * non-mutating `Array.prototype.splice()` as a standalone function
68
- * @returns changed array copy
69
- */
70
- declare const splice: <T>(list: readonly T[], start: number, deleteCount: number, ...items: T[]) => T[];
71
- declare const remove: <T>(list: readonly T[], item: T) => T[];
72
- /**
73
- * Create a new subset object without the provided keys
74
- *
75
- * @example
76
- * ```ts
77
- * const newObject = omit({ a:"foo", b:"bar", c: "baz" }, 'a', 'b')
78
- * newObject // => { c: "baz" }
79
- * ```
80
- */
81
- declare const omit: <O extends object, K extends keyof O>(object: O, ...keys: K[]) => Omit<O, K>;
82
- /**
83
- * Create a new subset object with only the provided keys
84
- *
85
- * @example
86
- * ```ts
87
- * const newObject = pick({ a:"foo", b:"bar", c: "baz" }, 'a', 'b')
88
- * newObject // => { a:"foo", b:"bar" }
89
- * ```
90
- */
91
- declare const pick: <O extends object, K extends keyof O>(object: O, ...keys: K[]) => Pick<O, K>;
92
-
93
- export { drop, filter, filterOut, map, omit, pick, push, remove, slice, splice, withArrayCopy, withCopy, withObjectCopy };
package/dist/fp.js DELETED
@@ -1,30 +0,0 @@
1
- import {
2
- drop,
3
- filter,
4
- filterOut,
5
- map,
6
- omit,
7
- pick,
8
- push,
9
- remove,
10
- slice,
11
- splice,
12
- withArrayCopy,
13
- withCopy,
14
- withObjectCopy
15
- } from "./chunk-BVHCDFCW.js";
16
- export {
17
- drop,
18
- filter,
19
- filterOut,
20
- map,
21
- omit,
22
- pick,
23
- push,
24
- remove,
25
- slice,
26
- splice,
27
- withArrayCopy,
28
- withCopy,
29
- withObjectCopy
30
- };
package/dist/setter.cjs DELETED
@@ -1,79 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
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 });
15
- }
16
- return target;
17
- };
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);
23
-
24
- // src/setter.ts
25
- var setter_exports = {};
26
- __export(setter_exports, {
27
- drop: () => drop2,
28
- filter: () => filter2,
29
- filterOut: () => filterOut2,
30
- map: () => map,
31
- push: () => push2,
32
- remove: () => remove2,
33
- slice: () => slice,
34
- splice: () => splice2
35
- });
36
-
37
- // src/fp.ts
38
- var withArrayCopy = (array, mutator) => {
39
- const copy = array.slice();
40
- mutator(copy);
41
- return copy;
42
- };
43
- var push = (list, item) => withArrayCopy(list, (list2) => list2.push(item));
44
- var drop = (list, n = 1) => list.slice(n);
45
- var filterOut = (list, item) => filter(list, (i) => i !== item);
46
- function filter(list, predicate) {
47
- const newList = list.filter(predicate);
48
- newList.removed = list.length - newList.length;
49
- return newList;
50
- }
51
- var splice = (list, start, deleteCount, ...items) => withArrayCopy(list, (list2) => list2.splice(start, deleteCount, ...items));
52
- var remove = (list, item) => {
53
- const index = list.indexOf(item);
54
- return splice(list, index, 1);
55
- };
56
-
57
- // src/setter.ts
58
- var push2 = (item) => (list) => push(list, item);
59
- var drop2 = (n = 1) => (list) => drop(list, n);
60
- var filterOut2 = (item) => (list) => filterOut(list, item);
61
- var filter2 = (predicate) => (list) => filter(list, predicate);
62
- var map = (mapFn) => (list) => list.map(mapFn);
63
- var slice = (start, end) => (list) => list.slice(start, end);
64
- function splice2(start, deleteCount, ...items) {
65
- return (list) => splice(list, start, deleteCount, ...items);
66
- }
67
- var remove2 = (item) => (list) => remove(list, item);
68
- module.exports = __toCommonJS(setter_exports);
69
- // Annotate the CommonJS export names for ESM import in node:
70
- 0 && (module.exports = {
71
- drop,
72
- filter,
73
- filterOut,
74
- map,
75
- push,
76
- remove,
77
- slice,
78
- splice
79
- });
package/dist/setter.d.ts DELETED
@@ -1,18 +0,0 @@
1
- import { P as Predicate, c as MappingFn } from './types-5d7b3b37';
2
- import 'solid-js';
3
-
4
- declare const push: <T>(item: T) => (list: T[]) => T[];
5
- declare const drop: (n?: number) => <T>(list: T[]) => T[];
6
- declare const filterOut: <T>(item: T) => (list: T[]) => T[] & {
7
- removed: number;
8
- };
9
- declare const filter: <T>(predicate: Predicate<T>) => (list: T[]) => T[] & {
10
- removed: number;
11
- };
12
- declare const map: <T>(mapFn: MappingFn<T, T>) => (list: T[]) => T[];
13
- declare const slice: (start?: number | undefined, end?: number | undefined) => <T>(list: T[]) => T[];
14
- declare function splice(start: number, deleteCount: number): <T>(list: T[]) => T[];
15
- declare function splice<T>(start: number, deleteCount: number, ...items: T[]): (list: T[]) => T[];
16
- declare const remove: <T>(item: T) => (list: T[]) => T[];
17
-
18
- export { drop, filter, filterOut, map, push, remove, slice, splice };
package/dist/setter.js DELETED
@@ -1,30 +0,0 @@
1
- import {
2
- drop,
3
- filter,
4
- filterOut,
5
- push,
6
- remove,
7
- splice
8
- } from "./chunk-BVHCDFCW.js";
9
-
10
- // src/setter.ts
11
- var push2 = (item) => (list) => push(list, item);
12
- var drop2 = (n = 1) => (list) => drop(list, n);
13
- var filterOut2 = (item) => (list) => filterOut(list, item);
14
- var filter2 = (predicate) => (list) => filter(list, predicate);
15
- var map = (mapFn) => (list) => list.map(mapFn);
16
- var slice = (start, end) => (list) => list.slice(start, end);
17
- function splice2(start, deleteCount, ...items) {
18
- return (list) => splice(list, start, deleteCount, ...items);
19
- }
20
- var remove2 = (item) => (list) => remove(list, item);
21
- export {
22
- drop2 as drop,
23
- filter2 as filter,
24
- filterOut2 as filterOut,
25
- map,
26
- push2 as push,
27
- remove2 as remove,
28
- slice,
29
- splice2 as splice
30
- };
@@ -1,64 +0,0 @@
1
- import { Accessor } from 'solid-js';
2
-
3
- /**
4
- * A function
5
- */
6
- declare type Fn<R = void> = () => R;
7
- /**
8
- * Can be single or in an array
9
- */
10
- declare type Many<T> = T | T[];
11
- declare type Keys<O extends Object> = keyof O;
12
- declare type Values<O extends Object> = O[Keys<O>];
13
- declare type Noop = (...a: any[]) => void;
14
- /**
15
- * Infers the type of the array elements
16
- */
17
- declare type ItemsOf<T> = T extends (infer E)[] ? E : never;
18
- declare type Predicate<T> = (item: T, index: number, array: readonly T[]) => boolean;
19
- declare type MappingFn<T, V> = (item: T, index: number, array: readonly T[]) => V;
20
- /**
21
- * T or a reactive/non-reactive function returning T
22
- */
23
- declare type MaybeAccessor<T> = T | Accessor<T>;
24
- /**
25
- * Accessed value of a MaybeAccessor
26
- * @example
27
- * ```ts
28
- * MaybeAccessorValue<MaybeAccessor<string>>
29
- * // => string
30
- * MaybeAccessorValue<MaybeAccessor<() => string>>
31
- * // => string | (() => string)
32
- * MaybeAccessorValue<MaybeAccessor<string> | Function>
33
- * // => string | void
34
- * ```
35
- */
36
- declare type MaybeAccessorValue<T extends MaybeAccessor<any>> = T extends Fn ? ReturnType<T> : T;
37
- declare type OnAccessEffectFunction<S, Prev, Next extends Prev = Prev> = (input: AccessReturnTypes<S>, prevInput: AccessReturnTypes<S>, v: Prev) => Next;
38
- declare type AccessReturnTypes<S> = S extends MaybeAccessor<any>[] ? {
39
- [I in keyof S]: AccessReturnTypes<S[I]>;
40
- } : MaybeAccessorValue<S>;
41
- /** Allows to make shallow overwrites to an interface */
42
- declare type Modify<T, R> = Omit<T, keyof R> & R;
43
- /** Allows to make nested overwrites to an interface */
44
- declare type ModifyDeep<A extends AnyObject, B extends DeepPartialAny<A>> = {
45
- [K in keyof A]: B[K] extends never ? A[K] : B[K] extends AnyObject ? ModifyDeep<A[K], B[K]> : B[K];
46
- } & (A extends AnyObject ? Omit<B, keyof A> : A);
47
- /** Makes each property optional and turns each leaf property into any, allowing for type overrides by narrowing any. */
48
- declare type DeepPartialAny<T> = {
49
- [P in keyof T]?: T[P] extends AnyObject ? DeepPartialAny<T[P]> : any;
50
- };
51
- declare type AnyObject = Record<string, any>;
52
- declare type AnyFunction = (...args: any[]) => any;
53
- declare type PrimitiveValue = string | boolean | number | bigint | symbol | null | undefined;
54
- declare type FalsyValue = false | 0 | "" | null | undefined;
55
- declare type Truthy<T> = T extends FalsyValue ? never : T;
56
- declare type Falsy<T> = T extends FalsyValue ? T : never;
57
- /**
58
- * Destructible store object, with values changed to accessors
59
- */
60
- declare type Destore<T extends Object> = {
61
- [K in keyof T]: T[K] extends Function ? T[K] : Accessor<T[K]>;
62
- };
63
-
64
- export { AnyFunction as A, Destore as D, Fn as F, ItemsOf as I, Keys as K, MaybeAccessorValue as M, Noop as N, OnAccessEffectFunction as O, Predicate as P, Truthy as T, Values as V, MaybeAccessor as a, Many as b, MappingFn as c, AccessReturnTypes as d, Modify as e, ModifyDeep as f, DeepPartialAny as g, AnyObject as h, PrimitiveValue as i, FalsyValue as j, Falsy as k };