@solid-primitives/utils 0.0.255 → 0.1.2
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 +41 -1
- package/dist/chunk-UFTWPD62.js +44 -0
- package/dist/fp.cjs +83 -0
- package/dist/fp.d.ts +92 -0
- package/dist/fp.js +28 -0
- package/dist/index.cjs +83 -37
- package/dist/index.d.ts +139 -19
- package/dist/index.js +52 -29
- package/dist/setter.cjs +72 -0
- package/dist/setter.d.ts +17 -0
- package/dist/setter.js +27 -0
- package/dist/types-5d7b3b37.d.ts +64 -0
- package/package.json +41 -8
package/README.md
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
# @solid-primitives/utils
|
|
2
2
|
|
|
3
|
-
Solid Primitives Utilities is a support and helper package for a number of primitives in our library. Please free to augment or
|
|
3
|
+
Solid Primitives Utilities is a support and helper package for a number of primitives in our library. Please free to augment or centralize useful utilities and methods in this package for sharing.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @solid-primitives/utils
|
|
9
|
+
# or
|
|
10
|
+
yarn add @solid-primitives/utils
|
|
11
|
+
```
|
|
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).
|
|
4
32
|
|
|
5
33
|
## Changelog
|
|
6
34
|
|
|
@@ -15,4 +43,16 @@ First commit of the timer primitive.
|
|
|
15
43
|
|
|
16
44
|
Republished version with better ESM support and build tooling.
|
|
17
45
|
|
|
46
|
+
0.0.260
|
|
47
|
+
|
|
48
|
+
Added comments for util methods.
|
|
49
|
+
|
|
50
|
+
0.1.0
|
|
51
|
+
|
|
52
|
+
Add `/fp` and `/setter` export entries. Add `destore` and `raceTimeout` util. More jsdoc.
|
|
53
|
+
|
|
54
|
+
0.1.2
|
|
55
|
+
|
|
56
|
+
Updated to Solid 1.3
|
|
57
|
+
|
|
18
58
|
</details>
|
|
@@ -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,92 @@
|
|
|
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
|
+
/**
|
|
72
|
+
* Create a new subset object without the provided keys
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const newObject = omit({ a:"foo", b:"bar", c: "baz" }, 'a', 'b')
|
|
77
|
+
* newObject // => { c: "baz" }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
declare const omit: <O extends object, K extends keyof O>(object: O, ...keys: K[]) => Omit<O, K>;
|
|
81
|
+
/**
|
|
82
|
+
* Create a new subset object with only the provided keys
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const newObject = pick({ a:"foo", b:"bar", c: "baz" }, 'a', 'b')
|
|
87
|
+
* newObject // => { a:"foo", b:"bar" }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare const pick: <O extends object, K extends keyof O>(object: O, ...keys: K[]) => Pick<O, K>;
|
|
91
|
+
|
|
92
|
+
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
CHANGED
|
@@ -1,49 +1,96 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2
5
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
3
6
|
var __export = (target, all) => {
|
|
4
|
-
__markAsModule(target);
|
|
5
7
|
for (var name in all)
|
|
6
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
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);
|
|
8
23
|
|
|
9
24
|
// src/index.ts
|
|
10
|
-
|
|
25
|
+
var src_exports = {};
|
|
26
|
+
__export(src_exports, {
|
|
11
27
|
access: () => access,
|
|
12
28
|
accessAsArray: () => accessAsArray,
|
|
13
|
-
|
|
29
|
+
asAccessor: () => asAccessor,
|
|
30
|
+
asArray: () => asArray,
|
|
14
31
|
createCallbackStack: () => createCallbackStack,
|
|
32
|
+
createSubRoot: () => createSubRoot,
|
|
33
|
+
createSubRootFunction: () => createSubRootFunction,
|
|
34
|
+
destore: () => destore,
|
|
15
35
|
entries: () => entries,
|
|
16
36
|
forEach: () => forEach,
|
|
17
37
|
isClient: () => isClient,
|
|
18
|
-
|
|
38
|
+
isDefined: () => isDefined,
|
|
39
|
+
isFunction: () => isFunction,
|
|
40
|
+
isServer: () => import_web.isServer,
|
|
41
|
+
noop: () => noop,
|
|
42
|
+
onAccess: () => onAccess,
|
|
43
|
+
onRootCleanup: () => onRootCleanup,
|
|
19
44
|
promiseTimeout: () => promiseTimeout,
|
|
20
|
-
|
|
21
|
-
toArray: () => toArray,
|
|
22
|
-
toFloat: () => toFloat,
|
|
23
|
-
toInt: () => toInt,
|
|
45
|
+
raceTimeout: () => raceTimeout,
|
|
24
46
|
withAccess: () => withAccess
|
|
25
47
|
});
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
48
|
+
var import_solid_js = require("solid-js");
|
|
49
|
+
var import_web = require("solid-js/web");
|
|
50
|
+
var noop = () => void 0;
|
|
51
|
+
var isClient = !import_web.isServer;
|
|
52
|
+
var isDefined = (value) => typeof value !== "undefined" && value !== null;
|
|
53
|
+
var isFunction = (value) => typeof value === "function";
|
|
54
|
+
var access = (v) => isFunction(v) ? v() : v;
|
|
55
|
+
var accessAsArray = (value) => asArray(access(value));
|
|
56
|
+
var asArray = (value) => Array.isArray(value) ? value : [value];
|
|
32
57
|
var withAccess = (value, fn) => {
|
|
33
58
|
const _value = access(value);
|
|
34
|
-
|
|
35
|
-
fn(_value);
|
|
59
|
+
isDefined(_value) && fn(_value);
|
|
36
60
|
};
|
|
61
|
+
var asAccessor = (v) => isFunction(v) ? v : () => v;
|
|
62
|
+
function onAccess(deps, fn, options) {
|
|
63
|
+
const source = deps.map(asAccessor);
|
|
64
|
+
return (0, import_solid_js.on)(source, fn, options);
|
|
65
|
+
}
|
|
37
66
|
var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
|
|
38
67
|
var entries = (object) => Object.entries(access(object));
|
|
39
68
|
var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
69
|
+
function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
|
|
70
|
+
const promises = asArray(input);
|
|
71
|
+
const race = Promise.race([...promises, promiseTimeout(ms, throwOnTimeout, reason)]);
|
|
72
|
+
race.finally(() => {
|
|
73
|
+
promises.forEach((p) => p && typeof p === "object" && typeof p.dispose === "function" && p.dispose());
|
|
74
|
+
});
|
|
75
|
+
return race;
|
|
76
|
+
}
|
|
77
|
+
function destore(store) {
|
|
78
|
+
const _store = store;
|
|
79
|
+
const result = {};
|
|
80
|
+
Object.keys(_store).forEach((key) => {
|
|
81
|
+
result[key] = isFunction(_store[key]) ? _store[key].bind(_store) : () => _store[key];
|
|
82
|
+
});
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
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
|
+
}
|
|
47
94
|
var createCallbackStack = () => {
|
|
48
95
|
let stack = [];
|
|
49
96
|
const clear = () => stack = [];
|
|
@@ -56,28 +103,27 @@ var createCallbackStack = () => {
|
|
|
56
103
|
clear
|
|
57
104
|
};
|
|
58
105
|
};
|
|
59
|
-
|
|
60
|
-
var concat = (...a) => a.reduce((t, c) => {
|
|
61
|
-
const v = access(c);
|
|
62
|
-
return Array.isArray(v) ? [...t, ...v] : [...t, v];
|
|
63
|
-
}, []);
|
|
64
|
-
var toFloat = (string) => Number.parseFloat(access(string));
|
|
65
|
-
var toInt = (string, radix) => Number.parseInt(access(string), radix);
|
|
66
|
-
var toArray = (...a) => a.map((v) => access(v));
|
|
106
|
+
module.exports = __toCommonJS(src_exports);
|
|
67
107
|
// Annotate the CommonJS export names for ESM import in node:
|
|
68
108
|
0 && (module.exports = {
|
|
69
109
|
access,
|
|
70
110
|
accessAsArray,
|
|
71
|
-
|
|
111
|
+
asAccessor,
|
|
112
|
+
asArray,
|
|
72
113
|
createCallbackStack,
|
|
114
|
+
createSubRoot,
|
|
115
|
+
createSubRootFunction,
|
|
116
|
+
destore,
|
|
73
117
|
entries,
|
|
74
118
|
forEach,
|
|
75
119
|
isClient,
|
|
76
|
-
|
|
120
|
+
isDefined,
|
|
121
|
+
isFunction,
|
|
122
|
+
isServer,
|
|
123
|
+
noop,
|
|
124
|
+
onAccess,
|
|
125
|
+
onRootCleanup,
|
|
77
126
|
promiseTimeout,
|
|
78
|
-
|
|
79
|
-
toArray,
|
|
80
|
-
toFloat,
|
|
81
|
-
toInt,
|
|
127
|
+
raceTimeout,
|
|
82
128
|
withAccess
|
|
83
129
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,32 +1,152 @@
|
|
|
1
|
-
import { Accessor } from 'solid-js';
|
|
1
|
+
import { Accessor, onCleanup } from 'solid-js';
|
|
2
|
+
import { OnOptions, EffectFunction, NoInfer, Owner } from 'solid-js/types/reactive/signal';
|
|
3
|
+
import { Store } from 'solid-js/store';
|
|
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';
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
declare
|
|
5
|
-
declare
|
|
6
|
-
|
|
8
|
+
/** no operation */
|
|
9
|
+
declare const noop: Noop;
|
|
10
|
+
declare const isClient = true;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* `if (typeof value !== "undefined" && value !== null)`
|
|
14
|
+
*/
|
|
15
|
+
declare const isDefined: <T>(value: T | null | undefined) => value is T;
|
|
16
|
+
declare const isFunction: <T>(value: Function | T) => value is Function;
|
|
7
17
|
/**
|
|
8
|
-
*
|
|
18
|
+
* Accesses the value of a MaybeAccessor
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* access("foo") // => "foo"
|
|
22
|
+
* access(() => "foo") // => "foo"
|
|
23
|
+
* ```
|
|
9
24
|
*/
|
|
10
|
-
declare type ItemsOf<T> = T extends (infer E)[] ? E : never;
|
|
11
|
-
declare type MaybeAccessor<T> = T | Accessor<T>;
|
|
12
|
-
declare type MaybeAccessorValue<T extends MaybeAccessor<any>> = T extends Fn ? ReturnType<T> : T;
|
|
13
|
-
declare const isClient: boolean;
|
|
14
25
|
declare const access: <T extends unknown>(v: T) => MaybeAccessorValue<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Accesses the value of a MaybeAccessor, but always returns an array
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* accessAsArray('abc') // => ['abc']
|
|
31
|
+
* accessAsArray(() => 'abc') // => ['abc']
|
|
32
|
+
* accessAsArray([1,2,3]) // => [1,2,3]
|
|
33
|
+
* accessAsArray(() => [1,2,3]) // => [1,2,3]
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
15
36
|
declare const accessAsArray: <T extends unknown, V = MaybeAccessorValue<T>>(value: T) => V extends any[] ? V : V[];
|
|
37
|
+
declare const asArray: <T>(value: T) => T extends any[] ? T : T[];
|
|
38
|
+
/**
|
|
39
|
+
* Run the function if the accessed value is not `undefined` nor `null`
|
|
40
|
+
* @param value
|
|
41
|
+
* @param fn
|
|
42
|
+
*/
|
|
16
43
|
declare const withAccess: <T, A extends MaybeAccessor<T>, V = MaybeAccessorValue<A>>(value: A, fn: (value: NonNullable<V>) => void) => void;
|
|
44
|
+
declare const asAccessor: <A extends unknown>(v: A) => Accessor<MaybeAccessorValue<A>>;
|
|
45
|
+
declare function onAccess<S extends MaybeAccessor<unknown>[] | [], Next, Init = unknown>(deps: S, fn: OnAccessEffectFunction<S, Init | Next, Next>, options?: OnOptions): EffectFunction<NoInfer<Init> | NoInfer<Next>, NoInfer<Next>>;
|
|
46
|
+
/**
|
|
47
|
+
* Quickly iterate over an MaybeAccessor<any>
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const myFunc = (source: MaybeAccessor<string[]>) => {
|
|
52
|
+
* forEach(source, item => console.log(item))
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
17
56
|
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
|
+
/**
|
|
58
|
+
* Get `Object.entries()` of an MaybeAccessor<Object>
|
|
59
|
+
*/
|
|
18
60
|
declare const entries: <A extends MaybeAccessor<Object>, V = MaybeAccessorValue<A>>(object: A) => [string, Values<V>][];
|
|
61
|
+
/**
|
|
62
|
+
* Creates a promise that resolves *(or rejects)* after gives time.
|
|
63
|
+
*
|
|
64
|
+
* @param ms timeout duration in ms
|
|
65
|
+
* @param throwOnTimeout promise will be rejected on timeout if set to `true`
|
|
66
|
+
* @param reason rejection reason
|
|
67
|
+
* @returns Promise<void>
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* await promiseTimeout(1500) // will resolve void after timeout
|
|
72
|
+
* await promiseTimeout(1500, true, 'rejection reason') // will reject 'rejection reason' after timout
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
19
75
|
declare const promiseTimeout: (ms: number, throwOnTimeout?: boolean, reason?: string) => Promise<void>;
|
|
20
|
-
|
|
21
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Combination of `Promise.race()` and `promiseTimeout`.
|
|
78
|
+
*
|
|
79
|
+
* @param promises single promise, or array of promises
|
|
80
|
+
* @param ms timeout duration in ms
|
|
81
|
+
* @param throwOnTimeout promise will be rejected on timeout if set to `true`
|
|
82
|
+
* @param reason rejection reason
|
|
83
|
+
* @returns a promise resulting in value of the first source promises to be resolved
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* // single promise
|
|
88
|
+
* await raceTimeout(new Promise(() => {...}), 3000)
|
|
89
|
+
* // list of promises racing
|
|
90
|
+
* await raceTimeout([new Promise(),new Promise()...], 3000)
|
|
91
|
+
* // reject on timeout
|
|
92
|
+
* await raceTimeout(new Promise(), 3000, true, 'rejection reason')
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout: true, reason?: string): T extends any[] ? Promise<Awaited<T[number]>> : Promise<Awaited<T>>;
|
|
96
|
+
declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolean, reason?: string): T extends any[] ? Promise<Awaited<T[number]> | undefined> : Promise<Awaited<T> | undefined>;
|
|
97
|
+
/**
|
|
98
|
+
* Allows the Solid's store to be destructured
|
|
99
|
+
*
|
|
100
|
+
* @param store
|
|
101
|
+
* @returns Destructible object, with values changed to accessors
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const [state, setState] = createStore({
|
|
106
|
+
* count: 0,
|
|
107
|
+
* get double() { return this.count * 2 },
|
|
108
|
+
* })
|
|
109
|
+
* const { count, double } = destore(state)
|
|
110
|
+
* // use it like a signal:
|
|
111
|
+
* count()
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
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
|
+
declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {
|
|
22
147
|
push: (...callbacks: Fn[]) => void;
|
|
23
|
-
execute: (arg0:
|
|
148
|
+
execute: (arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void;
|
|
24
149
|
clear: Fn;
|
|
25
150
|
};
|
|
26
|
-
declare const stringConcat: (...a: MaybeAccessor<any>[]) => string;
|
|
27
|
-
declare const concat: <A extends any[], V = MaybeAccessorValue<ItemsOf<A>>>(...a: A) => (V extends any[] ? ItemsOf<V> : V)[];
|
|
28
|
-
declare const toFloat: (string: MaybeAccessor<string>) => number;
|
|
29
|
-
declare const toInt: (string: MaybeAccessor<string>, radix?: number | undefined) => number;
|
|
30
|
-
declare const toArray: <A extends any[]>(...a: A) => MaybeAccessorValue<ItemsOf<A>>[];
|
|
31
151
|
|
|
32
|
-
export {
|
|
152
|
+
export { access, accessAsArray, asAccessor, asArray, createCallbackStack, createSubRoot, createSubRootFunction, destore, entries, forEach, isClient, isDefined, isFunction, noop, onAccess, onRootCleanup, promiseTimeout, raceTimeout, withAccess };
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,50 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { createRoot, getOwner, onCleanup, runWithOwner, on } from "solid-js";
|
|
3
|
+
import { isServer } from "solid-js/web";
|
|
4
|
+
var noop = () => void 0;
|
|
5
|
+
var isClient = !isServer;
|
|
6
|
+
var isDefined = (value) => typeof value !== "undefined" && value !== null;
|
|
7
|
+
var isFunction = (value) => typeof value === "function";
|
|
8
|
+
var access = (v) => isFunction(v) ? v() : v;
|
|
9
|
+
var accessAsArray = (value) => asArray(access(value));
|
|
10
|
+
var asArray = (value) => Array.isArray(value) ? value : [value];
|
|
8
11
|
var withAccess = (value, fn) => {
|
|
9
12
|
const _value = access(value);
|
|
10
|
-
|
|
11
|
-
fn(_value);
|
|
13
|
+
isDefined(_value) && fn(_value);
|
|
12
14
|
};
|
|
15
|
+
var asAccessor = (v) => isFunction(v) ? v : () => v;
|
|
16
|
+
function onAccess(deps, fn, options) {
|
|
17
|
+
const source = deps.map(asAccessor);
|
|
18
|
+
return on(source, fn, options);
|
|
19
|
+
}
|
|
13
20
|
var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
|
|
14
21
|
var entries = (object) => Object.entries(access(object));
|
|
15
22
|
var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
|
|
24
|
+
const promises = asArray(input);
|
|
25
|
+
const race = Promise.race([...promises, promiseTimeout(ms, throwOnTimeout, reason)]);
|
|
26
|
+
race.finally(() => {
|
|
27
|
+
promises.forEach((p) => p && typeof p === "object" && typeof p.dispose === "function" && p.dispose());
|
|
28
|
+
});
|
|
29
|
+
return race;
|
|
30
|
+
}
|
|
31
|
+
function destore(store) {
|
|
32
|
+
const _store = store;
|
|
33
|
+
const result = {};
|
|
34
|
+
Object.keys(_store).forEach((key) => {
|
|
35
|
+
result[key] = isFunction(_store[key]) ? _store[key].bind(_store) : () => _store[key];
|
|
36
|
+
});
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
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
|
+
}
|
|
23
48
|
var createCallbackStack = () => {
|
|
24
49
|
let stack = [];
|
|
25
50
|
const clear = () => stack = [];
|
|
@@ -32,27 +57,25 @@ var createCallbackStack = () => {
|
|
|
32
57
|
clear
|
|
33
58
|
};
|
|
34
59
|
};
|
|
35
|
-
var stringConcat = (...a) => a.reduce((t, c) => t + access(c), "");
|
|
36
|
-
var concat = (...a) => a.reduce((t, c) => {
|
|
37
|
-
const v = access(c);
|
|
38
|
-
return Array.isArray(v) ? [...t, ...v] : [...t, v];
|
|
39
|
-
}, []);
|
|
40
|
-
var toFloat = (string) => Number.parseFloat(access(string));
|
|
41
|
-
var toInt = (string, radix) => Number.parseInt(access(string), radix);
|
|
42
|
-
var toArray = (...a) => a.map((v) => access(v));
|
|
43
60
|
export {
|
|
44
61
|
access,
|
|
45
62
|
accessAsArray,
|
|
46
|
-
|
|
63
|
+
asAccessor,
|
|
64
|
+
asArray,
|
|
47
65
|
createCallbackStack,
|
|
66
|
+
createSubRoot,
|
|
67
|
+
createSubRootFunction,
|
|
68
|
+
destore,
|
|
48
69
|
entries,
|
|
49
70
|
forEach,
|
|
50
71
|
isClient,
|
|
51
|
-
|
|
72
|
+
isDefined,
|
|
73
|
+
isFunction,
|
|
74
|
+
isServer,
|
|
75
|
+
noop,
|
|
76
|
+
onAccess,
|
|
77
|
+
onRootCleanup,
|
|
52
78
|
promiseTimeout,
|
|
53
|
-
|
|
54
|
-
toArray,
|
|
55
|
-
toFloat,
|
|
56
|
-
toInt,
|
|
79
|
+
raceTimeout,
|
|
57
80
|
withAccess
|
|
58
81
|
};
|
package/dist/setter.cjs
ADDED
|
@@ -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
|
+
});
|
package/dist/setter.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
|
|
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,64 @@
|
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solid-primitives/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.2",
|
|
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,8 +18,38 @@
|
|
|
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
|
+
},
|
|
21
48
|
"scripts": {
|
|
22
|
-
"build": "tsup"
|
|
49
|
+
"build": "tsup",
|
|
50
|
+
"test": "uvu -r solid-register",
|
|
51
|
+
"watch-test": "watchlist src test -- npm test",
|
|
52
|
+
"docs": "typedoc"
|
|
23
53
|
},
|
|
24
54
|
"keywords": [
|
|
25
55
|
"utilities",
|
|
@@ -28,14 +58,17 @@
|
|
|
28
58
|
"primitives"
|
|
29
59
|
],
|
|
30
60
|
"devDependencies": {
|
|
31
|
-
"jsdom": "
|
|
32
|
-
"prettier": "^2.
|
|
33
|
-
"solid-register": "^0.
|
|
61
|
+
"jsdom": "18.1.1",
|
|
62
|
+
"prettier": "^2.5.1",
|
|
63
|
+
"solid-register": "^0.1.1",
|
|
34
64
|
"tslib": "^2.3.1",
|
|
35
|
-
"tsup": "^5.
|
|
36
|
-
"
|
|
65
|
+
"tsup": "^5.11.0",
|
|
66
|
+
"typedoc": "^0.22.10",
|
|
67
|
+
"typedoc-plugin-markdown": "^3.11.8",
|
|
68
|
+
"uvu": "^0.5.2",
|
|
69
|
+
"watchlist": "^0.3.1"
|
|
37
70
|
},
|
|
38
71
|
"peerDependencies": {
|
|
39
|
-
"solid-js": "
|
|
72
|
+
"solid-js": "1.3.0"
|
|
40
73
|
}
|
|
41
74
|
}
|