@solid-primitives/utils 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -25,24 +25,31 @@ 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
34
  destore: () => destore,
35
35
  entries: () => entries,
36
36
  forEach: () => forEach,
37
+ isArray: () => isArray,
38
+ isBoolean: () => isBoolean,
37
39
  isClient: () => isClient,
38
40
  isDefined: () => isDefined,
39
41
  isFunction: () => isFunction,
42
+ isNumber: () => isNumber,
43
+ isObject: () => isObject,
40
44
  isServer: () => import_web.isServer,
45
+ isString: () => isString,
46
+ keys: () => keys,
41
47
  noop: () => noop,
42
48
  onAccess: () => onAccess,
43
49
  onRootCleanup: () => onRootCleanup,
44
50
  promiseTimeout: () => promiseTimeout,
45
51
  raceTimeout: () => raceTimeout,
52
+ tuple: () => tuple,
46
53
  withAccess: () => withAccess
47
54
  });
48
55
  var import_solid_js = require("solid-js");
@@ -51,9 +58,17 @@ var noop = () => void 0;
51
58
  var isClient = !import_web.isServer;
52
59
  var isDefined = (value) => typeof value !== "undefined" && value !== null;
53
60
  var isFunction = (value) => typeof value === "function";
61
+ var isBoolean = (val) => typeof val === "boolean";
62
+ var isNumber = (val) => typeof val === "number";
63
+ var isString = (val) => typeof val === "string";
64
+ var isObject = (val) => toString.call(val) === "[object Object]";
65
+ var isArray = (val) => Array.isArray(val);
66
+ var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
67
+ var tuple = (input) => input;
54
68
  var access = (v) => isFunction(v) ? v() : v;
55
69
  var accessAsArray = (value) => asArray(access(value));
56
70
  var asArray = (value) => Array.isArray(value) ? value : [value];
71
+ var accessArray = (list) => list.map((v) => access(v));
57
72
  var withAccess = (value, fn) => {
58
73
  const _value = access(value);
59
74
  isDefined(_value) && fn(_value);
@@ -65,6 +80,7 @@ function onAccess(deps, fn, options) {
65
80
  }
66
81
  var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
67
82
  var entries = (object) => Object.entries(access(object));
83
+ var keys = (object) => Object.keys(access(object));
68
84
  var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
69
85
  function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
70
86
  const promises = asArray(input);
@@ -74,6 +90,7 @@ function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
74
90
  });
75
91
  return race;
76
92
  }
93
+ var onRootCleanup = (fn) => (0, import_solid_js.getOwner)() ? (0, import_solid_js.onCleanup)(fn) : fn;
77
94
  function destore(store) {
78
95
  const _store = store;
79
96
  const result = {};
@@ -82,15 +99,6 @@ function destore(store) {
82
99
  });
83
100
  return result;
