is-what 3.8.0 → 3.11.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/build/rollup.js CHANGED
@@ -23,7 +23,7 @@ const name = pkg.name
23
23
  const className = name.replace(/(^\w|-\w)/g, c => c.replace('-', '').toUpperCase())
24
24
  const external = Object.keys(pkg.dependencies || [])
25
25
  const plugins = [
26
- typescript({useTsconfigDeclarationDir: true}),
26
+ typescript({ useTsconfigDeclarationDir: true, tsconfigOverride: { exclude: ['test/**/*'] } }),
27
27
  ]
28
28
 
29
29
  // ------------------------------------------------------------------------------------------
@@ -33,15 +33,18 @@ function defaults (config) {
33
33
  // defaults
34
34
  const defaults = {
35
35
  plugins,
36
- external
36
+ external,
37
37
  }
38
38
  // defaults.output
39
39
  config.output = config.output.map(output => {
40
- return Object.assign({
41
- sourcemap: false,
42
- name: className,
43
- exports: 'named',
44
- }, output)
40
+ return Object.assign(
41
+ {
42
+ sourcemap: false,
43
+ name: className,
44
+ exports: 'named',
45
+ },
46
+ output
47
+ )
45
48
  })
46
49
  return Object.assign(defaults, config)
47
50
  }
@@ -50,8 +53,8 @@ export default [
50
53
  defaults({
51
54
  input: 'src/index.ts',
52
55
  output: [
53
- {file: 'dist/index.cjs.js', format: 'cjs'},
54
- {file: 'dist/index.esm.js', format: 'esm'},
56
+ { file: 'dist/index.cjs.js', format: 'cjs' },
57
+ { file: 'dist/index.esm.js', format: 'esm' },
55
58
  ],
56
59
  }),
57
60
  ]
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
  *
