@solid-primitives/utils 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -20
- package/dist/index.cjs +15 -2
- package/dist/index.d.ts +25 -2
- package/dist/index.js +11 -1
- package/package.json +2 -5
package/README.md
CHANGED
|
@@ -10,26 +10,6 @@ npm install @solid-primitives/utils
|
|
|
10
10
|
yarn add @solid-primitives/utils
|
|
11
11
|
```
|
|
12
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).
|
|
32
|
-
|
|
33
13
|
## Changelog
|
|
34
14
|
|
|
35
15
|
<details>
|
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ __export(src_exports, {
|
|
|
32
32
|
compare: () => compare,
|
|
33
33
|
createCallbackStack: () => createCallbackStack,
|
|
34
34
|
createProxy: () => createProxy,
|
|
35
|
+
definite: () => definite,
|
|
35
36
|
destore: () => destore,
|
|
36
37
|
entries: () => entries,
|
|
37
38
|
forEach: () => forEach,
|
|
@@ -57,7 +58,9 @@ __export(src_exports, {
|
|
|
57
58
|
raceTimeout: () => raceTimeout,
|
|
58
59
|
tuple: () => tuple,
|
|
59
60
|
warn: () => warn,
|
|
60
|
-
withAccess: () => withAccess
|
|
61
|
+
withAccess: () => withAccess,
|
|
62
|
+
withFallback: () => withFallback,
|
|
63
|
+
withFallbackFn: () => withFallbackFn
|
|
61
64
|
});
|
|
62
65
|
var import_solid_js = require("solid-js");
|
|
63
66
|
var import_web = require("solid-js/web");
|
|
@@ -76,6 +79,13 @@ var isArray = Array.isArray;
|
|
|
76
79
|
var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
|
|
77
80
|
var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
78
81
|
var tuple = (input) => input;
|
|
82
|
+
var definite = (v) => v;
|
|
83
|
+
function withFallback(v, fallback) {
|
|
84
|
+
return isDefined(v) ? v : fallback;
|
|
85
|
+
}
|
|
86
|
+
function withFallbackFn(v, fallback) {
|
|
87
|
+
return isDefined(v) ? v : fallback();
|
|
88
|
+
}
|
|
79
89
|
var includes = (arr, ...items) => {
|
|
80
90
|
for (const item of arr) {
|
|
81
91
|
if (items.includes(item))
|
|
@@ -154,6 +164,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
154
164
|
compare,
|
|
155
165
|
createCallbackStack,
|
|
156
166
|
createProxy,
|
|
167
|
+
definite,
|
|
157
168
|
destore,
|
|
158
169
|
entries,
|
|
159
170
|
forEach,
|
|
@@ -179,5 +190,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
179
190
|
raceTimeout,
|
|
180
191
|
tuple,
|
|
181
192
|
warn,
|
|
182
|
-
withAccess
|
|
193
|
+
withAccess,
|
|
194
|
+
withFallback,
|
|
195
|
+
withFallbackFn
|
|
183
196
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -64,6 +64,7 @@ declare type PrimitiveValue = string | boolean | number | bigint | symbol | null
|
|
|
64
64
|
declare type FalsyValue = false | 0 | "" | null | undefined;
|
|
65
65
|
declare type Truthy<T> = Exclude<T, FalsyValue>;
|
|
66
66
|
declare type Falsy<T> = Extract<T, FalsyValue>;
|
|
67
|
+
declare type Fallback<T, F = NonNullable<T>> = NonNullable<T> | F;
|
|
67
68
|
/**
|
|
68
69
|
* Destructible store object, with values changed to accessors
|
|
69
70
|
*/
|
|
@@ -95,15 +96,37 @@ declare const isNumber: (val: any) => val is number;
|
|
|
95
96
|
declare const isString: (val: unknown) => val is string;
|
|
96
97
|
declare const isObject: (val: any) => val is object;
|
|
97
98
|
declare const isArray: (val: any) => val is any[];
|
|
99
|
+
/**
|
|
100
|
+
* Check if the value is an instance of ___
|
|
101
|
+
*/
|
|
98
102
|
declare const ofClass: (v: any, c: AnyClass) => boolean;
|
|
99
103
|
declare const compare: (a: any, b: any) => number;
|
|
100
104
|
/**
|
|
101
105
|
* for creating tuples by inferring type
|
|
102
106
|
* @example
|
|
103
107
|
* const users = tuple(["John", "Jeff", "Joe"]);
|
|
104
|
-
* //
|
|
108
|
+
* users // T: [string, string, string]
|
|
105
109
|
*/
|
|
106
110
|
declare const tuple: <T extends any[] | []>(input: T) => T;
|
|
111
|
+
/**
|
|
112
|
+
* Removes the `null` and `undefined` from the type.
|
|
113
|
+
* @warning **Obviously use with caution**
|
|
114
|
+
*/
|
|
115
|
+
declare const definite: <T>(v: T) => NonNullable<T>;
|
|
116
|
+
/**
|
|
117
|
+
* Get the value if it is defined, or get the fallback otherwise
|
|
118
|
+
* @param v the value to check
|
|
119
|
+
* @param fallback the fallback value
|
|
120
|
+
*/
|
|
121
|
+
declare function withFallback<T>(v: T, fallback: NonNullable<T>): Fallback<T>;
|
|
122
|
+
declare function withFallback<T, F>(v: T, fallback: F): Fallback<T, F>;
|
|
123
|
+
/**
|
|
124
|
+
* Get the value if it is defined, or get the fallback otherwise
|
|
125
|
+
* @param v the value to check
|
|
126
|
+
* @param fallback function returning a fallback value
|
|
127
|
+
*/
|
|
128
|
+
declare function withFallbackFn<T>(v: T, fallback: () => NonNullable<T>): Fallback<T>;
|
|
129
|
+
declare function withFallbackFn<T, F>(v: T, fallback: () => F): Fallback<T, F>;
|
|
107
130
|
/** `Array.prototype.includes()` without so strict types. Also allows for checking for multiple items */
|
|
108
131
|
declare const includes: (arr: any[], ...items: any) => boolean;
|
|
109
132
|
/**
|
|
@@ -238,4 +261,4 @@ declare function createProxy<T extends Record<string | symbol, any>>(traps: {
|
|
|
238
261
|
set?: undefined;
|
|
239
262
|
}): Readonly<T>;
|
|
240
263
|
|
|
241
|
-
export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, Clear, DeepPartialAny, Destore, Directive, ExtractIfPossible, Falsy, FalsyValue, Fn, Get, ItemsOf, ItemsOfMany, Keys, LiteralKey, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Noop, OnAccessEffectFunction, Position, PrimitiveValue, Truthy, UnionToIntersection, Values, access, accessArray, accessAsArray, asAccessor, asArray, compare, createCallbackStack, createProxy, destore, entries, forEach, forEachEntry, includes, isArray, isBoolean, isClient, isDefined, isDev, isFunction, isNumber, isObject, isProd, isString, keys, noop, ofClass, onAccess, onRootCleanup, promiseTimeout, raceTimeout, tuple, warn, withAccess };
|
|
264
|
+
export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, Clear, DeepPartialAny, Destore, Directive, ExtractIfPossible, Fallback, Falsy, FalsyValue, Fn, Get, ItemsOf, ItemsOfMany, Keys, LiteralKey, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Noop, OnAccessEffectFunction, Position, PrimitiveValue, Truthy, UnionToIntersection, Values, access, accessArray, accessAsArray, asAccessor, asArray, compare, createCallbackStack, createProxy, definite, destore, entries, forEach, forEachEntry, includes, isArray, isBoolean, isClient, isDefined, isDev, isFunction, isNumber, isObject, isProd, isString, keys, noop, ofClass, onAccess, onRootCleanup, promiseTimeout, raceTimeout, tuple, warn, withAccess, withFallback, withFallbackFn };
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,13 @@ var isArray = Array.isArray;
|
|
|
16
16
|
var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
|
|
17
17
|
var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
18
18
|
var tuple = (input) => input;
|
|
19
|
+
var definite = (v) => v;
|
|
20
|
+
function withFallback(v, fallback) {
|
|
21
|
+
return isDefined(v) ? v : fallback;
|
|
22
|
+
}
|
|
23
|
+
function withFallbackFn(v, fallback) {
|
|
24
|
+
return isDefined(v) ? v : fallback();
|
|
25
|
+
}
|
|
19
26
|
var includes = (arr, ...items) => {
|
|
20
27
|
for (const item of arr) {
|
|
21
28
|
if (items.includes(item))
|
|
@@ -92,6 +99,7 @@ export {
|
|
|
92
99
|
compare,
|
|
93
100
|
createCallbackStack,
|
|
94
101
|
createProxy,
|
|
102
|
+
definite,
|
|
95
103
|
destore,
|
|
96
104
|
entries,
|
|
97
105
|
forEach,
|
|
@@ -117,5 +125,7 @@ export {
|
|
|
117
125
|
raceTimeout,
|
|
118
126
|
tuple,
|
|
119
127
|
warn,
|
|
120
|
-
withAccess
|
|
128
|
+
withAccess,
|
|
129
|
+
withFallback,
|
|
130
|
+
withFallbackFn
|
|
121
131
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solid-primitives/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A bunch of reactive utility types and functions, for building primitives with Solid.js",
|
|
5
5
|
"author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,8 +24,7 @@
|
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsup",
|
|
26
26
|
"test": "uvu -r solid-register",
|
|
27
|
-
"watch-test": "watchlist src test -- npm test"
|
|
28
|
-
"docs": "typedoc"
|
|
27
|
+
"watch-test": "watchlist src test -- npm test"
|
|
29
28
|
},
|
|
30
29
|
"keywords": [
|
|
31
30
|
"utilities",
|
|
@@ -39,8 +38,6 @@
|
|
|
39
38
|
"solid-register": "^0.1.1",
|
|
40
39
|
"tslib": "^2.3.1",
|
|
41
40
|
"tsup": "^5.11.0",
|
|
42
|
-
"typedoc": "^0.22.10",
|
|
43
|
-
"typedoc-plugin-markdown": "^3.11.8",
|
|
44
41
|
"uvu": "^0.5.2",
|
|
45
42
|
"watchlist": "^0.3.1"
|
|
46
43
|
},
|