84
101
  }
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
102
  var createCallbackStack = () => {
95
103
  let stack = [];
96
104
  const clear = () => stack = [];
@@ -107,23 +115,30 @@ module.exports = __toCommonJS(src_exports);
107
115
  // Annotate the CommonJS export names for ESM import in node:
108
116
  0 && (module.exports = {
109
117
  access,
118
+ accessArray,
110
119
  accessAsArray,
111
120
  asAccessor,
112
121
  asArray,
122
+ compare,
113
123
  createCallbackStack,
114
- createSubRoot,
115
- createSubRootFunction,
116
124
  destore,
117
125
  entries,
118
126
  forEach,
127
+ isArray,
128
+ isBoolean,
119
129
  isClient,
120
130
  isDefined,
121
131
  isFunction,
132
+ isNumber,
133
+ isObject,
122
134
  isServer,
135
+ isString,
136
+ keys,
123
137
  noop,
124
138
  onAccess,
125
139
  onRootCleanup,
126
140
  promiseTimeout,
127
141
  raceTimeout,
142
+ tuple,
128
143
  withAccess
129
144
  });
package/dist/index.d.ts CHANGED
@@ -1,9 +1,66 @@
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
+ /**
11
+ * Can be single or in an array
12
+ */
13
+ declare type Many<T> = T | T[];
14
+ declare type Keys<O extends Object> = keyof O;
15
+ declare type Values<O extends Object> = O[Keys<O>];
16
+ declare type Noop = (...a: any[]) => void;
17
+ /**
18
+ * Infers the type of the array elements
19
+ */
20
+ declare type ItemsOf<T> = T extends (infer E)[] ? E : never;
21
+ /**
22
+ * T or a reactive/non-reactive function returning T
23
+ */
24
+ declare type MaybeAccessor<T> = T | Accessor<T>;
25
+ /**
26
+ * Accessed value of a MaybeAccessor
27
+ * @example
28
+ * ```ts
29
+ * MaybeAccessorValue<MaybeAccessor<string>>
30
+ * // => string
31
+ * MaybeAccessorValue<MaybeAccessor<() => string>>
32
+ * // => string | (() => string)
33
+ * MaybeAccessorValue<MaybeAccessor<string> | Function>
34
+ * // => string | void
35
+ * ```
36
+ */
37
+ declare type MaybeAccessorValue<T extends MaybeAccessor<any>> = T extends Fn ? ReturnType<T> : T;
38
+ declare type OnAccessEffectFunction<S, Prev, Next extends Prev = Prev> = (input: AccessReturnTypes<S>, prevInput: AccessReturnTypes<S>, v: Prev) => Next;
39
+ declare type AccessReturnTypes<S> = S extends MaybeAccessor<any>[] ? {
40
+ [I in keyof S]: AccessReturnTypes<S[I]>;
41
+ } : MaybeAccessorValue<S>;
42
+ /** Allows to make shallow overwrites to an interface */
43
+ declare type Modify<T, R> = Omit<T, keyof R> & R;
44
+ /** Allows to make nested overwrites to an interface */
45
+ declare type ModifyDeep<A extends AnyObject, B extends DeepPartialAny<A>> = {
46
+ [K in keyof A]: B[K] extends never ? A[K] : B[K] extends AnyObject ? ModifyDeep<A[K], B[K]> : B[K];
47
+ } & (A extends AnyObject ? Omit<B, keyof A> : A);
48
+ /** Makes each property optional and turns each leaf property into any, allowing for type overrides by narrowing any. */
49
+ declare type DeepPartialAny<T> = {
50
+ [P in keyof T]?: T[P] extends AnyObject ? DeepPartialAny<T[P]> : any;
51
+ };
52
+ declare type AnyObject = Record<string, any>;
53
+ declare type AnyFunction = (...args: any[]) => any;
54
+ declare type PrimitiveValue = string | boolean | number | bigint | symbol | null | undefined;
55
+ declare type FalsyValue = false | 0 | "" | null | undefined;
56
+ declare type Truthy<T> = T extends FalsyValue ? never : T;
57
+ declare type Falsy<T> = T extends FalsyValue ? T : never;
58
+ /**
59
+ * Destructible store object, with values changed to accessors
60
+ */
61
+ declare type Destore<T extends Object> = {
62
+ [K in keyof T]: T[K] extends Function ? T[K] : Accessor<T[K]>;
63
+ };
7
64
 
8
65
  /** no operation */
9
66
  declare const noop: Noop;
@@ -14,6 +71,19 @@ declare const isClient = true;
14
71
  */
15
72
  declare const isDefined: <T>(value: T | null | undefined) => value is T;
16
73
  declare const isFunction: <T>(value: Function | T) => value is Function;
74
+ declare const isBoolean: (val: any) => val is boolean;
75
+ declare const isNumber: (val: any) => val is number;
76
+ declare const isString: (val: unknown) => val is string;
77
+ declare const isObject: (val: any) => val is object;
78
+ declare const isArray: (val: any) => val is any[];
79
+ declare const compare: (a: any, b: any) => number;
80
+ /**
81
+ * for creating tuples by inferring type
82
+ * @example
83
+ * const users = tuple(["John", "Jeff", "Joe"]);
84
+ * // users: [string, string, string]
85
+ */
86
+ declare const tuple: <T extends any[] | []>(input: T) => T;
17
87
  /**
18
88
  * Accesses the value of a MaybeAccessor
19
89
  * @example
@@ -35,6 +105,13 @@ declare const access: <T extends unknown>(v: T) => MaybeAccessorValue<T>;
35
105
  */
36
106
  declare const accessAsArray: <T extends unknown, V = MaybeAccessorValue<T>>(value: T) => V extends any[] ? V : V[];
37
107
  declare const asArray: <T>(value: T) => T extends any[] ? T : T[];
108
+ /**
109
+ * Access an array of MaybeAccessors
110
+ * @example
111
+ * const list = [1, 2, () => 3)] // T: MaybeAccessor<number>[]
112
+ * const newList = accessArray(list) // T: number[]
113
+ */
114
+ declare const accessArray: <A extends unknown>(list: readonly A[]) => MaybeAccessorValue<A>[];
38
115
  /**
39
116
  * Run the function if the accessed value is not `undefined` nor `null`
40
117
  * @param value
@@ -57,9 +134,13 @@ declare const forEach: <A extends unknown, V = MaybeAccessorValue<A>>(array: A,
57
134
  /**
58
135
  * Get `Object.entries()` of an MaybeAccessor<Object>
59
136
  */
60
- declare const entries: <A extends MaybeAccessor<Object>, V = MaybeAccessorValue<A>>(object: A) => [string, Values<V>][];
137
+ declare const entries: <A extends MaybeAccessor<object>, V = MaybeAccessorValue<A>>(object: A) => [string, Values<V>][];
138
+ /**
139
+ * Get `Object.keys()` of an MaybeAccessor<Object>
140
+ */
141
+ declare const keys: <A extends MaybeAccessor<object>>(object: A) => (keyof MaybeAccessorValue<A>)[];
61
142
  /**
62
- * Creates a promise that resolves *(or rejects)* after gives time.
143
+ * Creates a promise that resolves *(or rejects)* after given time.
63
144
  *
64
145
  * @param ms timeout duration in ms
65
146
  * @param throwOnTimeout promise will be rejected on timeout if set to `true`
@@ -94,6 +175,10 @@ declare const promiseTimeout: (ms: number, throwOnTimeout?: boolean, reason?: st
94
175
  */
95
176
  declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout: true, reason?: string): T extends any[] ? Promise<Awaited<T[number]>> : Promise<Awaited<T>>;
