@solid-primitives/utils 0.0.150 → 0.0.260
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 +21 -0
- package/dist/index.cjs +96 -0
- package/dist/index.d.ts +95 -18
- package/dist/index.js +66 -19
- package/package.json +14 -19
- package/dist/cjs/index.js +0 -34
package/README.md
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
1
|
# @solid-primitives/utils
|
|
2
|
+
|
|
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
|
+
## Changelog
|
|
6
|
+
|
|
7
|
+
<details>
|
|
8
|
+
<summary><b>Expand Changelog</b></summary>
|
|
9
|
+
|
|
10
|
+
0.0.100
|
|
11
|
+
|
|
12
|
+
First commit of the timer primitive.
|
|
13
|
+
|
|
14
|
+
0.0.250
|
|
15
|
+
|
|
16
|
+
Republished version with better ESM support and build tooling.
|
|
17
|
+
|
|
18
|
+
0.0.260
|
|
19
|
+
|
|
20
|
+
Added comments for util methods.
|
|
21
|
+
|
|
22
|
+
</details>
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
__markAsModule(target);
|
|
5
|
+
for (var name in all)
|
|
6
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/index.ts
|
|
10
|
+
__export(exports, {
|
|
11
|
+
access: () => access,
|
|
12
|
+
accessAsArray: () => accessAsArray,
|
|
13
|
+
concat: () => concat,
|
|
14
|
+
createCallbackStack: () => createCallbackStack,
|
|
15
|
+
destore: () => destore,
|
|
16
|
+
entries: () => entries,
|
|
17
|
+
forEach: () => forEach,
|
|
18
|
+
isClient: () => isClient,
|
|
19
|
+
isServer: () => isServer,
|
|
20
|
+
objectOmit: () => objectOmit,
|
|
21
|
+
promiseTimeout: () => promiseTimeout,
|
|
22
|
+
stringConcat: () => stringConcat,
|
|
23
|
+
toArray: () => toArray,
|
|
24
|
+
toFloat: () => toFloat,
|
|
25
|
+
toInt: () => toInt,
|
|
26
|
+
withAccess: () => withAccess
|
|
27
|
+
});
|
|
28
|
+
var isClient = typeof window !== "undefined";
|
|
29
|
+
var isServer = !isClient;
|
|
30
|
+
var access = (v) => typeof v === "function" ? v() : v;
|
|
31
|
+
var accessAsArray = (value) => {
|
|
32
|
+
const _value = access(value);
|
|
33
|
+
return Array.isArray(_value) ? _value : [_value];
|
|
34
|
+
};
|
|
35
|
+
var withAccess = (value, fn) => {
|
|
36
|
+
const _value = access(value);
|
|
37
|
+
if (typeof _value !== "undefined" && _value !== null)
|
|
38
|
+
fn(_value);
|
|
39
|
+
};
|
|
40
|
+
var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
|
|
41
|
+
var entries = (object) => Object.entries(access(object));
|
|
42
|
+
var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
|
|
43
|
+
var objectOmit = (object, ...keys) => {
|
|
44
|
+
const copy = Object.assign({}, object);
|
|
45
|
+
for (const key of keys) {
|
|
46
|
+
delete copy[key];
|
|
47
|
+
}
|
|
48
|
+
return copy;
|
|
49
|
+
};
|
|
50
|
+
function destore(store) {
|
|
51
|
+
const _store = store;
|
|
52
|
+
const result = {};
|
|
53
|
+
Object.keys(_store).forEach((key) => {
|
|
54
|
+
result[key] = typeof _store[key] === "function" ? _store[key].bind(_store) : () => _store[key];
|
|
55
|
+
});
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
var createCallbackStack = () => {
|
|
59
|
+
let stack = [];
|
|
60
|
+
const clear = () => stack = [];
|
|
61
|
+
return {
|
|
62
|
+
push: (...callbacks) => stack.push(...callbacks),
|
|
63
|
+
execute: (arg0, arg1, arg2, arg3) => {
|
|
64
|
+
stack.forEach((cb) => cb(arg0, arg1, arg2, arg3));
|
|
65
|
+
clear();
|
|
66
|
+
},
|
|
67
|
+
clear
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
var stringConcat = (...a) => a.reduce((t, c) => t + access(c), "");
|
|
71
|
+
var concat = (...a) => a.reduce((t, c) => {
|
|
72
|
+
const v = access(c);
|
|
73
|
+
return Array.isArray(v) ? [...t, ...v] : [...t, v];
|
|
74
|
+
}, []);
|
|
75
|
+
var toFloat = (string) => Number.parseFloat(access(string));
|
|
76
|
+
var toInt = (string, radix) => Number.parseInt(access(string), radix);
|
|
77
|
+
var toArray = (...a) => a.map((v) => access(v));
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
access,
|
|
81
|
+
accessAsArray,
|
|
82
|
+
concat,
|
|
83
|
+
createCallbackStack,
|
|
84
|
+
destore,
|
|
85
|
+
entries,
|
|
86
|
+
forEach,
|
|
87
|
+
isClient,
|
|
88
|
+
isServer,
|
|
89
|
+
objectOmit,
|
|
90
|
+
promiseTimeout,
|
|
91
|
+
stringConcat,
|
|
92
|
+
toArray,
|
|
93
|
+
toFloat,
|
|
94
|
+
toInt,
|
|
95
|
+
withAccess
|
|
96
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,95 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { Accessor } from 'solid-js';
|
|
2
|
+
import { Store } from 'solid-js/store';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A function
|
|
6
|
+
*/
|
|
7
|
+
declare type Fn<R = void> = () => R;
|
|
8
|
+
/**
|
|
9
|
+
* Can be single or in an array
|
|
10
|
+
*/
|
|
11
|
+
declare type Many<T> = T | T[];
|
|
12
|
+
declare type Keys<O extends Object> = keyof O;
|
|
13
|
+
declare type Values<O extends Object> = O[Keys<O>];
|
|
14
|
+
/**
|
|
15
|
+
* Infers the type of the array elements
|
|
16
|
+
*/
|
|
17
|
+
declare type ItemsOf<T> = T extends (infer E)[] ? E : never;
|
|
18
|
+
/**
|
|
19
|
+
* T or a reactive/non-reactive function returning T
|
|
20
|
+
*/
|
|
21
|
+
declare type MaybeAccessor<T> = T | Accessor<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Accessed value of a MaybeAccessor
|
|
24
|
+
* @example
|
|
25
|
+
* MaybeAccessorValue<MaybeAccessor<string>>
|
|
26
|
+
* // => string
|
|
27
|
+
* MaybeAccessorValue<MaybeAccessor<() => string>>
|
|
28
|
+
* // => string | (() => string)
|
|
29
|
+
* MaybeAccessorValue<MaybeAccessor<string> | Function>
|
|
30
|
+
* // => string | void
|
|
31
|
+
*/
|
|
32
|
+
declare type MaybeAccessorValue<T extends MaybeAccessor<any>> = T extends Fn ? ReturnType<T> : T;
|
|
33
|
+
declare const isClient: boolean;
|
|
34
|
+
declare const isServer: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Accesses the value of a MaybeAccessor
|
|
37
|
+
* @example
|
|
38
|
+
* access(x as MaybeAccessor<string>)
|
|
39
|
+
* // => string
|
|
40
|
+
* access(x as MaybeAccessor<() => string>)
|
|
41
|
+
* // => string | (() => string)
|
|
42
|
+
* access(x as MaybeAccessor<string> | Function)
|
|
43
|
+
* // => string | void
|
|
44
|
+
*/
|
|
45
|
+
declare const access: <T extends unknown>(v: T) => MaybeAccessorValue<T>;
|
|
46
|
+
/**
|
|
47
|
+
* Accesses the value of a MaybeAccessor, but always returns an array
|
|
48
|
+
* @example
|
|
49
|
+
* accessAsArray('abc') // => ['abc']
|
|
50
|
+
* accessAsArray(() => 'abc') // => ['abc']
|
|
51
|
+
* accessAsArray([1,2,3]) // => [1,2,3]
|
|
52
|
+
* accessAsArray(() => [1,2,3]) // => [1,2,3]
|
|
53
|
+
*/
|
|
54
|
+
declare const accessAsArray: <T extends unknown, V = MaybeAccessorValue<T>>(value: T) => V extends any[] ? V : V[];
|
|
55
|
+
/**
|
|
56
|
+
* Run the function if the accessed value is not `undefined` nor `null`
|
|
57
|
+
* @param value
|
|
58
|
+
* @param fn
|
|
59
|
+
*/
|
|
60
|
+
declare const withAccess: <T, A extends MaybeAccessor<T>, V = MaybeAccessorValue<A>>(value: A, fn: (value: NonNullable<V>) => void) => void;
|
|
61
|
+
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;
|
|
62
|
+
declare const entries: <A extends MaybeAccessor<Object>, V = MaybeAccessorValue<A>>(object: A) => [string, Values<V>][];
|
|
63
|
+
declare const promiseTimeout: (ms: number, throwOnTimeout?: boolean, reason?: string) => Promise<void>;
|
|
64
|
+
declare const objectOmit: <T extends Object, K extends (keyof T)[]>(object: T, ...keys: K) => Omit<T, ItemsOf<K>>;
|
|
65
|
+
declare type Destore<T extends Object> = {
|
|
66
|
+
[K in keyof T]: T[K] extends Function ? T[K] : Accessor<T[K]>;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Allows the Solid's store to be destructured
|
|
70
|
+
*
|
|
71
|
+
* @param store
|
|
72
|
+
* @returns Destructible object, with values changed to accessors
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* const [state, setState] = createStore({
|
|
76
|
+
* count: 0,
|
|
77
|
+
* get double() { return this.count * 2 },
|
|
78
|
+
* })
|
|
79
|
+
* const { count, double } = destore(state)
|
|
80
|
+
* // use it like a signal:
|
|
81
|
+
* count()
|
|
82
|
+
*/
|
|
83
|
+
declare function destore<T extends Object>(store: Store<T>): Destore<T>;
|
|
84
|
+
declare const createCallbackStack: <Arg0 = void, Arg1 = void, Arg2 = void, Arg3 = void>() => {
|
|
85
|
+
push: (...callbacks: Fn[]) => void;
|
|
86
|
+
execute: (arg0: Arg0, arg1: Arg1, arg2: Arg2, arg3: Arg3) => void;
|
|
87
|
+
clear: Fn;
|
|
88
|
+
};
|
|
89
|
+
declare const stringConcat: (...a: MaybeAccessor<any>[]) => string;
|
|
90
|
+
declare const concat: <A extends any[], V = MaybeAccessorValue<ItemsOf<A>>>(...a: A) => (V extends any[] ? ItemsOf<V> : V)[];
|
|
91
|
+
declare const toFloat: (string: MaybeAccessor<string>) => number;
|
|
92
|
+
declare const toInt: (string: MaybeAccessor<string>, radix?: number | undefined) => number;
|
|
93
|
+
declare const toArray: <A extends any[]>(...a: A) => MaybeAccessorValue<ItemsOf<A>>[];
|
|
94
|
+
|
|
95
|
+
export { Destore, Fn, ItemsOf, Keys, Many, MaybeAccessor, MaybeAccessorValue, Values, access, accessAsArray, concat, createCallbackStack, destore, entries, forEach, isClient, isServer, objectOmit, promiseTimeout, stringConcat, toArray, toFloat, toInt, withAccess };
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var isClient = typeof window !== "undefined";
|
|
3
|
+
var isServer = !isClient;
|
|
4
|
+
var access = (v) => typeof v === "function" ? v() : v;
|
|
5
|
+
var accessAsArray = (value) => {
|
|
6
|
+
const _value = access(value);
|
|
7
|
+
return Array.isArray(_value) ? _value : [_value];
|
|
5
8
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
var withAccess = (value, fn) => {
|
|
10
|
+
const _value = access(value);
|
|
11
|
+
if (typeof _value !== "undefined" && _value !== null)
|
|
12
|
+
fn(_value);
|
|
10
13
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
var forEach = (array, iterator) => accessAsArray(array).forEach(iterator);
|
|
15
|
+
var entries = (object) => Object.entries(access(object));
|
|
16
|
+
var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
|
|
17
|
+
var objectOmit = (object, ...keys) => {
|
|
18
|
+
const copy = Object.assign({}, object);
|
|
19
|
+
for (const key of keys) {
|
|
20
|
+
delete copy[key];
|
|
21
|
+
}
|
|
22
|
+
return copy;
|
|
23
|
+
};
|
|
24
|
+
function destore(store) {
|
|
25
|
+
const _store = store;
|
|
26
|
+
const result = {};
|
|
27
|
+
Object.keys(_store).forEach((key) => {
|
|
28
|
+
result[key] = typeof _store[key] === "function" ? _store[key].bind(_store) : () => _store[key];
|
|
29
|
+
});
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
var createCallbackStack = () => {
|
|
33
|
+
let stack = [];
|
|
34
|
+
const clear = () => stack = [];
|
|
35
|
+
return {
|
|
36
|
+
push: (...callbacks) => stack.push(...callbacks),
|
|
37
|
+
execute: (arg0, arg1, arg2, arg3) => {
|
|
38
|
+
stack.forEach((cb) => cb(arg0, arg1, arg2, arg3));
|
|
39
|
+
clear();
|
|
40
|
+
},
|
|
41
|
+
clear
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
var stringConcat = (...a) => a.reduce((t, c) => t + access(c), "");
|
|
45
|
+
var concat = (...a) => a.reduce((t, c) => {
|
|
46
|
+
const v = access(c);
|
|
47
|
+
return Array.isArray(v) ? [...t, ...v] : [...t, v];
|
|
19
48
|
}, []);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
49
|
+
var toFloat = (string) => Number.parseFloat(access(string));
|
|
50
|
+
var toInt = (string, radix) => Number.parseInt(access(string), radix);
|
|
51
|
+
var toArray = (...a) => a.map((v) => access(v));
|
|
52
|
+
export {
|
|
53
|
+
access,
|
|
54
|
+
accessAsArray,
|
|
55
|
+
concat,
|
|
56
|
+
createCallbackStack,
|
|
57
|
+
destore,
|
|
58
|
+
entries,
|
|
59
|
+
forEach,
|
|
60
|
+
isClient,
|
|
61
|
+
isServer,
|
|
62
|
+
objectOmit,
|
|
63
|
+
promiseTimeout,
|
|
64
|
+
stringConcat,
|
|
65
|
+
toArray,
|
|
66
|
+
toFloat,
|
|
67
|
+
toInt,
|
|
68
|
+
withAccess
|
|
69
|
+
};
|
package/package.json
CHANGED
|
@@ -1,32 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solid-primitives/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.260",
|
|
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",
|
|
7
|
-
"homepage": "https://github.com/davedbase/solid-primitives/utils#readme",
|
|
7
|
+
"homepage": "https://github.com/davedbase/solid-primitives/tree/main/packages/utils#readme",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/davedbase/solid-primitives.git"
|
|
11
11
|
},
|
|
12
12
|
"private": false,
|
|
13
|
-
"
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "dist/index.cjs",
|
|
14
16
|
"module": "dist/index.js",
|
|
15
17
|
"types": "dist/index.d.ts",
|
|
16
18
|
"files": [
|
|
17
19
|
"dist"
|
|
18
20
|
],
|
|
19
|
-
"exports": {
|
|
20
|
-
"require": "./dist/cjs/index.js",
|
|
21
|
-
"import": "./dist/index.js",
|
|
22
|
-
"default": "./dist/index.js"
|
|
23
|
-
},
|
|
24
|
-
"sideEffects": false,
|
|
25
21
|
"scripts": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"test": "uvu -r solid-register"
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"test": "uvu -r solid-register",
|
|
24
|
+
"watch-test": "watchlist src test -- npm test"
|
|
30
25
|
},
|
|
31
26
|
"keywords": [
|
|
32
27
|
"utilities",
|
|
@@ -35,15 +30,15 @@
|
|
|
35
30
|
"primitives"
|
|
36
31
|
],
|
|
37
32
|
"devDependencies": {
|
|
38
|
-
"jsdom": "^
|
|
39
|
-
"prettier": "^2.
|
|
40
|
-
"rimraf": "^3.0.2",
|
|
33
|
+
"jsdom": "^19.0.0",
|
|
34
|
+
"prettier": "^2.5.1",
|
|
41
35
|
"solid-register": "^0.0.18",
|
|
42
36
|
"tslib": "^2.3.1",
|
|
43
|
-
"
|
|
44
|
-
"uvu": "^0.5.2"
|
|
37
|
+
"tsup": "^5.11.0",
|
|
38
|
+
"uvu": "^0.5.2",
|
|
39
|
+
"watchlist": "^0.3.1"
|
|
45
40
|
},
|
|
46
41
|
"peerDependencies": {
|
|
47
|
-
"solid-js": "^1.2.
|
|
42
|
+
"solid-js": "^1.2.6"
|
|
48
43
|
}
|
|
49
44
|
}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toArray = exports.toInt = exports.toFloat = exports.concat = exports.stringConcat = exports.promiseTimeout = exports.withAccess = exports.accessAsArray = exports.access = void 0;
|
|
4
|
-
const access = (v) => typeof v === 'function' ? v() : v;
|
|
5
|
-
exports.access = access;
|
|
6
|
-
const accessAsArray = (value) => {
|
|
7
|
-
const _value = (0, exports.access)(value);
|
|
8
|
-
return Array.isArray(_value) ? _value : [_value];
|
|
9
|
-
};
|
|
10
|
-
exports.accessAsArray = accessAsArray;
|
|
11
|
-
const withAccess = (value, fn) => {
|
|
12
|
-
const _value = (0, exports.access)(value);
|
|
13
|
-
if (typeof _value !== 'undefined' && _value !== null)
|
|
14
|
-
fn(_value);
|
|
15
|
-
};
|
|
16
|
-
exports.withAccess = withAccess;
|
|
17
|
-
const promiseTimeout = (ms, throwOnTimeout = false, reason = 'Timeout') => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
|
|
18
|
-
exports.promiseTimeout = promiseTimeout;
|
|
19
|
-
//
|
|
20
|
-
// SIGNAL BUILDERS:
|
|
21
|
-
//
|
|
22
|
-
const stringConcat = (...a) => a.reduce((t, c) => t + (0, exports.access)(c), '');
|
|
23
|
-
exports.stringConcat = stringConcat;
|
|
24
|
-
const concat = (...a) => a.reduce((t, c) => {
|
|
25
|
-
const v = (0, exports.access)(c);
|
|
26
|
-
return Array.isArray(v) ? [...t, ...v] : [...t, v];
|
|
27
|
-
}, []);
|
|
28
|
-
exports.concat = concat;
|
|
29
|
-
const toFloat = (string) => Number.parseFloat((0, exports.access)(string));
|
|
30
|
-
exports.toFloat = toFloat;
|
|
31
|
-
const toInt = (string, radix) => Number.parseInt((0, exports.access)(string), radix);
|
|
32
|
-
exports.toInt = toInt;
|
|
33
|
-
const toArray = (...a) => a.map(v => (0, exports.access)(v));
|
|
34
|
-
exports.toArray = toArray;
|