is-what 3.9.1 → 3.10.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/dist/index.cjs.js +10 -0
- package/dist/index.esm.js +10 -1
- package/package.json +1 -1
- package/src/index.ts +10 -0
- package/test/ava.ts +18 -0
- package/types/index.d.ts +7 -0
package/dist/index.cjs.js
CHANGED
@@ -49,6 +49,15 @@ function isPlainObject(payload) {
|
|
49
49
|
function isObject(payload) {
|
50
50
|
return isPlainObject(payload);
|
51
51
|
}
|
52
|
+
/**
|
53
|
+
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
|
54
|
+
*
|
55
|
+
* @param {*} payload
|
56
|
+
* @returns {payload is {}}
|
57
|
+
*/
|
58
|
+
function isEmptyObject(payload) {
|
59
|
+
return isPlainObject(payload) && Object.keys(payload).length === 0;
|
60
|
+
}
|
52
61
|
/**
|
53
62
|
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
|
54
63
|
*
|
@@ -295,6 +304,7 @@ exports.isArray = isArray;
|
|
295
304
|
exports.isBlob = isBlob;
|
296
305
|
exports.isBoolean = isBoolean;
|
297
306
|
exports.isDate = isDate;
|
307
|
+
exports.isEmptyObject = isEmptyObject;
|
298
308
|
exports.isEmptyString = isEmptyString;
|
299
309
|
exports.isError = isError;
|
300
310
|
exports.isFile = isFile;
|
package/dist/index.esm.js
CHANGED
@@ -45,6 +45,15 @@ function isPlainObject(payload) {
|
|
45
45
|
function isObject(payload) {
|
46
46
|
return isPlainObject(payload);
|
47
47
|
}
|
48
|
+
/**
|
49
|
+
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
|
50
|
+
*
|
51
|
+
* @param {*} payload
|
52
|
+
* @returns {payload is {}}
|
53
|
+
*/
|
54
|
+
function isEmptyObject(payload) {
|
55
|
+
return isPlainObject(payload) && Object.keys(payload).length === 0;
|
56
|
+
}
|
48
57
|
/**
|
49
58
|
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
|
50
59
|
*
|
@@ -285,4 +294,4 @@ function isType(payload, type) {
|
|
285
294
|
return getType(payload) === name || Boolean(payload && payload.constructor === type);
|
286
295
|
}
|
287
296
|
|
288
|
-
export { getType, isAnyObject, isArray, isBlob, isBoolean, isDate, isEmptyString, isError, isFile, isFullString, isFunction, isMap, isNaNValue, isNull, isNullOrUndefined, isNumber, isObject, isObjectLike, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isType, isUndefined, isWeakMap, isWeakSet };
|
297
|
+
export { getType, isAnyObject, isArray, isBlob, isBoolean, isDate, isEmptyObject, isEmptyString, isError, isFile, isFullString, isFunction, isMap, isNaNValue, isNull, isNullOrUndefined, isNumber, isObject, isObjectLike, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isType, isUndefined, isWeakMap, isWeakSet };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "is-what",
|
3
3
|
"sideEffects": false,
|
4
|
-
"version": "3.
|
4
|
+
"version": "3.10.0",
|
5
5
|
"description": "JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.",
|
6
6
|
"main": "dist/index.cjs.js",
|
7
7
|
"module": "dist/index.esm.js",
|
package/src/index.ts
CHANGED
@@ -49,6 +49,16 @@ export function isObject (payload: any): payload is { [key: string]: any } {
|
|
49
49
|
return isPlainObject(payload)
|
50
50
|
}
|
51
51
|
|
52
|
+
/**
|
53
|
+
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
|
54
|
+
*
|
55
|
+
* @param {*} payload
|
56
|
+
* @returns {payload is {}}
|
57
|
+
*/
|
58
|
+
export function isEmptyObject (payload: any): payload is {} {
|
59
|
+
return isPlainObject(payload) && Object.keys(payload).length === 0
|
60
|
+
}
|
61
|
+
|
52
62
|
/**
|
53
63
|
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
|
54
64
|
*
|
package/test/ava.ts
CHANGED
@@ -27,6 +27,7 @@ import {
|
|
27
27
|
// isFile,
|
28
28
|
isPromise,
|
29
29
|
isNaNValue,
|
30
|
+
isEmptyObject,
|
30
31
|
} from '../src/index'
|
31
32
|
|
32
33
|
// const blob = Buffer.from([])
|
@@ -89,6 +90,23 @@ test('Basic false tests', t => {
|
|
89
90
|
t.is(isNullOrUndefined(NaN), false)
|
90
91
|
})
|
91
92
|
|
93
|
+
test('isEmptyObject', t => {
|
94
|
+
t.is(isEmptyObject({}), true)
|
95
|
+
t.is(isEmptyObject(new Object()), true)
|
96
|
+
|
97
|
+
t.is(isEmptyObject('{}'), false)
|
98
|
+
t.is(isEmptyObject('{}'), false)
|
99
|
+
t.is(isEmptyObject(null), false)
|
100
|
+
t.is(isEmptyObject(new Date()), false)
|
101
|
+
t.is(isEmptyObject(new Error('')), false)
|
102
|
+
t.is(isEmptyObject(new Date()), false)
|
103
|
+
t.is(isEmptyObject(Symbol()), false)
|
104
|
+
t.is(isEmptyObject(new Map()), false)
|
105
|
+
t.is(isEmptyObject(new WeakMap()), false)
|
106
|
+
t.is(isEmptyObject(new Set()), false)
|
107
|
+
t.is(isEmptyObject(new WeakSet()), false)
|
108
|
+
})
|
109
|
+
|
92
110
|
test('NaN tests', t => {
|
93
111
|
t.is(isNaNValue(NaN), true)
|
94
112
|
t.is(isNaNValue(new Error('')), false)
|
package/types/index.d.ts
CHANGED
@@ -37,6 +37,13 @@ export declare function isPlainObject(payload: any): payload is {
|
|
37
37
|
export declare function isObject(payload: any): payload is {
|
38
38
|
[key: string]: any;
|
39
39
|
};
|
40
|
+
/**
|
41
|
+
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
|
42
|
+
*
|
43
|
+
* @param {*} payload
|
44
|
+
* @returns {payload is {}}
|
45
|
+
*/
|
46
|
+
export declare function isEmptyObject(payload: any): payload is {};
|
40
47
|
/**
|
41
48
|
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
|
42
49
|
*
|