96
177
  declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolean, reason?: string): T extends any[] ? Promise<Awaited<T[number]> | undefined> : Promise<Awaited<T> | undefined>;
178
+ /**
179
+ * Solid's `onCleanup` that is registered only if there is a root.
180
+ */
181
+ declare const onRootCleanup: typeof onCleanup;
97
182
  /**
98
183
  * Allows the Solid's store to be destructured
99
184
  *
@@ -112,41 +197,10 @@ declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolea
112
197
  * ```
113
198
  */
114
199
  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
200
  declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {
147
201
  push: (...callbacks: Fn[]) => void;
148
202
  execute: (arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void;
149
203
  clear: Fn;
150
204
  };
151
205
 
152
- export { access, accessAsArray, asAccessor, asArray, createCallbackStack, createSubRoot, createSubRootFunction, destore, entries, forEach, isClient, isDefined, isFunction, noop, onAccess, onRootCleanup, promiseTimeout, raceTimeout, withAccess };
206
+ export { AccessReturnTypes, AnyFunction, AnyObject, DeepPartialAny, Destore, Falsy, FalsyValue, Fn, ItemsOf, Keys, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Noop, OnAccessEffectFunction, PrimitiveValue, Truthy, Values, access, accessArray, accessAsArray, asAccessor, asArray, compare, createCallbackStack, destore, entries, forEach, isArray, isBoolean, isClient, isDefined, isFunction, isNumber, isObject, isString, keys, noop, onAccess, onRootCleanup, promiseTimeout, raceTimeout, tuple, withAccess };
package/dist/index.js CHANGED
@@ -1,13 +1,21 @@
1
1
  // src/index.ts
2
- import { createRoot, getOwner, onCleanup, runWithOwner, on } from "solid-js";
2
+ import { getOwner, onCleanup, on } from "solid-js";
3
3
  import { isServer } from "solid-js/web";
4
4
  var noop = () => void 0;
5
5
  var isClient = !isServer;
6
6
  var isDefined = (value) => typeof value !== "undefined" && value !== null;
7
7
  var isFunction = (value) => typeof value === "function";
8
+ var isBoolean = (val) => typeof val === "boolean";
9
+ var isNumber = (val) => typeof val === "number";
10
+ var isString = (val) => typeof val === "string";
11
+ var isObject = (val) => toString.call(val) === "[object Object]";
12
+ var isArray = (val) => Array.isArray(val);
13
+ var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
14
+ var tuple = (input) => input;
8
15
  var access = (v) => isFunction(v) ? v() : v;
9
16
  var accessAsArray = (value) => asArray(access(value));
10
17
  var asArray = (value) => Array.isArray(value) ? value : [value];
18
+ var accessArray = (list) => list.map((v) => access(v));
11
19
  var withAccess = (value, fn) => {
12
20
  const _value = access(value);
13
21
  isDefined(_value) && fn(_value);
@@ -19,6 +27,7 @@ function onAccess(deps, fn, options) {
19
27
  }
20
28
  var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
21
29
  var entries = (object) => Object.entries(access(object));
30
+ var keys = (object) => Object.keys(access(object));
22
31
  var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
23
32
  function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
24
33
  const promises = asArray(input);
@@ -28,6 +37,7 @@ function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
28
37
  });
