@rimbu/base 0.9.5 → 0.10.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plain-object.js","sourceRoot":"","sources":["../../src/plain-object.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"plain-object.js","sourceRoot":"","sources":["../../src/plain-object.ts"],"names":[],"mappings":";;;AAuEA;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,GAAQ;IACjC,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,IAAI,KAAK,GAAG;QACZ,CAAC,GAAG,CAAC,WAAW,KAAK,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,WAAW,YAAY,QAAQ,CAAC,CAAC;QACtE,CAAC,CAAC,MAAM,CAAC,QAAQ,IAAI,GAAG,CAAC;QACzB,CAAC,CAAC,MAAM,CAAC,aAAa,IAAI,GAAG,CAAC,CAC/B,CAAC;AACJ,CAAC;AARD,gCAQC;AAED;;;GAGG;AACH,SAAgB,UAAU,CAAC,GAAQ;IACjC,OAAO,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,IAAI,GAAG,CAAC;AAC3E,CAAC;AAFD,gCAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plain-object.js","sourceRoot":"","sources":["../../src/plain-object.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plain-object.js","sourceRoot":"","sources":["../../src/plain-object.ts"],"names":[],"mappings":"AAuEA;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,GAAQ;IACjC,OAAO,CACL,OAAO,GAAG,KAAK,QAAQ;QACvB,IAAI,KAAK,GAAG;QACZ,CAAC,GAAG,CAAC,WAAW,KAAK,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,WAAW,YAAY,QAAQ,CAAC,CAAC;QACtE,CAAC,CAAC,MAAM,CAAC,QAAQ,IAAI,GAAG,CAAC;QACzB,CAAC,CAAC,MAAM,CAAC,aAAa,IAAI,GAAG,CAAC,CAC/B,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,GAAQ;IACjC,OAAO,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,IAAI,GAAG,CAAC;AAC3E,CAAC"}
|
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
* Matches any type of function
|
|
3
3
|
*/
|
|
4
4
|
export declare type AnyFunc = (...args: any[]) => any;
|
|
5
|
+
/**
|
|
6
|
+
* Gives true if the given type T is a function, false otherwise.
|
|
7
|
+
* @typeparam T - the input type
|
|
8
|
+
*/
|
|
9
|
+
export declare type IsAnyFunc<T> = AnyFunc extends T ? true : false;
|
|
5
10
|
/**
|
|
6
11
|
* A predicate type for any record that resolves to true if any of the record
|
|
7
12
|
* properties is a function, false otherwise.
|
|
8
13
|
* This is useful to have a coarse discrimination between pure data objects and class instances.
|
|
14
|
+
* @typeparam T - the input type
|
|
9
15
|
*/
|
|
10
|
-
export declare type IsObjWithoutFunctions<T
|
|
16
|
+
export declare type IsObjWithoutFunctions<T> = AnyFunc extends T[keyof T] ? false : true;
|
|
11
17
|
/**
|
|
12
18
|
* A predicate type that resolves to true if the given type satisfies:
|
|
13
19
|
* - it is an object type (not a primitive)
|
|
@@ -15,8 +21,9 @@ export declare type IsObjWithoutFunctions<T extends Record<any, any>> = AnyFunc
|
|
|
15
21
|
* - it is not iterable
|
|
16
22
|
* - it does not have any properties that are functions
|
|
17
23
|
* Otherwise, it resolves to false
|
|
24
|
+
* @typeparam T - the input type
|
|
18
25
|
*/
|
|
19
|
-
export declare type IsPlainObj<T> = T extends null | undefined | number | string | boolean | bigint | symbol | AnyFunc | Iterable<
|
|
26
|
+
export declare type IsPlainObj<T> = T extends null | undefined | number | string | boolean | bigint | symbol | AnyFunc | Iterable<any> | AsyncIterable<any> ? false : IsObjWithoutFunctions<T>;
|
|
20
27
|
/**
|
|
21
28
|
* Utility type that will only accept objects that are considered 'plain objects' according
|
|
22
29
|
* to the `IsPlainObj` predicate type.
|
|
@@ -28,6 +35,18 @@ export declare type PlainObj<T> = IsPlainObj<T> extends true ? T : never;
|
|
|
28
35
|
* @typeparam T - the value type to test
|
|
29
36
|
*/
|
|
30
37
|
export declare type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
38
|
+
/**
|
|
39
|
+
* Utility type that will only return true if the input type T is a (readonly) array.
|
|
40
|
+
* @typeparm T - the value type to test
|
|
41
|
+
*/
|
|
42
|
+
export declare type IsArray<T> = T extends readonly any[] ? true : false;
|
|
43
|
+
/**
|
|
44
|
+
* Utility type to exclude any types that are iterable. Useful in cases where
|
|
45
|
+
* plain objects are required as inputs but not arrays.
|
|
46
|
+
*/
|
|
47
|
+
export declare type NotIterable = {
|
|
48
|
+
[Symbol.iterator]?: never;
|
|
49
|
+
};
|
|
31
50
|
/**
|
|
32
51
|
* Companion function to the `IsRecord<T>` type that checks whether the given object is a pure
|
|
33
52
|
* data object.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rimbu/base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Utilities to implement Rimbu collections",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"array",
|
|
@@ -47,11 +47,12 @@
|
|
|
47
47
|
"format:check": "yarn format:base --check",
|
|
48
48
|
"lint": "eslint src",
|
|
49
49
|
"test": "jest",
|
|
50
|
+
"test:types": "tsd",
|
|
50
51
|
"typecheck": "tsc"
|
|
51
52
|
},
|
|
52
53
|
"sideEffects": false,
|
|
53
54
|
"dependencies": {
|
|
54
|
-
"@rimbu/common": "^0.
|
|
55
|
+
"@rimbu/common": "^0.11.0",
|
|
55
56
|
"tslib": "^2.4.0"
|
|
56
57
|
},
|
|
57
58
|
"publishConfig": {
|
|
@@ -61,5 +62,5 @@
|
|
|
61
62
|
"index": "src/index.ts",
|
|
62
63
|
"replacer": "../../config/denoify-rimbu-replacer.js"
|
|
63
64
|
},
|
|
64
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "28454fe17a4e51a42f6107f7b1733270d0d88de5"
|
|
65
66
|
}
|
package/src/plain-object.ts
CHANGED
|
@@ -3,13 +3,21 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export type AnyFunc = (...args: any[]) => any;
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Gives true if the given type T is a function, false otherwise.
|
|
8
|
+
* @typeparam T - the input type
|
|
9
|
+
*/
|
|
10
|
+
export type IsAnyFunc<T> = AnyFunc extends T ? true : false;
|
|
11
|
+
|
|
6
12
|
/**
|
|
7
13
|
* A predicate type for any record that resolves to true if any of the record
|
|
8
14
|
* properties is a function, false otherwise.
|
|
9
15
|
* This is useful to have a coarse discrimination between pure data objects and class instances.
|
|
16
|
+
* @typeparam T - the input type
|
|
10
17
|
*/
|
|
11
|
-
export type IsObjWithoutFunctions<T extends
|
|
12
|
-
|
|
18
|
+
export type IsObjWithoutFunctions<T> = AnyFunc extends T[keyof T]
|
|
19
|
+
? false
|
|
20
|
+
: true;
|
|
13
21
|
|
|
14
22
|
/**
|
|
15
23
|
* A predicate type that resolves to true if the given type satisfies:
|
|
@@ -18,6 +26,7 @@ export type IsObjWithoutFunctions<T extends Record<any, any>> =
|
|
|
18
26
|
* - it is not iterable
|
|
19
27
|
* - it does not have any properties that are functions
|
|
20
28
|
* Otherwise, it resolves to false
|
|
29
|
+
* @typeparam T - the input type
|
|
21
30
|
*/
|
|
22
31
|
export type IsPlainObj<T> = T extends
|
|
23
32
|
| null
|
|
@@ -28,8 +37,8 @@ export type IsPlainObj<T> = T extends
|
|
|
28
37
|
| bigint
|
|
29
38
|
| symbol
|
|
30
39
|
| AnyFunc
|
|
31
|
-
| Iterable<
|
|
32
|
-
| AsyncIterable<
|
|
40
|
+
| Iterable<any>
|
|
41
|
+
| AsyncIterable<any>
|
|
33
42
|
? false
|
|
34
43
|
: IsObjWithoutFunctions<T>;
|
|
35
44
|
|
|
@@ -46,6 +55,20 @@ export type PlainObj<T> = IsPlainObj<T> extends true ? T : never;
|
|
|
46
55
|
*/
|
|
47
56
|
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
48
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Utility type that will only return true if the input type T is a (readonly) array.
|
|
60
|
+
* @typeparm T - the value type to test
|
|
61
|
+
*/
|
|
62
|
+
export type IsArray<T> = T extends readonly any[] ? true : false;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Utility type to exclude any types that are iterable. Useful in cases where
|
|
66
|
+
* plain objects are required as inputs but not arrays.
|
|
67
|
+
*/
|
|
68
|
+
export type NotIterable = {
|
|
69
|
+
[Symbol.iterator]?: never;
|
|
70
|
+
};
|
|
71
|
+
|
|
49
72
|
/**
|
|
50
73
|
* Companion function to the `IsRecord<T>` type that checks whether the given object is a pure
|
|
51
74
|
* data object.
|