@rimbu/base 0.9.0 → 0.9.3
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/plain-object.js +5 -11
- package/dist/main/plain-object.js.map +1 -1
- package/dist/module/plain-object.js +5 -11
- package/dist/module/plain-object.js.map +1 -1
- package/dist/types/plain-object.d.ts +10 -0
- package/package.json +3 -4
- package/src/plain-object.ts +18 -15
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
|
|
|
@@ -9,17 +9,11 @@ exports.isIterable = exports.isPlainObj = void 0;
|
|
|
9
9
|
* @note does not check whether a record's properties are not functions
|
|
10
10
|
*/
|
|
11
11
|
function isPlainObj(obj) {
|
|
12
|
-
|
|
13
|
-
null
|
|
14
|
-
|
|
15
|
-
(
|
|
16
|
-
|
|
17
|
-
Symbol.iterator in obj ||
|
|
18
|
-
Symbol.asyncIterator in obj) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
var prototype = Object.getPrototypeOf(obj);
|
|
22
|
-
return null === prototype || prototype === Object.prototype;
|
|
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));
|
|
23
17
|
}
|
|
24
18
|
exports.isPlainObj = isPlainObj;
|
|
25
19
|
/**
|
|
@@ -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":";;;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"}
|
|
@@ -6,17 +6,11 @@
|
|
|
6
6
|
* @note does not check whether a record's properties are not functions
|
|
7
7
|
*/
|
|
8
8
|
export function isPlainObj(obj) {
|
|
9
|
-
|
|
10
|
-
null
|
|
11
|
-
|
|
12
|
-
(
|
|
13
|
-
|
|
14
|
-
Symbol.iterator in obj ||
|
|
15
|
-
Symbol.asyncIterator in obj) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
const prototype = Object.getPrototypeOf(obj);
|
|
19
|
-
return null === prototype || prototype === Object.prototype;
|
|
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));
|
|
20
14
|
}
|
|
21
15
|
/**
|
|
22
16
|
* Returns true if the given object is Iterable
|
|
@@ -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":"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"}
|
|
@@ -17,7 +17,17 @@ export declare type IsObjWithoutFunctions<T extends Record<any, any>> = AnyFunc
|
|
|
17
17
|
* Otherwise, it resolves to false
|
|
18
18
|
*/
|
|
19
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
|
+
*/
|
|
20
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;
|
|
21
31
|
/**
|
|
22
32
|
* Companion function to the `IsRecord<T>` type that checks whether the given object is a pure
|
|
23
33
|
* data object.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rimbu/base",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Utilities to implement Rimbu collections",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"array",
|
|
@@ -51,8 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"sideEffects": false,
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@rimbu/common": "^0.
|
|
55
|
-
"tslib": "^2.4.0"
|
|
54
|
+
"@rimbu/common": "^0.10.1"
|
|
56
55
|
},
|
|
57
56
|
"publishConfig": {
|
|
58
57
|
"access": "public"
|
|
@@ -61,5 +60,5 @@
|
|
|
61
60
|
"index": "src/index.ts",
|
|
62
61
|
"replacer": "../../config/denoify-rimbu-replacer.js"
|
|
63
62
|
},
|
|
64
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "9e7cd56ce066f7903c5749110c2a7a8b06809403"
|
|
65
64
|
}
|
package/src/plain-object.ts
CHANGED
|
@@ -33,8 +33,19 @@ export type IsPlainObj<T> = T extends
|
|
|
33
33
|
? false
|
|
34
34
|
: IsObjWithoutFunctions<T>;
|
|
35
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
|
+
*/
|
|
36
41
|
export type PlainObj<T> = IsPlainObj<T> extends true ? T : never;
|
|
37
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
|
+
|
|
38
49
|
/**
|
|
39
50
|
* Companion function to the `IsRecord<T>` type that checks whether the given object is a pure
|
|
40
51
|
* data object.
|
|
@@ -43,21 +54,13 @@ export type PlainObj<T> = IsPlainObj<T> extends true ? T : never;
|
|
|
43
54
|
* @note does not check whether a record's properties are not functions
|
|
44
55
|
*/
|
|
45
56
|
export function isPlainObj(obj: any): boolean {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
null
|
|
49
|
-
|
|
50
|
-
(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
Symbol.asyncIterator in obj
|
|
54
|
-
) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const prototype = Object.getPrototypeOf(obj);
|
|
59
|
-
|
|
60
|
-
return null === prototype || prototype === Object.prototype;
|
|
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
|
+
);
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
/**
|