@rimbu/base 0.8.2 → 0.9.2
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 +1 -1
- package/dist/main/index.js +4 -6
- package/dist/main/index.js.map +1 -1
- package/dist/main/plain-object.js +27 -0
- package/dist/main/plain-object.js.map +1 -0
- package/dist/module/index.js +4 -4
- package/dist/module/index.js.map +1 -1
- package/dist/module/plain-object.js +22 -0
- package/dist/module/plain-object.js.map +1 -0
- package/dist/types/index.d.ts +4 -4
- package/dist/types/plain-object.d.ts +43 -0
- package/package.json +3 -3
- package/src/index.ts +4 -5
- package/src/plain-object.ts +72 -0
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ console.log(arr);
|
|
|
76
76
|
|
|
77
77
|
## Contributing
|
|
78
78
|
|
|
79
|
-
Feel very welcome to contribute to further improve Rimbu. Please read our [Contributing guide](
|
|
79
|
+
Feel very welcome to contribute to further improve Rimbu. Please read our [Contributing guide](https://github.com/rimbu-org/rimbu/blob/main/CONTRIBUTING.md).
|
|
80
80
|
|
|
81
81
|
## Contributors
|
|
82
82
|
|
package/dist/main/index.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RimbuError = exports.Entry = exports.Arr = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var RimbuError = tslib_1.__importStar(require("./rimbu-error"));
|
|
10
|
-
exports.RimbuError = RimbuError;
|
|
5
|
+
exports.Arr = tslib_1.__importStar(require("./arr"));
|
|
6
|
+
exports.Entry = tslib_1.__importStar(require("./entry"));
|
|
7
|
+
exports.RimbuError = tslib_1.__importStar(require("./rimbu-error"));
|
|
8
|
+
tslib_1.__exportStar(require("./plain-object"), exports);
|
|
11
9
|
tslib_1.__exportStar(require("./internal"), exports);
|
|
12
10
|
//# sourceMappingURL=index.js.map
|
package/dist/main/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,qDAA6B;AAC7B,yDAAiC;AACjC,oEAA4C;AAC5C,yDAA+B;AAE/B,qDAA2B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isIterable = exports.isPlainObj = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Companion function to the `IsRecord<T>` type that checks whether the given object is a pure
|
|
6
|
+
* data object.
|
|
7
|
+
* @param obj - the object to check
|
|
8
|
+
* @returns true if the given object is a pure data object
|
|
9
|
+
* @note does not check whether a record's properties are not functions
|
|
10
|
+
*/
|
|
11
|
+
function isPlainObj(obj) {
|
|
12
|
+
return (typeof obj === 'object' &&
|
|
13
|
+
null !== obj &&
|
|
14
|
+
(obj.constructor === Object || !(obj.constructor instanceof Function)) &&
|
|
15
|
+
!(Symbol.iterator in obj) &&
|
|
16
|
+
!(Symbol.asyncIterator in obj));
|
|
17
|
+
}
|
|
18
|
+
exports.isPlainObj = isPlainObj;
|
|
19
|
+
/**
|
|
20
|
+
* Returns true if the given object is Iterable
|
|
21
|
+
* @param obj - the object to check
|
|
22
|
+
*/
|
|
23
|
+
function isIterable(obj) {
|
|
24
|
+
return obj !== null && typeof obj === 'object' && Symbol.iterator in obj;
|
|
25
|
+
}
|
|
26
|
+
exports.isIterable = isIterable;
|
|
27
|
+
//# sourceMappingURL=plain-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plain-object.js","sourceRoot":"","sources":["../../src/plain-object.ts"],"names":[],"mappings":";;;AAgDA;;;;;;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"}
|
package/dist/module/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
1
|
+
export * as Arr from './arr';
|
|
2
|
+
export * as Entry from './entry';
|
|
3
|
+
export * as RimbuError from './rimbu-error';
|
|
4
|
+
export * from './plain-object';
|
|
5
5
|
export * from './internal';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,cAAc,gBAAgB,CAAC;AAE/B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Companion function to the `IsRecord<T>` type that checks whether the given object is a pure
|
|
3
|
+
* data object.
|
|
4
|
+
* @param obj - the object to check
|
|
5
|
+
* @returns true if the given object is a pure data object
|
|
6
|
+
* @note does not check whether a record's properties are not functions
|
|
7
|
+
*/
|
|
8
|
+
export function isPlainObj(obj) {
|
|
9
|
+
return (typeof obj === 'object' &&
|
|
10
|
+
null !== obj &&
|
|
11
|
+
(obj.constructor === Object || !(obj.constructor instanceof Function)) &&
|
|
12
|
+
!(Symbol.iterator in obj) &&
|
|
13
|
+
!(Symbol.asyncIterator in obj));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns true if the given object is Iterable
|
|
17
|
+
* @param obj - the object to check
|
|
18
|
+
*/
|
|
19
|
+
export function isIterable(obj) {
|
|
20
|
+
return obj !== null && typeof obj === 'object' && Symbol.iterator in obj;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=plain-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plain-object.js","sourceRoot":"","sources":["../../src/plain-object.ts"],"names":[],"mappings":"AAgDA;;;;;;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"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
1
|
+
export * as Arr from './arr';
|
|
2
|
+
export * as Entry from './entry';
|
|
3
|
+
export * as RimbuError from './rimbu-error';
|
|
4
|
+
export * from './plain-object';
|
|
5
5
|
export * from './internal';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches any type of function
|
|
3
|
+
*/
|
|
4
|
+
export declare type AnyFunc = (...args: any[]) => any;
|
|
5
|
+
/**
|
|
6
|
+
* A predicate type for any record that resolves to true if any of the record
|
|
7
|
+
* properties is a function, false otherwise.
|
|
8
|
+
* This is useful to have a coarse discrimination between pure data objects and class instances.
|
|
9
|
+
*/
|
|
10
|
+
export declare type IsObjWithoutFunctions<T extends Record<any, any>> = AnyFunc extends T[keyof T] ? false : true;
|
|
11
|
+
/**
|
|
12
|
+
* A predicate type that resolves to true if the given type satisfies:
|
|
13
|
+
* - it is an object type (not a primitive)
|
|
14
|
+
* - it is not a function
|
|
15
|
+
* - it is not iterable
|
|
16
|
+
* - it does not have any properties that are functions
|
|
17
|
+
* Otherwise, it resolves to false
|
|
18
|
+
*/
|
|
19
|
+
export declare type IsPlainObj<T> = T extends null | undefined | number | string | boolean | bigint | symbol | AnyFunc | Iterable<unknown> | AsyncIterable<unknown> ? false : IsObjWithoutFunctions<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Utility type that will only accept objects that are considered 'plain objects' according
|
|
22
|
+
* to the `IsPlainObj` predicate type.
|
|
23
|
+
* @typeparam T - the value type to test
|
|
24
|
+
*/
|
|
25
|
+
export declare type PlainObj<T> = IsPlainObj<T> extends true ? T : never;
|
|
26
|
+
/**
|
|
27
|
+
* Utility type that will only return true if the input type T is equal to `any`.
|
|
28
|
+
* @typeparam T - the value type to test
|
|
29
|
+
*/
|
|
30
|
+
export declare type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
31
|
+
/**
|
|
32
|
+
* Companion function to the `IsRecord<T>` type that checks whether the given object is a pure
|
|
33
|
+
* data object.
|
|
34
|
+
* @param obj - the object to check
|
|
35
|
+
* @returns true if the given object is a pure data object
|
|
36
|
+
* @note does not check whether a record's properties are not functions
|
|
37
|
+
*/
|
|
38
|
+
export declare function isPlainObj(obj: any): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Returns true if the given object is Iterable
|
|
41
|
+
* @param obj - the object to check
|
|
42
|
+
*/
|
|
43
|
+
export declare function isIterable(obj: any): obj is Iterable<unknown>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rimbu/base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "Utilities to implement Rimbu collections",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"array",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"sideEffects": false,
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@rimbu/common": "^0.
|
|
54
|
+
"@rimbu/common": "^0.10.0",
|
|
55
55
|
"tslib": "^2.4.0"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"index": "src/index.ts",
|
|
62
62
|
"replacer": "../../config/denoify-rimbu-replacer.js"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "4d6b7411c36f599331185b1bc597e58f34954d1a"
|
|
65
65
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { Arr, Entry, RimbuError };
|
|
1
|
+
export * as Arr from './arr';
|
|
2
|
+
export * as Entry from './entry';
|
|
3
|
+
export * as RimbuError from './rimbu-error';
|
|
4
|
+
export * from './plain-object';
|
|
6
5
|
|
|
7
6
|
export * from './internal';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matches any type of function
|
|
3
|
+
*/
|
|
4
|
+
export type AnyFunc = (...args: any[]) => any;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A predicate type for any record that resolves to true if any of the record
|
|
8
|
+
* properties is a function, false otherwise.
|
|
9
|
+
* This is useful to have a coarse discrimination between pure data objects and class instances.
|
|
10
|
+
*/
|
|
11
|
+
export type IsObjWithoutFunctions<T extends Record<any, any>> =
|
|
12
|
+
AnyFunc extends T[keyof T] ? false : true;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A predicate type that resolves to true if the given type satisfies:
|
|
16
|
+
* - it is an object type (not a primitive)
|
|
17
|
+
* - it is not a function
|
|
18
|
+
* - it is not iterable
|
|
19
|
+
* - it does not have any properties that are functions
|
|
20
|
+
* Otherwise, it resolves to false
|
|
21
|
+
*/
|
|
22
|
+
export type IsPlainObj<T> = T extends
|
|
23
|
+
| null
|
|
24
|
+
| undefined
|
|
25
|
+
| number
|
|
26
|
+
| string
|
|
27
|
+
| boolean
|
|
28
|
+
| bigint
|
|
29
|
+
| symbol
|
|
30
|
+
| AnyFunc
|
|
31
|
+
| Iterable<unknown>
|
|
32
|
+
| AsyncIterable<unknown>
|
|
33
|
+
? false
|
|
34
|
+
: IsObjWithoutFunctions<T>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Utility type that will only accept objects that are considered 'plain objects' according
|
|
38
|
+
* to the `IsPlainObj` predicate type.
|
|
39
|
+
* @typeparam T - the value type to test
|
|
40
|
+
*/
|
|
41
|
+
export type PlainObj<T> = IsPlainObj<T> extends true ? T : never;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Utility type that will only return true if the input type T is equal to `any`.
|
|
45
|
+
* @typeparam T - the value type to test
|
|
46
|
+
*/
|
|
47
|
+
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Companion function to the `IsRecord<T>` type that checks whether the given object is a pure
|
|
51
|
+
* data object.
|
|
52
|
+
* @param obj - the object to check
|
|
53
|
+
* @returns true if the given object is a pure data object
|
|
54
|
+
* @note does not check whether a record's properties are not functions
|
|
55
|
+
*/
|
|
56
|
+
export function isPlainObj(obj: any): boolean {
|
|
57
|
+
return (
|
|
58
|
+
typeof obj === 'object' &&
|
|
59
|
+
null !== obj &&
|
|
60
|
+
(obj.constructor === Object || !(obj.constructor instanceof Function)) &&
|
|
61
|
+
!(Symbol.iterator in obj) &&
|
|
62
|
+
!(Symbol.asyncIterator in obj)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Returns true if the given object is Iterable
|
|
68
|
+
* @param obj - the object to check
|
|
69
|
+
*/
|
|
70
|
+
export function isIterable(obj: any): obj is Iterable<unknown> {
|
|
71
|
+
return obj !== null && typeof obj === 'object' && Symbol.iterator in obj;
|
|
72
|
+
}
|