@@ -88,6 +97,15 @@ function isFunction(payload) {
88
97
  function isArray(payload) {
89
98
  return getType(payload) === 'Array';
90
99
  }
100
+ /**
101
+ * Returns whether the payload is a an empty array
102
+ *
103
+ * @param {*} payload
104
+ * @returns {payload is []}
105
+ */
106
+ function isEmptyArray(payload) {
107
+ return isArray(payload) && payload.length === 0;
108
+ }
91
109
  /**
92
110
  * Returns whether the payload is a string
93
111
  *
@@ -234,6 +252,15 @@ function isPromise(payload) {
234
252
  function isError(payload) {
235
253
  return getType(payload) === 'Error';
236
254
  }
255
+ /**
256
+ * Returns whether the payload is `NaN` but also a `number`
257
+ *
258
+ * @param {*} payload
259
+ * @returns {payload is typeof NaN}
260
+ */
261
+ function isNaNValue(payload) {
262
+ return getType(payload) === 'Number' && isNaN(payload);
263
+ }
237
264
  /**
238
265
  * Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
239
266
  *
@@ -286,12 +313,15 @@ exports.isArray = isArray;
286
313
  exports.isBlob = isBlob;
287
314
  exports.isBoolean = isBoolean;
288
315
  exports.isDate = isDate;
316
+ exports.isEmptyArray = isEmptyArray;
317
+ exports.isEmptyObject = isEmptyObject;
289
318
  exports.isEmptyString = isEmptyString;
290
319
  exports.isError = isError;
291
320
  exports.isFile = isFile;
292
321
  exports.isFullString = isFullString;
293
322
  exports.isFunction = isFunction;
294
323
  exports.isMap = isMap;
324
+ exports.isNaNValue = isNaNValue;
295
325
  exports.isNull = isNull;
296
326
  exports.isNullOrUndefined = isNullOrUndefined;
297
327
  exports.isNumber = isNumber;
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
  *
@@ -84,6 +93,15 @@ function isFunction(payload) {
84
93
  function isArray(payload) {
85
94
  return getType(payload) === 'Array';
86
95
  }
96
+ /**
97
+ * Returns whether the payload is a an empty array
98
+ *
99
+ * @param {*} payload
100
+ * @returns {payload is []}
101
+ */
102
+ function isEmptyArray(payload) {
103
+ return isArray(payload) && payload.length === 0;
104
+ }
87
105
  /**
88
106
  * Returns whether the payload is a string
89
107
  *
@@ -230,6 +248,15 @@ function isPromise(payload) {
230
248
  function isError(payload) {
231
249
  return getType(payload) === 'Error';
232
250
  }
251
+ /**
252
+ * Returns whether the payload is `NaN` but also a `number`
253
+ *
254
+ * @param {*} payload
255
+ * @returns {payload is typeof NaN}
256
+ */
257
+ function isNaNValue(payload) {
258
+ return getType(payload) === 'Number' && isNaN(payload);
259
+ }
233
260
  /**
234
261
  * Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
235
262
  *
@@ -276,4 +303,4 @@ function isType(payload, type) {
276
303
  return getType(payload) === name || Boolean(payload && payload.constructor === type);
277
304
  }
278
305
 
279
- export { getType, isAnyObject, isArray, isBlob, isBoolean, isDate, isEmptyString, isError, isFile, isFullString, isFunction, isMap, isNull, isNullOrUndefined, isNumber, isObject, isObjectLike, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isType, isUndefined, isWeakMap, isWeakSet };
306
+ export { getType, isAnyObject, isArray, isBlob, isBoolean, isDate, isEmptyArray, 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.8.0",
4
+ "version": "3.11.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",
@@ -47,30 +47,32 @@
47
47
  "homepage": "https://github.com/mesqueeb/is-what#readme",
48
48
  "dependencies": {},
49
49
  "devDependencies": {
50
- "@babel/core": "^7.9.0",
50
+ "@babel/core": "^7.11.0",
51
51
  "@types/babel-core": "^6.25.6",
52
- "@types/jest": "^25.2.1",
53
- "@typescript-eslint/eslint-plugin": "^2.27.0",
54
- "@typescript-eslint/parser": "^2.27.0",
55
- "ava": "^3.6.0",
52
+ "@types/jest": "^25.2.3",
53
+ "@typescript-eslint/eslint-plugin": "^2.34.0",
54
+ "@typescript-eslint/parser": "^2.34.0",
55
+ "ava": "^3.11.0",
56
56
  "babel-core": "^7.0.0-bridge.0",
57
- "babel-jest": "^25.3.0",
57
+ "babel-jest": "^25.5.1",
58
58
  "babel-preset-env": "^1.7.0",
59
59
  "eslint": "^6.8.0",
60
- "eslint-config-prettier": "^6.10.1",
60
+ "eslint-config-prettier": "^6.11.0",
61
61
  "eslint-plugin-tree-shaking": "^1.8.0",
62
- "jest": "^25.3.0",
63
- "regenerator-runtime": "^0.13.5",
62
+ "jest": "^25.5.4",
63
+ "regenerator-runtime": "^0.13.7",
64
64
  "rollup": "^1.32.1",
65
- "rollup-plugin-typescript2": "^0.26.0",
66
- "ts-node": "^8.8.2",
67
- "typescript": "^3.8.3"
65
+ "rollup-plugin-typescript2": "^0.27.1",
66
+ "tsconfig-paths": "^3.9.0",
67
+ "ts-node": "^8.10.2",
68
+ "typescript": "^3.9.7"
68
69
  },
69
70
  "ava": {
70
71
  "extensions": [
71
72
  "ts"
72
73
  ],
73
74
  "require": [
75
+ "tsconfig-paths/register",
74
76
  "ts-node/register"
75
77
  ]
76
78
  }
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
  *
@@ -92,6 +102,16 @@ export function isArray (payload: any): payload is any[] {
92
102
  return getType(payload) === 'Array'
93
103
  }
94
104
 
105
+ /**
106
+ * Returns whether the payload is a an empty array
107
+ *
108
+ * @param {*} payload
109
+ * @returns {payload is []}
110
+ */
111
+ export function isEmptyArray (payload: any): payload is [] {
112
+ return isArray(payload) && payload.length === 0
113
+ }
114
+
95
115
  /**
96
116
  * Returns whether the payload is a string
97
117
  *
@@ -254,6 +274,16 @@ export function isError (payload: any): payload is Error {
254
274
  return getType(payload) === 'Error'
255
275
  }
256
276
 
277
+ /**
278
+ * Returns whether the payload is `NaN` but also a `number`
279
+ *
280
+ * @param {*} payload
281
+ * @returns {payload is typeof NaN}
282
+ */
283
+ export function isNaNValue (payload: any): payload is typeof NaN {
284
+ return getType(payload) === 'Number' && isNaN(payload)
285
+ }
286
+
257
287
  /**
258
288
  * Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
259
289
  *
package/test/ava.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import test from 'ava'
2
2
  import {
3
3
  isError,
4
+ isEmptyArray,
4
5
  isObject,
5
6
  isPlainObject,
6
7
  isAnyObject,
@@ -26,6 +27,8 @@ import {
26
27
  // isBlob,
27
28
  // isFile,
28
29
  isPromise,
30
+ isNaNValue,
31
+ isEmptyObject,
29
32
  } from '../src/index'
30
33
 
31
34
  // const blob = Buffer.from([])
@@ -88,6 +91,74 @@ test('Basic false tests', t => {
88
91
  t.is(isNullOrUndefined(NaN), false)
89
92
  })
90
93
 
94
+ test('isEmptyObject', t => {
95
+ t.is(isEmptyObject({}), true)
96
+ t.is(isEmptyObject(new Object()), true)
97
+
98
+ t.is(isEmptyObject('{}'), false)
99
+ t.is(isEmptyObject('{}'), false)
100
+ t.is(isEmptyObject(null), false)
101
+ t.is(isEmptyObject(new Date()), false)
102
+ t.is(isEmptyObject(new Error('')), false)
103
+ t.is(isEmptyObject(new Date()), false)
104
+ t.is(isEmptyObject(Symbol()), false)
105
+ t.is(isEmptyObject(new Map()), false)
106
+ t.is(isEmptyObject(new WeakMap()), false)
107
+ t.is(isEmptyObject(new Set()), false)
108
+ t.is(isEmptyObject(new WeakSet()), false)
109
+ })
110
+
111
+ test('isEmptyArray', t => {
112
+ t.is(isEmptyArray([]), true)
113
+ t.is(isEmptyArray(new Array()), true)
114
+ t.is(isEmptyArray(new Array(0)), true)
115
+
116
+ t.is(isEmptyArray(new Array(1)), false)
117
+ t.is(isEmptyArray([undefined]), false)
118
+ t.is(isEmptyArray(null), false)
119
+ t.is(isEmptyArray(new Date()), false)
120
+ t.is(isEmptyArray(new Error('')), false)
121
+ t.is(isEmptyArray(new Date()), false)
122
+ t.is(isEmptyArray(Symbol()), false)
123
+ t.is(isEmptyArray(new Map()), false)
124
+ t.is(isEmptyArray(new WeakMap()), false)
125
+ t.is(isEmptyArray(new Set()), false)
126
+ t.is(isEmptyArray(new WeakSet()), false)
127
+ })
128
+
129
+ test('NaN tests', t => {
130
+ t.is(isNaNValue(NaN), true)
131
+ t.is(isNaNValue(new Error('')), false)
132
+ t.is(isNaNValue(undefined), false)
133
+ t.is(isNaNValue(null), false)
134
+ t.is(isNaNValue(undefined), false)
135
+ t.is(isNaNValue({}), false)
136
+ t.is(isNaNValue(new Object()), false)
137
+ t.is(
138
+ isNaNValue(_ => {}),
139
+ false
140
+ )
141
+ t.is(isNaNValue([]), false)
142
+ t.is(isNaNValue(new Array()), false)
143
+ t.is(isNaNValue(''), false)
144
+ t.is(isNaNValue('_'), false)
145
+ t.is(isNaNValue(''), false)
146
+ t.is(isNaNValue(' '), false)
147
+ t.is(isNaNValue(true), false)
148
+ t.is(isNaNValue(false), false)
149
+ t.is(isNaNValue(/./), false)
150
+ t.is(isNaNValue(/./gi), false)
151
+ t.is(isNaNValue(0), false)
152
+ t.is(isNaNValue(1), false)
153
+ t.is(isNaNValue(new Date()), false)
154
+ t.is(isNaNValue(Symbol()), false)
155
+ t.is(isNaNValue(new Map()), false)
156
+ t.is(isNaNValue(new WeakMap()), false)
157
+ t.is(isNaNValue(new Set()), false)
158
+ t.is(isNaNValue(new WeakSet()), false)
159
+ t.is(isNaNValue(new Promise((resolve, reject) => {})), false)
160
+ })
161
+
91
162
  test('Primitive tests', t => {
92
163
  // true
93
164
  t.is(isPrimitive(0), true)
package/tsconfig.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "baseUrl": ".",
3
4
  "declaration": true,
4
5
  "declarationDir": "./types/"
5
6
  },
6
7
  "include": [
7
- "src/**/*"
8
+ "src/**/*",
9
+ "test/**/*"
8
10
  ]
9
11
  }
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
  *
@@ -70,6 +77,13 @@ export declare function isFunction(payload: any): payload is Function;
70
77
  * @returns {payload is undefined}
71
78
  */
72
79
  export declare function isArray(payload: any): payload is any[];
80
+ /**
81
+ * Returns whether the payload is a an empty array
82
+ *
83
+ * @param {*} payload
84
+ * @returns {payload is []}
85
+ */
86
+ export declare function isEmptyArray(payload: any): payload is [];
73
87
  /**
74
88
  * Returns whether the payload is a string
75
89
  *
@@ -184,6 +198,13 @@ export declare function isPromise(payload: any): payload is Promise<any>;
184
198
  * @returns {payload is Error}
185
199
  */
186
200
  export declare function isError(payload: any): payload is Error;
201
+ /**
202
+ * Returns whether the payload is `NaN` but also a `number`
203
+ *
204
+ * @param {*} payload
205
+ * @returns {payload is typeof NaN}
206
+ */
207
+ export declare function isNaNValue(payload: any): payload is typeof NaN;
187
208
  /**
188
209
  * Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
189
210
  *