29
38
  return race;
30
39
  }
40
+ var onRootCleanup = (fn) => getOwner() ? onCleanup(fn) : fn;
31
41
  function destore(store) {
32
42
  const _store = store;
33
43
  const result = {};
@@ -36,15 +46,6 @@ function destore(store) {
36
46
  });
37
47
  return result;
38
48
  }
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
49
  var createCallbackStack = () => {
49
50
  let stack = [];
50
51
  const clear = () => stack = [];
@@ -59,23 +60,30 @@ var createCallbackStack = () => {
59
60
  };
60
61
  export {
61
62
  access,
63
+ accessArray,
62
64
  accessAsArray,
63
65
  asAccessor,
64
66
  asArray,
67
+ compare,
65
68
  createCallbackStack,
66
- createSubRoot,
67
- createSubRootFunction,
68
69
  destore,
69
70
  entries,
70
71
  forEach,
72
+ isArray,
73
+ isBoolean,
71
74
  isClient,
72
75
  isDefined,
73
76
  isFunction,
77
+ isNumber,
78
+ isObject,
74
79
  isServer,
80
+ isString,
81
+ keys,
75
82
  noop,
76
83
  onAccess,
77
84
  onRootCleanup,
78
85
  promiseTimeout,
79
86
  raceTimeout,
87
+ tuple,
80
88
  withAccess
81
89
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solid-primitives/utils",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "A bunch of reactive utility types and functions, for building primitives with Solid.js",
5
5
  "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",
6
6
  "license": "MIT",
@@ -18,33 +18,6 @@
18
18
  "files": [
19
19
  "dist"
20
20
  ],
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
21
  "scripts": {
49
22
  "build": "tsup",
50
23
  "test": "uvu -r solid-register",
@@ -71,4 +44,4 @@
71
44
  "peerDependencies": {
72
45
  "solid-js": "^1.3.1"
73
46
  }
74
- }
47
+ }
@@ -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 };