@solid-primitives/utils 0.2.0 → 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/dist/index.cjs +12 -0
- package/dist/index.d.ts +14 -3
- package/dist/index.js +10 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
destore: () => destore,
|
|
35
35
|
entries: () => entries,
|
|
36
36
|
forEach: () => forEach,
|
|
37
|
+
includes: () => includes,
|
|
37
38
|
isArray: () => isArray,
|
|
38
39
|
isBoolean: () => isBoolean,
|
|
39
40
|
isClient: () => isClient,
|
|
@@ -45,6 +46,7 @@ __export(src_exports, {
|
|
|
45
46
|
isString: () => isString,
|
|
46
47
|
keys: () => keys,
|
|
47
48
|
noop: () => noop,
|
|
49
|
+
ofClass: () => ofClass,
|
|
48
50
|
onAccess: () => onAccess,
|
|
49
51
|
onRootCleanup: () => onRootCleanup,
|
|
50
52
|
promiseTimeout: () => promiseTimeout,
|
|
@@ -63,8 +65,16 @@ var isNumber = (val) => typeof val === "number";
|
|
|
63
65
|
var isString = (val) => typeof val === "string";
|
|
64
66
|
var isObject = (val) => toString.call(val) === "[object Object]";
|
|
65
67
|
var isArray = (val) => Array.isArray(val);
|
|
68
|
+
var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
|
|
66
69
|
var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
67
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;
|
|
77
|
+
};
|
|
68
78
|
var access = (v) => isFunction(v) ? v() : v;
|
|
69
79
|
var accessAsArray = (value) => asArray(access(value));
|
|
70
80
|
var asArray = (value) => Array.isArray(value) ? value : [value];
|
|
@@ -124,6 +134,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
124
134
|
destore,
|
|
125
135
|
entries,
|
|
126
136
|
forEach,
|
|
137
|
+
includes,
|
|
127
138
|
isArray,
|
|
128
139
|
isBoolean,
|
|
129
140
|
isClient,
|
|
@@ -135,6 +146,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
135
146
|
isString,
|
|
136
147
|
keys,
|
|
137
148
|
noop,
|
|
149
|
+
ofClass,
|
|
138
150
|
onAccess,
|
|
139
151
|
onRootCleanup,
|
|
140
152
|
promiseTimeout,
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { isServer } from 'solid-js/web';
|
|
|
7
7
|
* A function
|
|
8
8
|
*/
|
|
9
9
|
declare type Fn<R = void> = () => R;
|
|
10
|
+
declare type Get<T> = (v: T) => void;
|
|
10
11
|
/**
|
|
11
12
|
* Can be single or in an array
|
|
12
13
|
*/
|
|
@@ -14,10 +15,12 @@ declare type Many<T> = T | T[];
|
|
|
14
15
|
declare type Keys<O extends Object> = keyof O;
|
|
15
16
|
declare type Values<O extends Object> = O[Keys<O>];
|
|
16
17
|
declare type Noop = (...a: any[]) => void;
|
|
18
|
+
declare type Directive<P = true> = (el: Element, props: Accessor<P>) => void;
|
|
17
19
|
/**
|
|
18
20
|
* Infers the type of the array elements
|
|
19
21
|
*/
|
|
20
22
|
declare type ItemsOf<T> = T extends (infer E)[] ? E : never;
|
|
23
|
+
declare type ItemsOfMany<T> = T extends any[] ? ItemsOf<T> : T;
|
|
21
24
|
/**
|
|
22
25
|
* T or a reactive/non-reactive function returning T
|
|
23
26
|
*/
|
|
@@ -49,12 +52,17 @@ declare type ModifyDeep<A extends AnyObject, B extends DeepPartialAny<A>> = {
|
|
|
49
52
|
declare type DeepPartialAny<T> = {
|
|
50
53
|
[P in keyof T]?: T[P] extends AnyObject ? DeepPartialAny<T[P]> : any;
|
|
51
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>;
|
|
52
58
|
declare type AnyObject = Record<string, any>;
|
|
53
59
|
declare type AnyFunction = (...args: any[]) => any;
|
|
60
|
+
declare type AnyClass = abstract new (...args: any) => any;
|
|
61
|
+
declare type LiteralKey = string | number | symbol;
|
|
54
62
|
declare type PrimitiveValue = string | boolean | number | bigint | symbol | null | undefined;
|
|
55
63
|
declare type FalsyValue = false | 0 | "" | null | undefined;
|
|
56
|
-
declare type Truthy<T> = T
|
|
57
|
-
declare type Falsy<T> = T
|
|
64
|
+
declare type Truthy<T> = Exclude<T, FalsyValue>;
|
|
65
|
+
declare type Falsy<T> = Extract<T, FalsyValue>;
|
|
58
66
|
/**
|
|
59
67
|
* Destructible store object, with values changed to accessors
|
|
60
68
|
*/
|
|
@@ -76,6 +84,7 @@ declare const isNumber: (val: any) => val is number;
|
|
|
76
84
|
declare const isString: (val: unknown) => val is string;
|
|
77
85
|
declare const isObject: (val: any) => val is object;
|
|
78
86
|
declare const isArray: (val: any) => val is any[];
|
|
87
|
+
declare const ofClass: (v: any, c: AnyClass) => boolean;
|
|
79
88
|
declare const compare: (a: any, b: any) => number;
|
|
80
89
|
/**
|
|
81
90
|
* for creating tuples by inferring type
|
|
@@ -84,6 +93,8 @@ declare const compare: (a: any, b: any) => number;
|
|
|
84
93
|
* // users: [string, string, string]
|
|
85
94
|
*/
|
|
86
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;
|
|
87
98
|
/**
|
|
88
99
|
* Accesses the value of a MaybeAccessor
|
|
89
100
|
* @example
|
|
@@ -203,4 +214,4 @@ declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>(
|
|
|
203
214
|
clear: Fn;
|
|
204
215
|
};
|
|
205
216
|
|
|
206
|
-
export { AccessReturnTypes, AnyFunction, AnyObject, DeepPartialAny, Destore, Falsy, FalsyValue, Fn, ItemsOf, Keys, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Noop, OnAccessEffectFunction, PrimitiveValue, Truthy, Values, access, accessArray, accessAsArray, asAccessor, asArray, compare, createCallbackStack, destore, entries, forEach, isArray, isBoolean, isClient, isDefined, isFunction, isNumber, isObject, isString, keys, noop, onAccess, onRootCleanup, promiseTimeout, raceTimeout, tuple, withAccess };
|
|
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
|
@@ -10,8 +10,16 @@ var isNumber = (val) => typeof val === "number";
|
|
|
10
10
|
var isString = (val) => typeof val === "string";
|
|
11
11
|
var isObject = (val) => toString.call(val) === "[object Object]";
|
|
12
12
|
var isArray = (val) => Array.isArray(val);
|
|
13
|
+
var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
|
|
13
14
|
var compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
14
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;
|
|
22
|
+
};
|
|
15
23
|
var access = (v) => isFunction(v) ? v() : v;
|
|
16
24
|
var accessAsArray = (value) => asArray(access(value));
|
|
17
25
|
var asArray = (value) => Array.isArray(value) ? value : [value];
|
|
@@ -69,6 +77,7 @@ export {
|
|
|
69
77
|
destore,
|
|
70
78
|
entries,
|
|
71
79
|
forEach,
|
|
80
|
+
includes,
|
|
72
81
|
isArray,
|
|
73
82
|
isBoolean,
|
|
74
83
|
isClient,
|
|
@@ -80,6 +89,7 @@ export {
|
|
|
80
89
|
isString,
|
|
81
90
|
keys,
|
|
82
91
|
noop,
|
|
92
|
+
ofClass,
|
|
83
93
|
onAccess,
|
|
84
94
|
onRootCleanup,
|
|
85
95
|
promiseTimeout,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solid-primitives/utils",
|
|
3
|
-
"version": "0.2.
|
|
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",
|