@solid-primitives/utils 0.1.0 → 0.1.1

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.
@@ -0,0 +1,44 @@
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 omit = (object, ...keys) => withObjectCopy(object, (object2) => keys.forEach((key) => delete object2[key]));
25
+ var pick = (object, ...keys) => keys.reduce((n, k) => {
26
+ if (k in object)
27
+ n[k] = object[k];
28
+ return n;
29
+ }, {});
30
+
31
+ export {
32
+ withArrayCopy,
33
+ withObjectCopy,
34
+ withCopy,
35
+ push,
36
+ drop,
37
+ filterOut,
38
+ filter,
39
+ map,
40
+ slice,
41
+ splice,
42
+ omit,
43
+ pick
44
+ };
package/dist/fp.cjs ADDED
@@ -0,0 +1,83 @@
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
+ slice: () => slice,
35
+ splice: () => splice,
36
+ withArrayCopy: () => withArrayCopy,
37
+ withCopy: () => withCopy,
38
+ withObjectCopy: () => withObjectCopy
39
+ });
40
+ var withArrayCopy = (array, mutator) => {
41
+ const copy = array.slice();
42
+ mutator(copy);
43
+ return copy;
44
+ };
45
+ var withObjectCopy = (object, mutator) => {
46
+ const copy = Object.assign({}, object);
47
+ mutator(copy);
48
+ return copy;
49
+ };
50
+ var withCopy = (source, mutator) => Array.isArray(source) ? withArrayCopy(source, mutator) : withObjectCopy(source, mutator);
51
+ var push = (list, item) => withArrayCopy(list, (list2) => list2.push(item));
52
+ var drop = (list, n = 1) => list.slice(n);
53
+ var filterOut = (list, item) => filter(list, (i) => i !== item);
54
+ function filter(list, predicate) {
55
+ const newList = list.filter(predicate);
56
+ newList.removed = list.length - newList.length;
57
+ return newList;
58
+ }
59
+ var map = (list, mapFn) => list.map(mapFn);
60
+ var slice = (list, start, end) => list.slice(start, end);
61
+ var splice = (list, start, deleteCount, ...items) => withArrayCopy(list, (list2) => list2.splice(start, deleteCount, ...items));
62
+ var omit = (object, ...keys) => withObjectCopy(object, (object2) => keys.forEach((key) => delete object2[key]));
63
+ var pick = (object, ...keys) => keys.reduce((n, k) => {
64
+ if (k in object)
65
+ n[k] = object[k];
66
+ return n;
67
+ }, {});
68
+ module.exports = __toCommonJS(fp_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
+ omit,
76
+ pick,
77
+ push,
78
+ slice,
79
+ splice,
80
+ withArrayCopy,
81
+ withCopy,
82
+ withObjectCopy
83
+ });
package/dist/fp.d.ts ADDED
@@ -0,0 +1,86 @@
1
+ import { P as Predicate, c as MappingFn } from './types-1e8c1610';
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
+ * const newList = drop([1,2,3])
36
+ * newList // => [2,3]
37
+ *
38
+ * const newList = drop([1,2,3], 2)
39
+ * newList // => [3]
40
+ */
41
+ declare const drop: <T>(list: T[], n?: number) => T[];
42
+ /**
43
+ * non-mutating `Array.prototype.filter()` that filters out passed item
44
+ * @returns changed array copy
45
+ */
46
+ declare const filterOut: <T>(list: readonly T[], item: T) => T[] & {
47
+ removed: number;
48
+ };
49
+ /**
50
+ * non-mutating `Array.prototype.filter()` as a standalone function
51
+ * @returns changed array copy
52
+ */
53
+ declare function filter<T>(list: readonly T[], predicate: Predicate<T>): T[] & {
54
+ removed: number;
55
+ };
56
+ /**
57
+ * standalone `Array.prototype.map()` function
58
+ */
59
+ declare const map: <T, V>(list: readonly T[], mapFn: MappingFn<T, V>) => V[];
60
+ /**
61
+ * standalone `Array.prototype.slice()` function
62
+ */
63
+ declare const slice: <T>(list: readonly T[], start?: number | undefined, end?: number | undefined) => T[];
64
+ /**
65
+ * non-mutating `Array.prototype.splice()` as a standalone function
66
+ * @returns changed array copy
67
+ */
68
+ declare const splice: <T>(list: readonly T[], start: number, deleteCount: number, ...items: T[]) => T[];
69
+ /**
70
+ * Create a new subset object without the provided keys
71
+ *
72
+ * @example
73
+ * const newObject = omit({ a:"foo", b:"bar", c: "baz" }, 'a', 'b')
74
+ * newObject // => { c: "baz" }
75
+ */
76
+ declare const omit: <O extends object, K extends keyof O>(object: O, ...keys: K[]) => Omit<O, K>;
77
+ /**
78
+ * Create a new subset object with only the provided keys
79
+ *
80
+ * @example
81
+ * const newObject = pick({ a:"foo", b:"bar", c: "baz" }, 'a', 'b')
82
+ * newObject // => { a:"foo", b:"bar" }
83
+ */
84
+ declare const pick: <O extends object, K extends keyof O>(object: O, ...keys: K[]) => Pick<O, K>;
85
+
86
+ export { drop, filter, filterOut, map, omit, pick, push, slice, splice, withArrayCopy, withCopy, withObjectCopy };
package/dist/fp.js ADDED
@@ -0,0 +1,28 @@
1
+ import {
2
+ drop,
3
+ filter,
4
+ filterOut,
5
+ map,
6
+ omit,
7
+ pick,
8
+ push,
9
+ slice,
10
+ splice,
11
+ withArrayCopy,
12
+ withCopy,
13
+ withObjectCopy
14
+ } from "./chunk-UFTWPD62.js";
15
+ export {
16
+ drop,
17
+ filter,
18
+ filterOut,
19
+ map,
20
+ omit,
21
+ pick,
22
+ push,
23
+ slice,
24
+ splice,
25
+ withArrayCopy,
26
+ withCopy,
27
+ withObjectCopy
28
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1,121 @@
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/index.ts
25
+ var src_exports = {};
26
+ __export(src_exports, {
27
+ access: () => access,
28
+ accessAsArray: () => accessAsArray,
29
+ concat: () => concat,
30
+ createCallbackStack: () => createCallbackStack,
31
+ destore: () => destore,
32
+ entries: () => entries,
33
+ forEach: () => forEach,
34
+ isClient: () => isClient,
35
+ isDefined: () => isDefined,
36
+ isServer: () => import_web.isServer,
37
+ noop: () => noop,
38
+ onRootCleanup: () => onRootCleanup,
39
+ promiseTimeout: () => promiseTimeout,
40
+ raceTimeout: () => raceTimeout,
41
+ stringConcat: () => stringConcat,
42
+ toArray: () => toArray,
43
+ toFloat: () => toFloat,
44
+ toInt: () => toInt,
45
+ withAccess: () => withAccess
46
+ });
47
+ var import_solid_js = require("solid-js");
48
+ var import_web = require("solid-js/web");
49
+ var noop = (...a) => {
50
+ };
51
+ var isClient = !import_web.isServer;
52
+ var isDefined = (value) => typeof value !== "undefined" && value !== null;
53
+ var access = (v) => typeof v === "function" ? v() : v;
54
+ var accessAsArray = (value) => {
55
+ const _value = access(value);
56
+ return Array.isArray(_value) ? _value : [_value];
57
+ };
58
+ var withAccess = (value, fn) => {
59
+ const _value = access(value);
60
+ isDefined(_value) && fn(_value);
61
+ };
62
+ var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
63
+ var entries = (object) => Object.entries(access(object));
64
+ var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
65
+ function raceTimeout(promises, ms, throwOnTimeout = false, reason = "Timeout") {
66
+ const promiseList = Array.isArray(promises) ? promises : [promises];
67
+ promiseList.push(promiseTimeout(ms, throwOnTimeout, reason));
68
+ return Promise.race(promiseList);
69
+ }
70
+ function destore(store) {
71
+ const _store = store;
72
+ const result = {};
73
+ Object.keys(_store).forEach((key) => {
74
+ result[key] = typeof _store[key] === "function" ? _store[key].bind(_store) : () => _store[key];
75
+ });
76
+ return result;
77
+ }
78
+ var onRootCleanup = (fn) => (0, import_solid_js.getOwner)() ? (0, import_solid_js.onCleanup)(fn) : fn;
79
+ var createCallbackStack = () => {
80
+ let stack = [];
81
+ const clear = () => stack = [];
82
+ return {
83
+ push: (...callbacks) => stack.push(...callbacks),
84
+ execute: (arg0, arg1, arg2, arg3) => {
85
+ stack.forEach((cb) => cb(arg0, arg1, arg2, arg3));
86
+ clear();
87
+ },
88
+ clear
89
+ };
90
+ };
91
+ var stringConcat = (...a) => a.reduce((t, c) => t + access(c), "");
92
+ var concat = (...a) => a.reduce((t, c) => {
93
+ const v = access(c);
94
+ return Array.isArray(v) ? [...t, ...v] : [...t, v];
95
+ }, []);
96
+ var toFloat = (string) => Number.parseFloat(access(string));
97
+ var toInt = (string, radix) => Number.parseInt(access(string), radix);
98
+ var toArray = (...a) => a.map((v) => access(v));
99
+ module.exports = __toCommonJS(src_exports);
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ access,
103
+ accessAsArray,
104
+ concat,
105
+ createCallbackStack,
106
+ destore,
107
+ entries,
108
+ forEach,
109
+ isClient,
110
+ isDefined,
111
+ isServer,
112
+ noop,
113
+ onRootCleanup,
114
+ promiseTimeout,
115
+ raceTimeout,
116
+ stringConcat,
117
+ toArray,
118
+ toFloat,
119
+ toInt,
120
+ withAccess
121
+ });
@@ -0,0 +1,113 @@
1
+ import { onCleanup } from 'solid-js';
2
+ import { Store } from 'solid-js/store';
3
+ export { isServer } from 'solid-js/web';
4
+ import { M as MaybeAccessorValue, a as MaybeAccessor, I as ItemsOf, V as Values, D as Destore, F as Fn } from './types-1e8c1610';
5
+ export { g as AnyFunction, A as AnyObject, f as DeepPartialAny, D as Destore, F as Fn, I as ItemsOf, K as Keys, b as Many, c as MappingFn, a as MaybeAccessor, M as MaybeAccessorValue, d as Modify, e as ModifyDeep, P as Predicate, h as PrimitiveValue, V as Values } from './types-1e8c1610';
6
+
7
+ /** no operation */
8
+ declare const noop: (...a: any[]) => void;
9
+ declare const isClient = true;
10
+
11
+ /**
12
+ * `if (typeof value !== "undefined" && value !== null)`
13
+ */
14
+ declare const isDefined: <T>(value: T | null | undefined) => value is T;
15
+ /**
16
+ * Accesses the value of a MaybeAccessor
17
+ * @example
18
+ * access("foo") // => "foo"
19
+ * access(() => "foo") // => "foo"
20
+ */
21
+ declare const access: <T extends unknown>(v: T) => MaybeAccessorValue<T>;
22
+ /**
23
+ * Accesses the value of a MaybeAccessor, but always returns an array
24
+ * @example
25
+ * accessAsArray('abc') // => ['abc']
26
+ * accessAsArray(() => 'abc') // => ['abc']
27
+ * accessAsArray([1,2,3]) // => [1,2,3]
28
+ * accessAsArray(() => [1,2,3]) // => [1,2,3]
29
+ */
30
+ declare const accessAsArray: <T extends unknown, V = MaybeAccessorValue<T>>(value: T) => V extends any[] ? V : V[];
31
+ /**
32
+ * Run the function if the accessed value is not `undefined` nor `null`
33
+ * @param value
34
+ * @param fn
35
+ */
36
+ declare const withAccess: <T, A extends MaybeAccessor<T>, V = MaybeAccessorValue<A>>(value: A, fn: (value: NonNullable<V>) => void) => void;
37
+ /**
38
+ * Quickly iterate over an MaybeAccessor<any>
39
+ *
40
+ * @example
41
+ * const myFunc = (source: MaybeAccessor<string[]>) => {
42
+ * forEach(source, item => console.log(item))
43
+ * }
44
+ */
45
+ 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;
46
+ /**
47
+ * Get `Object.entries()` of an MaybeAccessor<Object>
48
+ */
49
+ declare const entries: <A extends MaybeAccessor<Object>, V = MaybeAccessorValue<A>>(object: A) => [string, Values<V>][];
50
+ /**
51
+ * Creates a promise that resolves *(or rejects)* after gives time.
52
+ *
53
+ * @param ms timeout duration in ms
54
+ * @param throwOnTimeout promise will be rejected on timeout if set to `true`
55
+ * @param reason rejection reason
56
+ * @returns Promise<void>
57
+ *
58
+ * @example
59
+ * await promiseTimeout(1500) // will resolve void after timeout
60
+ * await promiseTimeout(1500, true, 'rejection reason') // will reject 'rejection reason' after timout
61
+ */
62
+ declare const promiseTimeout: (ms: number, throwOnTimeout?: boolean, reason?: string) => Promise<void>;
63
+ /**
64
+ * Combination of `Promise.race()` and `promiseTimeout`.
65
+ *
66
+ * @param promises single promise, or array of promises
67
+ * @param ms timeout duration in ms
68
+ * @param throwOnTimeout promise will be rejected on timeout if set to `true`
69
+ * @param reason rejection reason
70
+ * @returns a promise resulting in value of the first source promises to be resolved
71
+ *
72
+ * @example
73
+ * // single promise
74
+ * await raceTimeout(new Promise(() => {...}), 3000)
75
+ * // list of promises racing
76
+ * await raceTimeout([new Promise(),new Promise()...], 3000)
77
+ * // reject on timeout
78
+ * await raceTimeout(new Promise(), 3000, true, 'rejection reason')
79
+ */
80
+ declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout: true, reason?: string): T extends any[] ? Promise<Awaited<T[number]>> : Promise<Awaited<T>>;
81
+ declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolean, reason?: string): T extends any[] ? Promise<Awaited<T[number]> | undefined> : Promise<Awaited<T> | undefined>;
82
+ /**
83
+ * Allows the Solid's store to be destructured
84
+ *
85
+ * @param store
86
+ * @returns Destructible object, with values changed to accessors
87
+ *
88
+ * @example
89
+ * const [state, setState] = createStore({
90
+ * count: 0,
91
+ * get double() { return this.count * 2 },
92
+ * })
93
+ * const { count, double } = destore(state)
94
+ * // use it like a signal:
95
+ * count()
96
+ */
97
+ declare function destore<T extends Object>(store: Store<T>): Destore<T>;
98
+ /**
99
+ * Solid's `onCleanup` that runs only if there is a root.
100
+ */
101
+ declare const onRootCleanup: typeof onCleanup;
102
+ declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {
103
+ push: (...callbacks: Fn[]) => void;
104
+ execute: (arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void;
105
+ clear: Fn;
106
+ };
107
+ declare const stringConcat: (...a: MaybeAccessor<any>[]) => string;
108
+ declare const concat: <A extends any[], V = MaybeAccessorValue<ItemsOf<A>>>(...a: A) => (V extends any[] ? ItemsOf<V> : V)[];
109
+ declare const toFloat: (string: MaybeAccessor<string>) => number;
110
+ declare const toInt: (string: MaybeAccessor<string>, radix?: number | undefined) => number;
111
+ declare const toArray: <A extends any[]>(...a: A) => MaybeAccessorValue<ItemsOf<A>>[];
112
+
113
+ export { access, accessAsArray, concat, createCallbackStack, destore, entries, forEach, isClient, isDefined, noop, onRootCleanup, promiseTimeout, raceTimeout, stringConcat, toArray, toFloat, toInt, withAccess };
package/dist/index.js ADDED
@@ -0,0 +1,74 @@
1
+ // src/index.ts
2
+ import { getOwner, onCleanup } from "solid-js";
3
+ import { isServer } from "solid-js/web";
4
+ var noop = (...a) => {
5
+ };
6
+ var isClient = !isServer;
7
+ var isDefined = (value) => typeof value !== "undefined" && value !== null;
8
+ var access = (v) => typeof v === "function" ? v() : v;
9
+ var accessAsArray = (value) => {
10
+ const _value = access(value);
11
+ return Array.isArray(_value) ? _value : [_value];
12
+ };
13
+ var withAccess = (value, fn) => {
14
+ const _value = access(value);
15
+ isDefined(_value) && fn(_value);
16
+ };
17
+ var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
18
+ var entries = (object) => Object.entries(access(object));
19
+ var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
20
+ function raceTimeout(promises, ms, throwOnTimeout = false, reason = "Timeout") {
21
+ const promiseList = Array.isArray(promises) ? promises : [promises];
22
+ promiseList.push(promiseTimeout(ms, throwOnTimeout, reason));
23
+ return Promise.race(promiseList);
24
+ }
25
+ function destore(store) {
26
+ const _store = store;
27
+ const result = {};
28
+ Object.keys(_store).forEach((key) => {
29
+ result[key] = typeof _store[key] === "function" ? _store[key].bind(_store) : () => _store[key];
30
+ });
31
+ return result;
32
+ }
33
+ var onRootCleanup = (fn) => getOwner() ? onCleanup(fn) : fn;
34
+ var createCallbackStack = () => {
35
+ let stack = [];
36
+ const clear = () => stack = [];
37
+ return {
38
+ push: (...callbacks) => stack.push(...callbacks),
39
+ execute: (arg0, arg1, arg2, arg3) => {
40
+ stack.forEach((cb) => cb(arg0, arg1, arg2, arg3));
41
+ clear();
42
+ },
43
+ clear
44
+ };
45
+ };
46
+ var stringConcat = (...a) => a.reduce((t, c) => t + access(c), "");
47
+ var concat = (...a) => a.reduce((t, c) => {
48
+ const v = access(c);
49
+ return Array.isArray(v) ? [...t, ...v] : [...t, v];
50
+ }, []);
51
+ var toFloat = (string) => Number.parseFloat(access(string));
52
+ var toInt = (string, radix) => Number.parseInt(access(string), radix);
53
+ var toArray = (...a) => a.map((v) => access(v));
54
+ export {
55
+ access,
56
+ accessAsArray,
57
+ concat,
58
+ createCallbackStack,
59
+ destore,
60
+ entries,
61
+ forEach,
62
+ isClient,
63
+ isDefined,
64
+ isServer,
65
+ noop,
66
+ onRootCleanup,
67
+ promiseTimeout,
68
+ raceTimeout,
69
+ stringConcat,
70
+ toArray,
71
+ toFloat,
72
+ toInt,
73
+ withAccess
74
+ };
@@ -0,0 +1,72 @@
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
+ slice: () => slice,
33
+ splice: () => splice2
34
+ });
35
+
36
+ // src/fp.ts
37
+ var withArrayCopy = (array, mutator) => {
38
+ const copy = array.slice();
39
+ mutator(copy);
40
+ return copy;
41
+ };
42
+ var push = (list, item) => withArrayCopy(list, (list2) => list2.push(item));
43
+ var drop = (list, n = 1) => list.slice(n);
44
+ var filterOut = (list, item) => filter(list, (i) => i !== item);
45
+ function filter(list, predicate) {
46
+ const newList = list.filter(predicate);
47
+ newList.removed = list.length - newList.length;
48
+ return newList;
49
+ }
50
+ var splice = (list, start, deleteCount, ...items) => withArrayCopy(list, (list2) => list2.splice(start, deleteCount, ...items));
51
+
52
+ // src/setter.ts
53
+ var push2 = (item) => (list) => push(list, item);
54
+ var drop2 = (n = 1) => (list) => drop(list, n);
55
+ var filterOut2 = (item) => (list) => filterOut(list, item);
56
+ var filter2 = (predicate) => (list) => filter(list, predicate);
57
+ var map = (mapFn) => (list) => list.map(mapFn);
58
+ var slice = (start, end) => (list) => list.slice(start, end);
59
+ function splice2(start, deleteCount, ...items) {
60
+ return (list) => splice(list, start, deleteCount, ...items);
61
+ }
62
+ module.exports = __toCommonJS(setter_exports);
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ drop,
66
+ filter,
67
+ filterOut,
68
+ map,
69
+ push,
70
+ slice,
71
+ splice
72
+ });
@@ -0,0 +1,17 @@
1
+ import { P as Predicate, c as MappingFn } from './types-1e8c1610';
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
+
17
+ export { drop, filter, filterOut, map, push, slice, splice };
package/dist/setter.js ADDED
@@ -0,0 +1,27 @@
1
+ import {
2
+ drop,
3
+ filter,
4
+ filterOut,
5
+ push,
6
+ splice
7
+ } from "./chunk-UFTWPD62.js";
8
+
9
+ // src/setter.ts
10
+ var push2 = (item) => (list) => push(list, item);
11
+ var drop2 = (n = 1) => (list) => drop(list, n);
12
+ var filterOut2 = (item) => (list) => filterOut(list, item);
13
+ var filter2 = (predicate) => (list) => filter(list, predicate);
14
+ var map = (mapFn) => (list) => list.map(mapFn);
15
+ var slice = (start, end) => (list) => list.slice(start, end);
16
+ function splice2(start, deleteCount, ...items) {
17
+ return (list) => splice(list, start, deleteCount, ...items);
18
+ }
19
+ export {
20
+ drop2 as drop,
21
+ filter2 as filter,
22
+ filterOut2 as filterOut,
23
+ map,
24
+ push2 as push,
25
+ slice,
26
+ splice2 as splice
27
+ };
@@ -0,0 +1,54 @@
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
+ /**
14
+ * Infers the type of the array elements
15
+ */
16
+ declare type ItemsOf<T> = T extends (infer E)[] ? E : never;
17
+ declare type Predicate<T> = (item: T, index: number, array: readonly T[]) => boolean;
18
+ declare type MappingFn<T, V> = (item: T, index: number, array: readonly T[]) => V;
19
+ /**
20
+ * T or a reactive/non-reactive function returning T
21
+ */
22
+ declare type MaybeAccessor<T> = T | Accessor<T>;
23
+ /**
24
+ * Accessed value of a MaybeAccessor
25
+ * @example
26
+ * MaybeAccessorValue<MaybeAccessor<string>>
27
+ * // => string
28
+ * MaybeAccessorValue<MaybeAccessor<() => string>>
29
+ * // => string | (() => string)
30
+ * MaybeAccessorValue<MaybeAccessor<string> | Function>
31
+ * // => string | void
32
+ */
33
+ declare type MaybeAccessorValue<T extends MaybeAccessor<any>> = T extends Fn ? ReturnType<T> : T;
34
+ /** Allows to make shallow overwrites to an interface */
35
+ declare type Modify<T, R> = Omit<T, keyof R> & R;
36
+ /** Allows to make nested overwrites to an interface */
37
+ declare type ModifyDeep<A extends AnyObject, B extends DeepPartialAny<A>> = {
38
+ [K in keyof A]: B[K] extends never ? A[K] : B[K] extends AnyObject ? ModifyDeep<A[K], B[K]> : B[K];
39
+ } & (A extends AnyObject ? Omit<B, keyof A> : A);
40
+ /** Makes each property optional and turns each leaf property into any, allowing for type overrides by narrowing any. */
41
+ declare type DeepPartialAny<T> = {
42
+ [P in keyof T]?: T[P] extends AnyObject ? DeepPartialAny<T[P]> : any;
43
+ };
44
+ declare type AnyObject = Record<string, any>;
45
+ declare type AnyFunction = (...args: any[]) => any;
46
+ declare type PrimitiveValue = string | boolean | number | bigint | symbol | null | undefined;
47
+ /**
48
+ * Destructible store object, with values changed to accessors
49
+ */
50
+ declare type Destore<T extends Object> = {
51
+ [K in keyof T]: T[K] extends Function ? T[K] : Accessor<T[K]>;
52
+ };
53
+
54
+ export { AnyObject as A, Destore as D, Fn as F, ItemsOf as I, Keys as K, MaybeAccessorValue as M, Predicate as P, Values as V, MaybeAccessor as a, Many as b, MappingFn as c, Modify as d, ModifyDeep as e, DeepPartialAny as f, AnyFunction as g, PrimitiveValue as h };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solid-primitives/utils",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
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",
@@ -68,4 +68,4 @@
68
68
  "peerDependencies": {
69
69
  "solid-js": "^1.2.6"
70
70
  }
71
- }
71
+ }