is-what 3.14.0 → 3.14.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs.js +13 -3
- package/dist/index.esm.js +13 -4
- package/package.json +8 -2
- package/test/ava.ts +12 -6
- package/types/index.d.ts +15 -7
package/dist/index.cjs.js
CHANGED
@@ -33,7 +33,7 @@ function isNull(payload) {
|
|
33
33
|
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
|
34
34
|
*
|
35
35
|
* @param {*} payload
|
36
|
-
* @returns {payload is
|
36
|
+
* @returns {payload is PlainObject}
|
37
37
|
*/
|
38
38
|
function isPlainObject(payload) {
|
39
39
|
if (getType(payload) !== 'Object')
|
@@ -44,7 +44,7 @@ function isPlainObject(payload) {
|
|
44
44
|
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
|
45
45
|
*
|
46
46
|
* @param {*} payload
|
47
|
-
* @returns {payload is
|
47
|
+
* @returns {payload is PlainObject}
|
48
48
|
*/
|
49
49
|
function isObject(payload) {
|
50
50
|
return isPlainObject(payload);
|
@@ -58,11 +58,20 @@ function isObject(payload) {
|
|
58
58
|
function isEmptyObject(payload) {
|
59
59
|
return isPlainObject(payload) && Object.keys(payload).length === 0;
|
60
60
|
}
|
61
|
+
/**
|
62
|
+
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
|
63
|
+
*
|
64
|
+
* @param {*} payload
|
65
|
+
* @returns {payload is PlainObject}
|
66
|
+
*/
|
67
|
+
function isFullObject(payload) {
|
68
|
+
return isPlainObject(payload) && Object.keys(payload).length > 0;
|
69
|
+
}
|
61
70
|
/**
|
62
71
|
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
|
63
72
|
*
|
64
73
|
* @param {*} payload
|
65
|
-
* @returns {payload is
|
74
|
+
* @returns {payload is PlainObject}
|
66
75
|
*/
|
67
76
|
function isAnyObject(payload) {
|
68
77
|
return getType(payload) === 'Object';
|
@@ -331,6 +340,7 @@ exports.isEmptyString = isEmptyString;
|
|
331
340
|
exports.isError = isError;
|
332
341
|
exports.isFile = isFile;
|
333
342
|
exports.isFullArray = isFullArray;
|
343
|
+
exports.isFullObject = isFullObject;
|
334
344
|
exports.isFullString = isFullString;
|
335
345
|
exports.isFunction = isFunction;
|
336
346
|
exports.isMap = isMap;
|
package/dist/index.esm.js
CHANGED
@@ -29,7 +29,7 @@ function isNull(payload) {
|
|
29
29
|
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
|
30
30
|
*
|
31
31
|
* @param {*} payload
|
32
|
-
* @returns {payload is
|
32
|
+
* @returns {payload is PlainObject}
|
33
33
|
*/
|
34
34
|
function isPlainObject(payload) {
|
35
35
|
if (getType(payload) !== 'Object')
|
@@ -40,7 +40,7 @@ function isPlainObject(payload) {
|
|
40
40
|
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
|
41
41
|
*
|
42
42
|
* @param {*} payload
|
43
|
-
* @returns {payload is
|
43
|
+
* @returns {payload is PlainObject}
|
44
44
|
*/
|
45
45
|
function isObject(payload) {
|
46
46
|
return isPlainObject(payload);
|
@@ -54,11 +54,20 @@ function isObject(payload) {
|
|
54
54
|
function isEmptyObject(payload) {
|
55
55
|
return isPlainObject(payload) && Object.keys(payload).length === 0;
|
56
56
|
}
|
57
|
+
/**
|
58
|
+
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
|
59
|
+
*
|
60
|
+
* @param {*} payload
|
61
|
+
* @returns {payload is PlainObject}
|
62
|
+
*/
|
63
|
+
function isFullObject(payload) {
|
64
|
+
return isPlainObject(payload) && Object.keys(payload).length > 0;
|
65
|
+
}
|
57
66
|
/**
|
58
67
|
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
|
59
68
|
*
|
60
69
|
* @param {*} payload
|
61
|
-
* @returns {payload is
|
70
|
+
* @returns {payload is PlainObject}
|
62
71
|
*/
|
63
72
|
function isAnyObject(payload) {
|
64
73
|
return getType(payload) === 'Object';
|
@@ -315,4 +324,4 @@ function isType(payload, type) {
|
|
315
324
|
return getType(payload) === name || Boolean(payload && payload.constructor === type);
|
316
325
|
}
|
317
326
|
|
318
|
-
export { getType, isAnyObject, isArray, isBlob, isBoolean, isDate, isEmptyArray, isEmptyObject, isEmptyString, isError, isFile, isFullArray, isFullString, isFunction, isMap, isNaNValue, isNull, isNullOrUndefined, isNumber, isObject, isObjectLike, isOneOf, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isType, isUndefined, isWeakMap, isWeakSet };
|
327
|
+
export { getType, isAnyObject, isArray, isBlob, isBoolean, isDate, isEmptyArray, isEmptyObject, isEmptyString, isError, isFile, isFullArray, isFullObject, isFullString, isFunction, isMap, isNaNValue, isNull, isNullOrUndefined, isNumber, isObject, isObjectLike, isOneOf, 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.14.
|
4
|
+
"version": "3.14.1",
|
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",
|
@@ -12,7 +12,8 @@
|
|
12
12
|
"jest-w": "jest --watchAll",
|
13
13
|
"lint": "tsc --noEmit src/index.ts && eslint . --ext .js,.jsx,.ts,.tsx",
|
14
14
|
"rollup": "rollup -c ./build.js",
|
15
|
-
"build": "rimraf types && rimraf dist && npm run lint && npm run rollup && npm run test && npm run jest"
|
15
|
+
"build": "rimraf types && rimraf dist && npm run lint && npm run rollup && npm run test && npm run jest",
|
16
|
+
"release": "npm run build && np"
|
16
17
|
},
|
17
18
|
"repository": {
|
18
19
|
"type": "git",
|
@@ -59,6 +60,7 @@
|
|
59
60
|
"eslint-config-prettier": "^7.2.0",
|
60
61
|
"eslint-plugin-tree-shaking": "^1.8.0",
|
61
62
|
"jest": "^26.6.3",
|
63
|
+
"np": "^7.4.0",
|
62
64
|
"prettier": "^2.2.1",
|
63
65
|
"regenerator-runtime": "^0.13.7",
|
64
66
|
"rimraf": "^3.0.2",
|
@@ -76,5 +78,9 @@
|
|
76
78
|
"tsconfig-paths/register",
|
77
79
|
"ts-node/register"
|
78
80
|
]
|
81
|
+
},
|
82
|
+
"np": {
|
83
|
+
"yarn": false,
|
84
|
+
"branch": "production"
|
79
85
|
}
|
80
86
|
}
|
package/test/ava.ts
CHANGED
@@ -31,6 +31,7 @@ import {
|
|
31
31
|
isNaNValue,
|
32
32
|
isEmptyObject,
|
33
33
|
isOneOf,
|
34
|
+
isFullObject,
|
34
35
|
} from '../src/index'
|
35
36
|
|
36
37
|
// const blob = Buffer.from([])
|
@@ -42,8 +43,13 @@ test('Basic true tests', t => {
|
|
42
43
|
t.is(isNullOrUndefined(null), true)
|
43
44
|
t.is(isNullOrUndefined(undefined), true)
|
44
45
|
t.is(isObject({}), true)
|
46
|
+
t.is(isEmptyObject({}), true)
|
47
|
+
t.is(isFullObject({0: ''}), true)
|
48
|
+
t.is(isFullObject({'': ''}), true)
|
45
49
|
t.is(isObject(new Object()), true)
|
46
50
|
t.is(isArray([]), true)
|
51
|
+
t.is(isEmptyArray([]), true)
|
52
|
+
t.is(isFullArray(['']), true)
|
47
53
|
t.is(isArray(new Array()), true)
|
48
54
|
t.is(isString(''), true)
|
49
55
|
t.is(isString('_'), true)
|
@@ -122,7 +128,7 @@ test('isEmptyArray', t => {
|
|
122
128
|
t.is(isEmptyArray([]), true)
|
123
129
|
t.is(isEmptyArray(new Array()), true)
|
124
130
|
t.is(isEmptyArray(new Array(0)), true)
|
125
|
-
|
131
|
+
|
126
132
|
t.is(isEmptyArray(new Array(1)), false)
|
127
133
|
t.is(isEmptyArray([undefined]), false)
|
128
134
|
t.is(isEmptyArray(null), false)
|
@@ -141,11 +147,11 @@ test('isFullArray', t => {
|
|
141
147
|
t.is(isFullArray([undefined]), true)
|
142
148
|
t.is(isFullArray([null]), true)
|
143
149
|
t.is(isFullArray(['']), true)
|
144
|
-
|
150
|
+
|
145
151
|
t.is(isFullArray([]), false)
|
146
152
|
t.is(isFullArray(new Array()), false)
|
147
153
|
t.is(isFullArray(new Array(0)), false)
|
148
|
-
|
154
|
+
|
149
155
|
t.is(isFullArray(null), false)
|
150
156
|
t.is(isFullArray(new Date()), false)
|
151
157
|
t.is(isFullArray(new Error('')), false)
|
@@ -346,7 +352,7 @@ test('type related tests', t => {
|
|
346
352
|
// }
|
347
353
|
|
348
354
|
// const a: Record<string, number> = {}
|
349
|
-
|
355
|
+
|
350
356
|
// a[fn(1)] = fn(2)
|
351
357
|
|
352
358
|
// const myArray: string | string[] = ['a', 'b']
|
@@ -355,7 +361,7 @@ test('type related tests', t => {
|
|
355
361
|
// }
|
356
362
|
|
357
363
|
// const a: Record<string, number> = {}
|
358
|
-
|
364
|
+
|
359
365
|
// a[myArray[1]] = myArray[0]
|
360
366
|
|
361
367
|
// const myArray: string | any[] = [1, 2, 'a', 'b']
|
@@ -364,7 +370,7 @@ test('type related tests', t => {
|
|
364
370
|
// }
|
365
371
|
|
366
372
|
// const a: Record<string, number> = {}
|
367
|
-
|
373
|
+
|
368
374
|
// a[myArray[1]] = myArray[0]
|
369
375
|
|
370
376
|
})
|
package/types/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
export declare type AnyFunction = (...args: any[]) => any;
|
2
2
|
export declare type AnyAsyncFunction = (...args: any[]) => Promise<any>;
|
3
3
|
export declare type AnyClass = new (...args: any[]) => any;
|
4
|
+
export declare type PlainObject = Record<string | number | symbol, any>;
|
4
5
|
declare type TypeGuard<A, B extends A> = (payload: A) => payload is B;
|
5
6
|
/**
|
6
7
|
* Returns the object type of the given payload
|
@@ -27,16 +28,16 @@ export declare function isNull(payload: any): payload is null;
|
|
27
28
|
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
|
28
29
|
*
|
29
30
|
* @param {*} payload
|
30
|
-
* @returns {payload is
|
31
|
+
* @returns {payload is PlainObject}
|
31
32
|
*/
|
32
|
-
export declare function isPlainObject(payload: any): payload is
|
33
|
+
export declare function isPlainObject(payload: any): payload is PlainObject;
|
33
34
|
/**
|
34
35
|
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
|
35
36
|
*
|
36
37
|
* @param {*} payload
|
37
|
-
* @returns {payload is
|
38
|
+
* @returns {payload is PlainObject}
|
38
39
|
*/
|
39
|
-
export declare function isObject(payload: any): payload is
|
40
|
+
export declare function isObject(payload: any): payload is PlainObject;
|
40
41
|
/**
|
41
42
|
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
|
42
43
|
*
|
@@ -46,13 +47,20 @@ export declare function isObject(payload: any): payload is Record<string, any>;
|
|
46
47
|
export declare function isEmptyObject(payload: any): payload is {
|
47
48
|
[K in any]: never;
|
48
49
|
};
|
50
|
+
/**
|
51
|
+
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
|
52
|
+
*
|
53
|
+
* @param {*} payload
|
54
|
+
* @returns {payload is PlainObject}
|
55
|
+
*/
|
56
|
+
export declare function isFullObject(payload: any): payload is PlainObject;
|
49
57
|
/**
|
50
58
|
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
|
51
59
|
*
|
52
60
|
* @param {*} payload
|
53
|
-
* @returns {payload is
|
61
|
+
* @returns {payload is PlainObject}
|
54
62
|
*/
|
55
|
-
export declare function isAnyObject(payload: any): payload is
|
63
|
+
export declare function isAnyObject(payload: any): payload is PlainObject;
|
56
64
|
/**
|
57
65
|
* Returns whether the payload is an object like a type passed in < >
|
58
66
|
*
|
@@ -62,7 +70,7 @@ export declare function isAnyObject(payload: any): payload is Record<string, any
|
|
62
70
|
* @param {*} payload
|
63
71
|
* @returns {payload is T}
|
64
72
|
*/
|
65
|
-
export declare function isObjectLike<T extends
|
73
|
+
export declare function isObjectLike<T extends PlainObject>(payload: any): payload is T;
|
66
74
|
/**
|
67
75
|
* Returns whether the payload is a function (regular or async)
|
68
76
|
*
|