@solid-primitives/utils 0.1.1 → 0.2.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.
- package/README.md +16 -4
- package/dist/index.cjs +65 -30
- package/dist/index.d.ts +120 -16
- package/dist/index.js +51 -26
- package/package.json +9 -33
- package/dist/chunk-UFTWPD62.js +0 -44
- package/dist/fp.cjs +0 -83
- package/dist/fp.d.ts +0 -86
- package/dist/fp.js +0 -28
- package/dist/setter.cjs +0 -72
- package/dist/setter.d.ts +0 -17
- package/dist/setter.js +0 -27
- package/dist/types-1e8c1610.d.ts +0 -54
package/README.md
CHANGED
|
@@ -12,20 +12,24 @@ yarn add @solid-primitives/utils
|
|
|
12
12
|
|
|
13
13
|
## Package Entries
|
|
14
14
|
|
|
15
|
-
- [`*` - `@solid-primitives/utils`](https://github.com/davedbase/solid-primitives/blob/main/packages/utils/
|
|
16
|
-
- [`/fp` - `@solid-primitives/utils/fp`](https://github.com/davedbase/solid-primitives/blob/main/packages/utils/
|
|
17
|
-
- [`/setter` - `@solid-primitives/utils/setter`](https://github.com/davedbase/solid-primitives/blob/main/packages/utils/
|
|
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
18
|
|
|
19
19
|
Import accordingly.
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
|
-
import { access, promiseTimeout } from "@solid-primitives/utils";
|
|
22
|
+
import { access, promiseTimeout, MaybeAccessor } from "@solid-primitives/utils";
|
|
23
23
|
|
|
24
24
|
// between these two some function names will overlap.
|
|
25
25
|
import { pick, omit, filter } from "@solid-primitives/utils/fp";
|
|
26
26
|
import { push, filter, drop } from "@solid-primitives/utils/setter";
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
## >>> [Modules documentation](https://github.com/davedbase/solid-primitives/blob/main/packages/utils/docs/README.md) <<<
|
|
30
|
+
|
|
31
|
+
Documentation auto-generated from the [Typescript source files](https://github.com/davedbase/solid-primitives/blob/main/packages/utils/src) using [typedoc](https://typedoc.org) + [markdown plugin](https://www.npmjs.com/package/typedoc-plugin-markdown).
|
|
32
|
+
|
|
29
33
|
## Changelog
|
|
30
34
|
|
|
31
35
|
<details>
|
|
@@ -47,4 +51,12 @@ Added comments for util methods.
|
|
|
47
51
|
|
|
48
52
|
Add `/fp` and `/setter` export entries. Add `destore` and `raceTimeout` util. More jsdoc.
|
|
49
53
|
|
|
54
|
+
0.1.2
|
|
55
|
+
|
|
56
|
+
Updated to Solid 1.3
|
|
57
|
+
|
|
58
|
+
0.1.3
|
|
59
|
+
|
|
60
|
+
Minor upgrades.
|
|
61
|
+
|
|
50
62
|
</details>
|
package/dist/index.cjs
CHANGED
|
@@ -25,57 +25,90 @@ 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,
|
|
31
|
+
asArray: () => asArray,
|
|
32
|
+
compare: () => compare,
|
|
30
33
|
createCallbackStack: () => createCallbackStack,
|
|
31
34
|
destore: () => destore,
|
|
32
35
|
entries: () => entries,
|
|
33
36
|
forEach: () => forEach,
|
|
37
|
+
includes: () => includes,
|
|
38
|
+
isArray: () => isArray,
|
|
39
|
+
isBoolean: () => isBoolean,
|
|
34
40
|
isClient: () => isClient,
|
|
35
41
|
isDefined: () => isDefined,
|
|
42
|
+
isFunction: () => isFunction,
|
|
43
|
+
isNumber: () => isNumber,
|
|
44
|
+
isObject: () => isObject,
|
|
36
45
|
isServer: () => import_web.isServer,
|
|
46
|
+
isString: () => isString,
|
|
47
|
+
keys: () => keys,
|
|
37
48
|
noop: () => noop,
|
|
49
|
+
ofClass: () => ofClass,
|
|
50
|
+
onAccess: () => onAccess,
|
|
38
51
|
onRootCleanup: () => onRootCleanup,
|
|
39
52
|
promiseTimeout: () => promiseTimeout,
|
|
40
53
|
raceTimeout: () => raceTimeout,
|
|
41
|
-
|
|
42
|
-
toArray: () => toArray,
|
|
43
|
-
toFloat: () => toFloat,
|
|
44
|
-
toInt: () => toInt,
|
|
54
|
+
tuple: () => tuple,
|
|
45
55
|
withAccess: () => withAccess
|
|
46
56
|
});
|
|
47
57
|
var import_solid_js = require("solid-js");
|
|
48
58
|
var import_web = require("solid-js/web");
|
|
49
|
-
var noop = (
|
|
50
|
-
};
|
|
59
|
+
var noop = () => void 0;
|
|
51
60
|
var isClient = !import_web.isServer;
|
|
52
61
|
var isDefined = (value) => typeof value !== "undefined" && value !== null;
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
var isFunction = (value) => typeof value === "function";
|
|
63
|
+
var isBoolean = (val) => typeof val === "boolean";
|
|
64
|
+
var isNumber = (val) => typeof val === "number";
|
|
65
|
+
var isString = (val) => typeof val === "string";
|
|
66
|
+
var isObject = (val) => toString.call(val) === "[object Object]";
|
|
67
|
+
var isArray = (val) => Array.isArray(val);
|
|
68
|
+
var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
|
|
69
|
+
var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
70
|
+
var tuple = (input) => input;
|
|
71
|
+
var includes = (arr, ...items) => {
|
|
72
|
+
for (const item of arr) {
|
|
73
|
+
if (items.includes(item))
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
57
77
|
};
|
|
78
|
+
var access = (v) => isFunction(v) ? v() : v;
|
|
79
|
+
var accessAsArray = (value) => asArray(access(value));
|
|
80
|
+
var asArray = (value) => Array.isArray(value) ? value : [value];
|
|
81
|
+
var accessArray = (list) => list.map((v) => access(v));
|
|
58
82
|
var withAccess = (value, fn) => {
|
|
59
83
|
const _value = access(value);
|
|
60
84
|
isDefined(_value) && fn(_value);
|
|
61
85
|
};
|
|
86
|
+
var asAccessor = (v) => isFunction(v) ? v : () => v;
|
|
87
|
+
function onAccess(deps, fn, options) {
|
|
88
|
+
const source = deps.map(asAccessor);
|
|
89
|
+
return (0, import_solid_js.on)(source, fn, options);
|
|
90
|
+
}
|
|
62
91
|
var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
|
|
63
92
|
var entries = (object) => Object.entries(access(object));
|
|
93
|
+
var keys = (object) => Object.keys(access(object));
|
|
64
94
|
var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
|
|
65
|
-
function raceTimeout(
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
95
|
+
function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
|
|
96
|
+
const promises = asArray(input);
|
|
97
|
+
const race = Promise.race([...promises, promiseTimeout(ms, throwOnTimeout, reason)]);
|
|
98
|
+
race.finally(() => {
|
|
99
|
+
promises.forEach((p) => p && typeof p === "object" && typeof p.dispose === "function" && p.dispose());
|
|
100
|
+
});
|
|
101
|
+
return race;
|
|
69
102
|
}
|
|
103
|
+
var onRootCleanup = (fn) => (0, import_solid_js.getOwner)() ? (0, import_solid_js.onCleanup)(fn) : fn;
|
|
70
104
|
function destore(store) {
|
|
71
105
|
const _store = store;
|
|
72
106
|
const result = {};
|
|
73
107
|
Object.keys(_store).forEach((key) => {
|
|
74
|
-
result[key] =
|
|
108
|
+
result[key] = isFunction(_store[key]) ? _store[key].bind(_store) : () => _store[key];
|
|
75
109
|
});
|
|
76
110
|
return result;
|
|
77
111
|
}
|
|
78
|
-
var onRootCleanup = (fn) => (0, import_solid_js.getOwner)() ? (0, import_solid_js.onCleanup)(fn) : fn;
|
|
79
112
|
var createCallbackStack = () => {
|
|
80
113
|
let stack = [];
|
|
81
114
|
const clear = () => stack = [];
|
|
@@ -88,34 +121,36 @@ var createCallbackStack = () => {
|
|
|
88
121
|
clear
|
|
89
122
|
};
|
|
90
123
|
};
|
|
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
124
|
module.exports = __toCommonJS(src_exports);
|
|
100
125
|
// Annotate the CommonJS export names for ESM import in node:
|
|
101
126
|
0 && (module.exports = {
|
|
102
127
|
access,
|
|
128
|
+
accessArray,
|
|
103
129
|
accessAsArray,
|
|
104
|
-
|
|
130
|
+
asAccessor,
|
|
131
|
+
asArray,
|
|
132
|
+
compare,
|
|
105
133
|
createCallbackStack,
|
|
106
134
|
destore,
|
|
107
135
|
entries,
|
|
108
136
|
forEach,
|
|
137
|
+
includes,
|
|
138
|
+
isArray,
|
|
139
|
+
isBoolean,
|
|
109
140
|
isClient,
|
|
110
141
|
isDefined,
|
|
142
|
+
isFunction,
|
|
143
|
+
isNumber,
|
|
144
|
+
isObject,
|
|
111
145
|
isServer,
|
|
146
|
+
isString,
|
|
147
|
+
keys,
|
|
112
148
|
noop,
|
|
149
|
+
ofClass,
|
|
150
|
+
onAccess,
|
|
113
151
|
onRootCleanup,
|
|
114
152
|
promiseTimeout,
|
|
115
153
|
raceTimeout,
|
|
116
|
-
|
|
117
|
-
toArray,
|
|
118
|
-
toFloat,
|
|
119
|
-
toInt,
|
|
154
|
+
tuple,
|
|
120
155
|
withAccess
|
|
121
156
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,54 +1,157 @@
|
|
|
1
|
-
import { onCleanup } from 'solid-js';
|
|
1
|
+
import { Accessor, onCleanup } from 'solid-js';
|
|
2
|
+
import { OnOptions, EffectFunction, NoInfer } from 'solid-js/types/reactive/signal';
|
|
2
3
|
import { Store } from 'solid-js/store';
|
|
3
4
|
export { isServer } from 'solid-js/web';
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A function
|
|
8
|
+
*/
|
|
9
|
+
declare type Fn<R = void> = () => R;
|
|
10
|
+
declare type Get<T> = (v: T) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Can be single or in an array
|
|
13
|
+
*/
|
|
14
|
+
declare type Many<T> = T | T[];
|
|
15
|
+
declare type Keys<O extends Object> = keyof O;
|
|
16
|
+
declare type Values<O extends Object> = O[Keys<O>];
|
|
17
|
+
declare type Noop = (...a: any[]) => void;
|
|
18
|
+
declare type Directive<P = true> = (el: Element, props: Accessor<P>) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Infers the type of the array elements
|
|
21
|
+
*/
|
|
22
|
+
declare type ItemsOf<T> = T extends (infer E)[] ? E : never;
|
|
23
|
+
declare type ItemsOfMany<T> = T extends any[] ? ItemsOf<T> : T;
|
|
24
|
+
/**
|
|
25
|
+
* T or a reactive/non-reactive function returning T
|
|
26
|
+
*/
|
|
27
|
+
declare type MaybeAccessor<T> = T | Accessor<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Accessed value of a MaybeAccessor
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* MaybeAccessorValue<MaybeAccessor<string>>
|
|
33
|
+
* // => string
|
|
34
|
+
* MaybeAccessorValue<MaybeAccessor<() => string>>
|
|
35
|
+
* // => string | (() => string)
|
|
36
|
+
* MaybeAccessorValue<MaybeAccessor<string> | Function>
|
|
37
|
+
* // => string | void
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare type MaybeAccessorValue<T extends MaybeAccessor<any>> = T extends Fn ? ReturnType<T> : T;
|
|
41
|
+
declare type OnAccessEffectFunction<S, Prev, Next extends Prev = Prev> = (input: AccessReturnTypes<S>, prevInput: AccessReturnTypes<S>, v: Prev) => Next;
|
|
42
|
+
declare type AccessReturnTypes<S> = S extends MaybeAccessor<any>[] ? {
|
|
43
|
+
[I in keyof S]: AccessReturnTypes<S[I]>;
|
|
44
|
+
} : MaybeAccessorValue<S>;
|
|
45
|
+
/** Allows to make shallow overwrites to an interface */
|
|
46
|
+
declare type Modify<T, R> = Omit<T, keyof R> & R;
|
|
47
|
+
/** Allows to make nested overwrites to an interface */
|
|
48
|
+
declare type ModifyDeep<A extends AnyObject, B extends DeepPartialAny<A>> = {
|
|
49
|
+
[K in keyof A]: B[K] extends never ? A[K] : B[K] extends AnyObject ? ModifyDeep<A[K], B[K]> : B[K];
|
|
50
|
+
} & (A extends AnyObject ? Omit<B, keyof A> : A);
|
|
51
|
+
/** Makes each property optional and turns each leaf property into any, allowing for type overrides by narrowing any. */
|
|
52
|
+
declare type DeepPartialAny<T> = {
|
|
53
|
+
[P in keyof T]?: T[P] extends AnyObject ? DeepPartialAny<T[P]> : any;
|
|
54
|
+
};
|
|
55
|
+
/** `A | B => A & B` */
|
|
56
|
+
declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
57
|
+
declare type ExtractIfPossible<T, U> = Extract<T, U> extends never ? U : Extract<T, U>;
|
|
58
|
+
declare type AnyObject = Record<string, any>;
|
|
59
|
+
declare type AnyFunction = (...args: any[]) => any;
|
|
60
|
+
declare type AnyClass = abstract new (...args: any) => any;
|
|
61
|
+
declare type LiteralKey = string | number | symbol;
|
|
62
|
+
declare type PrimitiveValue = string | boolean | number | bigint | symbol | null | undefined;
|
|
63
|
+
declare type FalsyValue = false | 0 | "" | null | undefined;
|
|
64
|
+
declare type Truthy<T> = Exclude<T, FalsyValue>;
|
|
65
|
+
declare type Falsy<T> = Extract<T, FalsyValue>;
|
|
66
|
+
/**
|
|
67
|
+
* Destructible store object, with values changed to accessors
|
|
68
|
+
*/
|
|
69
|
+
declare type Destore<T extends Object> = {
|
|
70
|
+
[K in keyof T]: T[K] extends Function ? T[K] : Accessor<T[K]>;
|
|
71
|
+
};
|
|
6
72
|
|
|
7
73
|
/** no operation */
|
|
8
|
-
declare const noop:
|
|
74
|
+
declare const noop: Noop;
|
|
9
75
|
declare const isClient = true;
|
|
10
76
|
|
|
11
77
|
/**
|
|
12
78
|
* `if (typeof value !== "undefined" && value !== null)`
|
|
13
79
|
*/
|
|
14
80
|
declare const isDefined: <T>(value: T | null | undefined) => value is T;
|
|
81
|
+
declare const isFunction: <T>(value: Function | T) => value is Function;
|
|
82
|
+
declare const isBoolean: (val: any) => val is boolean;
|
|
83
|
+
declare const isNumber: (val: any) => val is number;
|
|
84
|
+
declare const isString: (val: unknown) => val is string;
|
|
85
|
+
declare const isObject: (val: any) => val is object;
|
|
86
|
+
declare const isArray: (val: any) => val is any[];
|
|
87
|
+
declare const ofClass: (v: any, c: AnyClass) => boolean;
|
|
88
|
+
declare const compare: (a: any, b: any) => number;
|
|
89
|
+
/**
|
|
90
|
+
* for creating tuples by inferring type
|
|
91
|
+
* @example
|
|
92
|
+
* const users = tuple(["John", "Jeff", "Joe"]);
|
|
93
|
+
* // users: [string, string, string]
|
|
94
|
+
*/
|
|
95
|
+
declare const tuple: <T extends any[] | []>(input: T) => T;
|
|
96
|
+
/** `Array.prototype.includes()` without so strict types. Also allows for checking for multiple items */
|
|
97
|
+
declare const includes: (arr: any[], ...items: any) => boolean;
|
|
15
98
|
/**
|
|
16
99
|
* Accesses the value of a MaybeAccessor
|
|
17
100
|
* @example
|
|
101
|
+
* ```ts
|
|
18
102
|
* access("foo") // => "foo"
|
|
19
103
|
* access(() => "foo") // => "foo"
|
|
104
|
+
* ```
|
|
20
105
|
*/
|
|
21
106
|
declare const access: <T extends unknown>(v: T) => MaybeAccessorValue<T>;
|
|
22
107
|
/**
|
|
23
108
|
* Accesses the value of a MaybeAccessor, but always returns an array
|
|
24
109
|
* @example
|
|
110
|
+
* ```ts
|
|
25
111
|
* accessAsArray('abc') // => ['abc']
|
|
26
112
|
* accessAsArray(() => 'abc') // => ['abc']
|
|
27
113
|
* accessAsArray([1,2,3]) // => [1,2,3]
|
|
28
114
|
* accessAsArray(() => [1,2,3]) // => [1,2,3]
|
|
115
|
+
* ```
|
|
29
116
|
*/
|
|
30
117
|
declare const accessAsArray: <T extends unknown, V = MaybeAccessorValue<T>>(value: T) => V extends any[] ? V : V[];
|
|
118
|
+
declare const asArray: <T>(value: T) => T extends any[] ? T : T[];
|
|
119
|
+
/**
|
|
120
|
+
* Access an array of MaybeAccessors
|
|
121
|
+
* @example
|
|
122
|
+
* const list = [1, 2, () => 3)] // T: MaybeAccessor<number>[]
|
|
123
|
+
* const newList = accessArray(list) // T: number[]
|
|
124
|
+
*/
|
|
125
|
+
declare const accessArray: <A extends unknown>(list: readonly A[]) => MaybeAccessorValue<A>[];
|
|
31
126
|
/**
|
|
32
127
|
* Run the function if the accessed value is not `undefined` nor `null`
|
|
33
128
|
* @param value
|
|
34
129
|
* @param fn
|
|
35
130
|
*/
|
|
36
131
|
declare const withAccess: <T, A extends MaybeAccessor<T>, V = MaybeAccessorValue<A>>(value: A, fn: (value: NonNullable<V>) => void) => void;
|
|
132
|
+
declare const asAccessor: <A extends unknown>(v: A) => Accessor<MaybeAccessorValue<A>>;
|
|
133
|
+
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>>;
|
|
37
134
|
/**
|
|
38
135
|
* Quickly iterate over an MaybeAccessor<any>
|
|
39
136
|
*
|
|
40
137
|
* @example
|
|
138
|
+
* ```ts
|
|
41
139
|
* const myFunc = (source: MaybeAccessor<string[]>) => {
|
|
42
140
|
* forEach(source, item => console.log(item))
|
|
43
141
|
* }
|
|
142
|
+
* ```
|
|
44
143
|
*/
|
|
45
144
|
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
145
|
/**
|
|
47
146
|
* Get `Object.entries()` of an MaybeAccessor<Object>
|
|
48
147
|
*/
|
|
49
|
-
declare const entries: <A extends MaybeAccessor<
|
|
148
|
+
declare const entries: <A extends MaybeAccessor<object>, V = MaybeAccessorValue<A>>(object: A) => [string, Values<V>][];
|
|
50
149
|
/**
|
|
51
|
-
*
|
|
150
|
+
* Get `Object.keys()` of an MaybeAccessor<Object>
|
|
151
|
+
*/
|
|
152
|
+
declare const keys: <A extends MaybeAccessor<object>>(object: A) => (keyof MaybeAccessorValue<A>)[];
|
|
153
|
+
/**
|
|
154
|
+
* Creates a promise that resolves *(or rejects)* after given time.
|
|
52
155
|
*
|
|
53
156
|
* @param ms timeout duration in ms
|
|
54
157
|
* @param throwOnTimeout promise will be rejected on timeout if set to `true`
|
|
@@ -56,8 +159,10 @@ declare const entries: <A extends MaybeAccessor<Object>, V = MaybeAccessorValue<
|
|
|
56
159
|
* @returns Promise<void>
|
|
57
160
|
*
|
|
58
161
|
* @example
|
|
162
|
+
* ```ts
|
|
59
163
|
* await promiseTimeout(1500) // will resolve void after timeout
|
|
60
164
|
* await promiseTimeout(1500, true, 'rejection reason') // will reject 'rejection reason' after timout
|
|
165
|
+
* ```
|
|
61
166
|
*/
|
|
62
167
|
declare const promiseTimeout: (ms: number, throwOnTimeout?: boolean, reason?: string) => Promise<void>;
|
|
63
168
|
/**
|
|
@@ -70,15 +175,21 @@ declare const promiseTimeout: (ms: number, throwOnTimeout?: boolean, reason?: st
|
|
|
70
175
|
* @returns a promise resulting in value of the first source promises to be resolved
|
|
71
176
|
*
|
|
72
177
|
* @example
|
|
178
|
+
* ```ts
|
|
73
179
|
* // single promise
|
|
74
180
|
* await raceTimeout(new Promise(() => {...}), 3000)
|
|
75
181
|
* // list of promises racing
|
|
76
182
|
* await raceTimeout([new Promise(),new Promise()...], 3000)
|
|
77
183
|
* // reject on timeout
|
|
78
184
|
* await raceTimeout(new Promise(), 3000, true, 'rejection reason')
|
|
185
|
+
* ```
|
|
79
186
|
*/
|
|
80
187
|
declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout: true, reason?: string): T extends any[] ? Promise<Awaited<T[number]>> : Promise<Awaited<T>>;
|
|
81
188
|
declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolean, reason?: string): T extends any[] ? Promise<Awaited<T[number]> | undefined> : Promise<Awaited<T> | undefined>;
|
|
189
|
+
/**
|
|
190
|
+
* Solid's `onCleanup` that is registered only if there is a root.
|
|
191
|
+
*/
|
|
192
|
+
declare const onRootCleanup: typeof onCleanup;
|
|
82
193
|
/**
|
|
83
194
|
* Allows the Solid's store to be destructured
|
|
84
195
|
*
|
|
@@ -86,6 +197,7 @@ declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolea
|
|
|
86
197
|
* @returns Destructible object, with values changed to accessors
|
|
87
198
|
*
|
|
88
199
|
* @example
|
|
200
|
+
* ```ts
|
|
89
201
|
* const [state, setState] = createStore({
|
|
90
202
|
* count: 0,
|
|
91
203
|
* get double() { return this.count * 2 },
|
|
@@ -93,21 +205,13 @@ declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolea
|
|
|
93
205
|
* const { count, double } = destore(state)
|
|
94
206
|
* // use it like a signal:
|
|
95
207
|
* count()
|
|
208
|
+
* ```
|
|
96
209
|
*/
|
|
97
210
|
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
211
|
declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {
|
|
103
212
|
push: (...callbacks: Fn[]) => void;
|
|
104
213
|
execute: (arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void;
|
|
105
214
|
clear: Fn;
|
|
106
215
|
};
|
|
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
216
|
|
|
113
|
-
export { access, accessAsArray,
|
|
217
|
+
export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, DeepPartialAny, Destore, Directive, ExtractIfPossible, Falsy, FalsyValue, Fn, Get, ItemsOf, ItemsOfMany, Keys, LiteralKey, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Noop, OnAccessEffectFunction, PrimitiveValue, Truthy, UnionToIntersection, Values, access, accessArray, accessAsArray, asAccessor, asArray, compare, createCallbackStack, destore, entries, forEach, includes, isArray, isBoolean, isClient, isDefined, isFunction, isNumber, isObject, isString, keys, noop, ofClass, onAccess, onRootCleanup, promiseTimeout, raceTimeout, tuple, withAccess };
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,59 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { getOwner, onCleanup } from "solid-js";
|
|
2
|
+
import { getOwner, onCleanup, on } from "solid-js";
|
|
3
3
|
import { isServer } from "solid-js/web";
|
|
4
|
-
var noop = (
|
|
5
|
-
};
|
|
4
|
+
var noop = () => void 0;
|
|
6
5
|
var isClient = !isServer;
|
|
7
6
|
var isDefined = (value) => typeof value !== "undefined" && value !== null;
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
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 ofClass = (v, c) => v instanceof c || v && v.constructor === c;
|
|
14
|
+
var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
15
|
+
var tuple = (input) => input;
|
|
16
|
+
var includes = (arr, ...items) => {
|
|
17
|
+
for (const item of arr) {
|
|
18
|
+
if (items.includes(item))
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
12
22
|
};
|
|
23
|
+
var access = (v) => isFunction(v) ? v() : v;
|
|
24
|
+
var accessAsArray = (value) => asArray(access(value));
|
|
25
|
+
var asArray = (value) => Array.isArray(value) ? value : [value];
|
|
26
|
+
var accessArray = (list) => list.map((v) => access(v));
|
|
13
27
|
var withAccess = (value, fn) => {
|
|
14
28
|
const _value = access(value);
|
|
15
29
|
isDefined(_value) && fn(_value);
|
|
16
30
|
};
|
|
31
|
+
var asAccessor = (v) => isFunction(v) ? v : () => v;
|
|
32
|
+
function onAccess(deps, fn, options) {
|
|
33
|
+
const source = deps.map(asAccessor);
|
|
34
|
+
return on(source, fn, options);
|
|
35
|
+
}
|
|
17
36
|
var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
|
|
18
37
|
var entries = (object) => Object.entries(access(object));
|
|
38
|
+
var keys = (object) => Object.keys(access(object));
|
|
19
39
|
var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
|
|
20
|
-
function raceTimeout(
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
40
|
+
function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
|
|
41
|
+
const promises = asArray(input);
|
|
42
|
+
const race = Promise.race([...promises, promiseTimeout(ms, throwOnTimeout, reason)]);
|
|
43
|
+
race.finally(() => {
|
|
44
|
+
promises.forEach((p) => p && typeof p === "object" && typeof p.dispose === "function" && p.dispose());
|
|
45
|
+
});
|
|
46
|
+
return race;
|
|
24
47
|
}
|
|
48
|
+
var onRootCleanup = (fn) => getOwner() ? onCleanup(fn) : fn;
|
|
25
49
|
function destore(store) {
|
|
26
50
|
const _store = store;
|
|
27
51
|
const result = {};
|
|
28
52
|
Object.keys(_store).forEach((key) => {
|
|
29
|
-
result[key] =
|
|
53
|
+
result[key] = isFunction(_store[key]) ? _store[key].bind(_store) : () => _store[key];
|
|
30
54
|
});
|
|
31
55
|
return result;
|
|
32
56
|
}
|
|
33
|
-
var onRootCleanup = (fn) => getOwner() ? onCleanup(fn) : fn;
|
|
34
57
|
var createCallbackStack = () => {
|
|
35
58
|
let stack = [];
|
|
36
59
|
const clear = () => stack = [];
|
|
@@ -43,32 +66,34 @@ var createCallbackStack = () => {
|
|
|
43
66
|
clear
|
|
44
67
|
};
|
|
45
68
|
};
|
|
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
69
|
export {
|
|
55
70
|
access,
|
|
71
|
+
accessArray,
|
|
56
72
|
accessAsArray,
|
|
57
|
-
|
|
73
|
+
asAccessor,
|
|
74
|
+
asArray,
|
|
75
|
+
compare,
|
|
58
76
|
createCallbackStack,
|
|
59
77
|
destore,
|
|
60
78
|
entries,
|
|
61
79
|
forEach,
|
|
80
|
+
includes,
|
|
81
|
+
isArray,
|
|
82
|
+
isBoolean,
|
|
62
83
|
isClient,
|
|
63
84
|
isDefined,
|
|
85
|
+
isFunction,
|
|
86
|
+
isNumber,
|
|
87
|
+
isObject,
|
|
64
88
|
isServer,
|
|
89
|
+
isString,
|
|
90
|
+
keys,
|
|
65
91
|
noop,
|
|
92
|
+
ofClass,
|
|
93
|
+
onAccess,
|
|
66
94
|
onRootCleanup,
|
|
67
95
|
promiseTimeout,
|
|
68
96
|
raceTimeout,
|
|
69
|
-
|
|
70
|
-
toArray,
|
|
71
|
-
toFloat,
|
|
72
|
-
toInt,
|
|
97
|
+
tuple,
|
|
73
98
|
withAccess
|
|
74
99
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solid-primitives/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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",
|
|
@@ -18,37 +18,11 @@
|
|
|
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",
|
|
51
|
-
"watch-test": "watchlist src test -- npm test"
|
|
24
|
+
"watch-test": "watchlist src test -- npm test",
|
|
25
|
+
"docs": "typedoc"
|
|
52
26
|
},
|
|
53
27
|
"keywords": [
|
|
54
28
|
"utilities",
|
|
@@ -57,15 +31,17 @@
|
|
|
57
31
|
"primitives"
|
|
58
32
|
],
|
|
59
33
|
"devDependencies": {
|
|
60
|
-
"jsdom": "
|
|
34
|
+
"jsdom": "18.1.1",
|
|
61
35
|
"prettier": "^2.5.1",
|
|
62
|
-
"solid-register": "^0.
|
|
36
|
+
"solid-register": "^0.1.1",
|
|
63
37
|
"tslib": "^2.3.1",
|
|
64
38
|
"tsup": "^5.11.0",
|
|
39
|
+
"typedoc": "^0.22.10",
|
|
40
|
+
"typedoc-plugin-markdown": "^3.11.8",
|
|
65
41
|
"uvu": "^0.5.2",
|
|
66
42
|
"watchlist": "^0.3.1"
|
|
67
43
|
},
|
|
68
44
|
"peerDependencies": {
|
|
69
|
-
"solid-js": "^1.
|
|
45
|
+
"solid-js": "^1.3.1"
|
|
70
46
|
}
|
|
71
|
-
}
|
|
47
|
+
}
|
package/dist/chunk-UFTWPD62.js
DELETED
|
@@ -1,44 +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 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
DELETED
|
@@ -1,83 +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
|
-
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
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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/setter.cjs
DELETED
|
@@ -1,72 +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
|
-
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
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/types-1e8c1610.d.ts
DELETED
|
@@ -1,54 +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
|
-
/**
|
|
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 };
|