is-what 4.1.0 → 4.1.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -0
- package/dist/index.cjs +382 -0
- package/dist/{index.js → index.es.js} +0 -0
- package/{types → dist/types}/index.d.ts +0 -0
- package/package.json +38 -33
- package/.babelrc +0 -3
- package/.eslintignore +0 -9
- package/.github/FUNDING.yml +0 -12
- package/.prettierrc +0 -9
- package/.vscode/settings.json +0 -9
- package/build.js +0 -40
- package/src/index.ts +0 -415
- package/test/ava.ts +0 -419
- package/tsconfig.json +0 -15
package/test/ava.ts
DELETED
@@ -1,419 +0,0 @@
|
|
1
|
-
import test from 'ava'
|
2
|
-
|
3
|
-
import {
|
4
|
-
isError,
|
5
|
-
isEmptyArray,
|
6
|
-
isObject,
|
7
|
-
isPlainObject,
|
8
|
-
isAnyObject,
|
9
|
-
isUndefined,
|
10
|
-
isNull,
|
11
|
-
isNullOrUndefined,
|
12
|
-
isFunction,
|
13
|
-
isArray,
|
14
|
-
isString,
|
15
|
-
isEmptyString,
|
16
|
-
isFullString,
|
17
|
-
isBoolean,
|
18
|
-
isRegExp,
|
19
|
-
isNumber,
|
20
|
-
isPositiveNumber,
|
21
|
-
isNegativeNumber,
|
22
|
-
isDate,
|
23
|
-
isSymbol,
|
24
|
-
isPrimitive,
|
25
|
-
isType,
|
26
|
-
isMap,
|
27
|
-
isWeakMap,
|
28
|
-
isSet,
|
29
|
-
isWeakSet,
|
30
|
-
isFullArray,
|
31
|
-
// isBlob,
|
32
|
-
// isFile,
|
33
|
-
isPromise,
|
34
|
-
isNaNValue,
|
35
|
-
isEmptyObject,
|
36
|
-
isOneOf,
|
37
|
-
isFullObject,
|
38
|
-
} from '../src/index.js'
|
39
|
-
|
40
|
-
// TODO: test isBlob
|
41
|
-
// test('isBlob', () => {
|
42
|
-
// expect(isBlob(Blob)).toBe(false)
|
43
|
-
// expect(isBlob(new Blob())).toBe(true)
|
44
|
-
// })
|
45
|
-
|
46
|
-
// TODO: test isFile
|
47
|
-
// test('isFile', () => {
|
48
|
-
// expect(isFile(File)).toBe(false)
|
49
|
-
// expect(isFile(new File([''], '', { type: 'text/html' }))).toBe(true)
|
50
|
-
// })
|
51
|
-
|
52
|
-
test('Basic true tests', (t: any) => {
|
53
|
-
t.is(isError(new Error('')), true)
|
54
|
-
t.is(isUndefined(undefined), true)
|
55
|
-
t.is(isNull(null), true)
|
56
|
-
t.is(isNullOrUndefined(null), true)
|
57
|
-
t.is(isNullOrUndefined(undefined), true)
|
58
|
-
t.is(isObject({}), true)
|
59
|
-
t.is(isEmptyObject({}), true)
|
60
|
-
t.is(isFullObject({ 0: '' }), true)
|
61
|
-
t.is(isFullObject({ '': '' }), true)
|
62
|
-
t.is(isObject(new Object()), true)
|
63
|
-
t.is(isArray([]), true)
|
64
|
-
t.is(isEmptyArray([]), true)
|
65
|
-
t.is(isFullArray(['']), true)
|
66
|
-
t.is(isArray(new Array()), true)
|
67
|
-
t.is(isString(''), true)
|
68
|
-
t.is(isString('_'), true)
|
69
|
-
t.is(isEmptyString(''), true)
|
70
|
-
t.is(isFullString(' '), true)
|
71
|
-
t.is(isBoolean(true), true)
|
72
|
-
t.is(isBoolean(false), true)
|
73
|
-
t.is(isRegExp(/./), true)
|
74
|
-
t.is(isRegExp(/./gi), true)
|
75
|
-
t.is(isNumber(0), true)
|
76
|
-
t.is(isNumber(1), true)
|
77
|
-
t.is(isDate(new Date()), true)
|
78
|
-
t.is(isSymbol(Symbol()), true)
|
79
|
-
t.is(isMap(new Map()), true)
|
80
|
-
t.is(isWeakMap(new WeakMap()), true)
|
81
|
-
t.is(isSet(new Set()), true)
|
82
|
-
t.is(isWeakSet(new WeakSet()), true)
|
83
|
-
// t.is(isBlob(blob), true)
|
84
|
-
// t.is(isFile(new File([''], '', { type: 'text/html' })), true)
|
85
|
-
t.is(isPromise(new Promise((resolve, reject) => {})), true)
|
86
|
-
})
|
87
|
-
|
88
|
-
test('Basic false tests', (t: any) => {
|
89
|
-
t.is(isError({}), false)
|
90
|
-
t.is(isNumber(NaN), false)
|
91
|
-
t.is(isDate(new Date('_')), false)
|
92
|
-
t.is(isDate(NaN), false)
|
93
|
-
t.is(isUndefined(NaN), false)
|
94
|
-
t.is(isNull(NaN), false)
|
95
|
-
t.is(isObject(NaN), false)
|
96
|
-
t.is(isArray(NaN), false)
|
97
|
-
t.is(isString(NaN), false)
|
98
|
-
t.is(isEmptyString(' '), false)
|
99
|
-
t.is(isFullString(''), false)
|
100
|
-
t.is(isBoolean(NaN), false)
|
101
|
-
t.is(isRegExp(NaN), false)
|
102
|
-
t.is(isSymbol(NaN), false)
|
103
|
-
t.is(isMap(new WeakMap()), false)
|
104
|
-
t.is(isWeakMap(new Map()), false)
|
105
|
-
t.is(isSet(new WeakSet()), false)
|
106
|
-
t.is(isWeakSet(new Set()), false)
|
107
|
-
t.is(isNullOrUndefined(NaN), false)
|
108
|
-
})
|
109
|
-
|
110
|
-
test('isFunction', (t: any) => {
|
111
|
-
t.is(isFunction(NaN), false)
|
112
|
-
t.is(
|
113
|
-
isFunction(() => {}),
|
114
|
-
true
|
115
|
-
)
|
116
|
-
t.is(
|
117
|
-
isFunction(function () {}),
|
118
|
-
true
|
119
|
-
)
|
120
|
-
t.is(
|
121
|
-
isFunction(async () => {}),
|
122
|
-
true
|
123
|
-
)
|
124
|
-
t.is(
|
125
|
-
isFunction(async function () {}),
|
126
|
-
true
|
127
|
-
)
|
128
|
-
t.is(
|
129
|
-
isFunction(function* () {}),
|
130
|
-
true
|
131
|
-
)
|
132
|
-
t.is(
|
133
|
-
isFunction(async function* () {}),
|
134
|
-
true
|
135
|
-
)
|
136
|
-
const _ = { fn: () => {}, method() {} }
|
137
|
-
t.is(isFunction(_.fn), true)
|
138
|
-
t.is(isFunction(_.method), true)
|
139
|
-
})
|
140
|
-
|
141
|
-
test('isEmptyObject', (t: any) => {
|
142
|
-
t.is(isEmptyObject({}), true)
|
143
|
-
t.is(isEmptyObject(new Object()), true)
|
144
|
-
|
145
|
-
t.is(isEmptyObject('{}'), false)
|
146
|
-
t.is(isEmptyObject('{}'), false)
|
147
|
-
t.is(isEmptyObject(null), false)
|
148
|
-
t.is(isEmptyObject(new Date()), false)
|
149
|
-
t.is(isEmptyObject(new Error('')), false)
|
150
|
-
t.is(isEmptyObject(new Date()), false)
|
151
|
-
t.is(isEmptyObject(Symbol()), false)
|
152
|
-
t.is(isEmptyObject(new Map()), false)
|
153
|
-
t.is(isEmptyObject(new WeakMap()), false)
|
154
|
-
t.is(isEmptyObject(new Set()), false)
|
155
|
-
t.is(isEmptyObject(new WeakSet()), false)
|
156
|
-
})
|
157
|
-
|
158
|
-
test('isEmptyArray', (t: any) => {
|
159
|
-
t.is(isEmptyArray([]), true)
|
160
|
-
t.is(isEmptyArray(new Array()), true)
|
161
|
-
t.is(isEmptyArray(new Array(0)), true)
|
162
|
-
|
163
|
-
t.is(isEmptyArray(new Array(1)), false)
|
164
|
-
t.is(isEmptyArray([undefined]), false)
|
165
|
-
t.is(isEmptyArray(null), false)
|
166
|
-
t.is(isEmptyArray(new Date()), false)
|
167
|
-
t.is(isEmptyArray(new Error('')), false)
|
168
|
-
t.is(isEmptyArray(new Date()), false)
|
169
|
-
t.is(isEmptyArray(Symbol()), false)
|
170
|
-
t.is(isEmptyArray(new Map()), false)
|
171
|
-
t.is(isEmptyArray(new WeakMap()), false)
|
172
|
-
t.is(isEmptyArray(new Set()), false)
|
173
|
-
t.is(isEmptyArray(new WeakSet()), false)
|
174
|
-
})
|
175
|
-
|
176
|
-
test('isFullArray', (t: any) => {
|
177
|
-
t.is(isFullArray(new Array(1)), true)
|
178
|
-
t.is(isFullArray([undefined]), true)
|
179
|
-
t.is(isFullArray([null]), true)
|
180
|
-
t.is(isFullArray(['']), true)
|
181
|
-
|
182
|
-
t.is(isFullArray([]), false)
|
183
|
-
t.is(isFullArray(new Array()), false)
|
184
|
-
t.is(isFullArray(new Array(0)), false)
|
185
|
-
|
186
|
-
t.is(isFullArray(null), false)
|
187
|
-
t.is(isFullArray(new Date()), false)
|
188
|
-
t.is(isFullArray(new Error('')), false)
|
189
|
-
t.is(isFullArray(new Date()), false)
|
190
|
-
t.is(isFullArray(Symbol()), false)
|
191
|
-
t.is(isFullArray(new Map()), false)
|
192
|
-
t.is(isFullArray(new WeakMap()), false)
|
193
|
-
t.is(isFullArray(new Set()), false)
|
194
|
-
t.is(isFullArray(new WeakSet()), false)
|
195
|
-
})
|
196
|
-
|
197
|
-
test('isPositiveNumber / isNegativeNumber', (t: any) => {
|
198
|
-
t.is(isPositiveNumber(-1), false)
|
199
|
-
t.is(isPositiveNumber(0), false)
|
200
|
-
t.is(isPositiveNumber(1), true)
|
201
|
-
t.is(isNegativeNumber(-1), true)
|
202
|
-
t.is(isNegativeNumber(0), false)
|
203
|
-
t.is(isNegativeNumber(1), false)
|
204
|
-
})
|
205
|
-
|
206
|
-
test('NaN tests', (t: any) => {
|
207
|
-
t.is(isNaNValue(NaN), true)
|
208
|
-
t.is(isNaNValue(new Error('')), false)
|
209
|
-
t.is(isNaNValue(undefined), false)
|
210
|
-
t.is(isNaNValue(null), false)
|
211
|
-
t.is(isNaNValue(undefined), false)
|
212
|
-
t.is(isNaNValue({}), false)
|
213
|
-
t.is(isNaNValue(new Object()), false)
|
214
|
-
t.is(
|
215
|
-
isNaNValue(() => {}),
|
216
|
-
false
|
217
|
-
)
|
218
|
-
t.is(isNaNValue([]), false)
|
219
|
-
t.is(isNaNValue(new Array()), false)
|
220
|
-
t.is(isNaNValue(''), false)
|
221
|
-
t.is(isNaNValue('_'), false)
|
222
|
-
t.is(isNaNValue(''), false)
|
223
|
-
t.is(isNaNValue(' '), false)
|
224
|
-
t.is(isNaNValue(true), false)
|
225
|
-
t.is(isNaNValue(false), false)
|
226
|
-
t.is(isNaNValue(/./), false)
|
227
|
-
t.is(isNaNValue(/./gi), false)
|
228
|
-
t.is(isNaNValue(0), false)
|
229
|
-
t.is(isNaNValue(1), false)
|
230
|
-
t.is(isNaNValue(new Date()), false)
|
231
|
-
t.is(isNaNValue(Symbol()), false)
|
232
|
-
t.is(isNaNValue(new Map()), false)
|
233
|
-
t.is(isNaNValue(new WeakMap()), false)
|
234
|
-
t.is(isNaNValue(new Set()), false)
|
235
|
-
t.is(isNaNValue(new WeakSet()), false)
|
236
|
-
t.is(isNaNValue(new Promise((resolve, reject) => {})), false)
|
237
|
-
})
|
238
|
-
|
239
|
-
test('Primitive tests', (t: any) => {
|
240
|
-
// true
|
241
|
-
t.is(isPrimitive(0), true)
|
242
|
-
t.is(isPrimitive(''), true)
|
243
|
-
t.is(isPrimitive('str'), true)
|
244
|
-
t.is(isPrimitive(Symbol()), true)
|
245
|
-
t.is(isPrimitive(true), true)
|
246
|
-
t.is(isPrimitive(false), true)
|
247
|
-
t.is(isPrimitive(null), true)
|
248
|
-
t.is(isPrimitive(undefined), true)
|
249
|
-
// false
|
250
|
-
t.is(isPrimitive(NaN), false)
|
251
|
-
t.is(isPrimitive([]), false)
|
252
|
-
t.is(isPrimitive(new Array()), false)
|
253
|
-
t.is(isPrimitive({}), false)
|
254
|
-
t.is(isPrimitive(new Object()), false)
|
255
|
-
t.is(isPrimitive(new Date()), false)
|
256
|
-
t.is(
|
257
|
-
isPrimitive(() => {}),
|
258
|
-
false
|
259
|
-
)
|
260
|
-
})
|
261
|
-
|
262
|
-
test('Date exception', (t: any) => {
|
263
|
-
t.is(isDate(new Date('_')), false)
|
264
|
-
})
|
265
|
-
|
266
|
-
test('Generic isType', (t: any) => {
|
267
|
-
// -----------------------------
|
268
|
-
// This is correct old fashion syntax for classes, if this is missing
|
269
|
-
function MyClass() {}
|
270
|
-
MyClass.prototype.constructor = MyClass
|
271
|
-
// @ts-ignore
|
272
|
-
const myClass = new MyClass()
|
273
|
-
// -----------------------------
|
274
|
-
class MyOtherClass {
|
275
|
-
constructor() {}
|
276
|
-
}
|
277
|
-
// this is expected behaviour
|
278
|
-
t.is(isType('', String), true)
|
279
|
-
t.is(isType('_', String), true)
|
280
|
-
t.is(isType('Hello World', String), true)
|
281
|
-
t.is(isType(NaN, Number), true)
|
282
|
-
t.is(isType(0, Number), true)
|
283
|
-
t.is(isType(1, Number), true)
|
284
|
-
t.is(isType({}, Object), true)
|
285
|
-
t.is(isType(new Object(), Object), true)
|
286
|
-
t.is(isType([], Array), true)
|
287
|
-
t.is(isType(new Array(), Array), true)
|
288
|
-
t.is(
|
289
|
-
isType(() => {}, Function),
|
290
|
-
true
|
291
|
-
)
|
292
|
-
t.is(isType(true, Boolean), true)
|
293
|
-
t.is(isType(false, Boolean), true)
|
294
|
-
t.is(isType(new Date('_'), Date), true)
|
295
|
-
t.is(isType(new Date(), Date), true)
|
296
|
-
t.is(isType(/./, RegExp), true)
|
297
|
-
t.is(isType(/./gi, RegExp), true)
|
298
|
-
t.is(isType(myClass, MyClass), true)
|
299
|
-
t.is(isType(new MyOtherClass(), MyOtherClass), true)
|
300
|
-
t.is(isType(myClass, MyOtherClass), false)
|
301
|
-
t.is(isType(Symbol(), Symbol), true)
|
302
|
-
// t.is(isType(null, Null), true)
|
303
|
-
// t.is(isType(undefined, Undefined), true)
|
304
|
-
// It SHOULD fail
|
305
|
-
t.is(isType(5, String), false)
|
306
|
-
t.is(isType(null, Object), false)
|
307
|
-
// Not sure if this would be the expected behaviour but everything is an object
|
308
|
-
// so I would say so
|
309
|
-
t.is(isType(myClass, Object), true)
|
310
|
-
})
|
311
|
-
|
312
|
-
test('isObject vs isAnyObject', (t: any) => {
|
313
|
-
// -----------------------------
|
314
|
-
// This is correct old fashion syntax for classes, if this is missing
|
315
|
-
function MyClass() {}
|
316
|
-
MyClass.prototype.constructor = MyClass
|
317
|
-
// @ts-ignore
|
318
|
-
const myClass = new MyClass()
|
319
|
-
// -----------------------------
|
320
|
-
class MyClass2 {
|
321
|
-
constructor() {}
|
322
|
-
}
|
323
|
-
const myClass2 = new MyClass2()
|
324
|
-
const mySpecialObject = {}
|
325
|
-
Object.setPrototypeOf(mySpecialObject, {
|
326
|
-
toDate: function () {
|
327
|
-
return new Date()
|
328
|
-
},
|
329
|
-
})
|
330
|
-
// IS OBJECT
|
331
|
-
// plain object
|
332
|
-
t.is(isObject({}), true)
|
333
|
-
t.is(isObject(new Object()), true)
|
334
|
-
t.is(isPlainObject({}), true)
|
335
|
-
t.is(isPlainObject(new Object()), true)
|
336
|
-
// classes & prototypes
|
337
|
-
t.is(isObject(myClass), false)
|
338
|
-
t.is(isObject(myClass2), false)
|
339
|
-
t.is(isObject(mySpecialObject), false)
|
340
|
-
t.is(isPlainObject(myClass), false)
|
341
|
-
t.is(isPlainObject(myClass2), false)
|
342
|
-
t.is(isPlainObject(mySpecialObject), false)
|
343
|
-
// arrays and dates
|
344
|
-
t.is(isObject([]), false)
|
345
|
-
t.is(isObject(new Array()), false)
|
346
|
-
t.is(isObject(new Date('_')), false)
|
347
|
-
t.is(isObject(new Date()), false)
|
348
|
-
t.is(isPlainObject([]), false)
|
349
|
-
t.is(isPlainObject(new Array()), false)
|
350
|
-
t.is(isPlainObject(new Date('_')), false)
|
351
|
-
t.is(isPlainObject(new Date()), false)
|
352
|
-
// IS ANY OBJECT
|
353
|
-
// plain object
|
354
|
-
t.is(isAnyObject({}), true)
|
355
|
-
t.is(isAnyObject(new Object()), true)
|
356
|
-
// classes & prototypes
|
357
|
-
t.is(isAnyObject(myClass), true)
|
358
|
-
t.is(isAnyObject(myClass2), true)
|
359
|
-
t.is(isAnyObject(mySpecialObject), true)
|
360
|
-
// arrays and dates
|
361
|
-
t.is(isAnyObject([]), false)
|
362
|
-
t.is(isAnyObject(new Array()), false)
|
363
|
-
t.is(isAnyObject(new Date('_')), false)
|
364
|
-
t.is(isAnyObject(new Date()), false)
|
365
|
-
})
|
366
|
-
|
367
|
-
test('isOneOf', (t: any) => {
|
368
|
-
t.is(isOneOf(isString, isNumber)('_'), true)
|
369
|
-
t.is(isOneOf(isString, isNumber)(1), true)
|
370
|
-
t.is(isOneOf(isString, isNumber)(undefined), false)
|
371
|
-
|
372
|
-
t.is(isOneOf(isString, isNumber, isBoolean)('_'), true)
|
373
|
-
t.is(isOneOf(isString, isNumber, isBoolean)(1), true)
|
374
|
-
t.is(isOneOf(isString, isNumber, isBoolean)(true), true)
|
375
|
-
t.is(isOneOf(isString, isNumber, isBoolean)(undefined), false)
|
376
|
-
|
377
|
-
t.is(isOneOf(isString, isNumber, isBoolean, isArray)('_'), true)
|
378
|
-
t.is(isOneOf(isString, isNumber, isBoolean, isArray)(1), true)
|
379
|
-
t.is(isOneOf(isString, isNumber, isBoolean, isArray)(true), true)
|
380
|
-
t.is(isOneOf(isString, isNumber, isBoolean, isArray)([]), true)
|
381
|
-
t.is(isOneOf(isString, isNumber, isBoolean, isArray)(undefined), false)
|
382
|
-
|
383
|
-
t.is(isOneOf(isString, isNumber, isBoolean, isArray, isPlainObject)('_'), true)
|
384
|
-
t.is(isOneOf(isString, isNumber, isBoolean, isArray, isPlainObject)(1), true)
|
385
|
-
t.is(isOneOf(isString, isNumber, isBoolean, isArray, isPlainObject)(true), true)
|
386
|
-
t.is(isOneOf(isString, isNumber, isBoolean, isArray, isPlainObject)([]), true)
|
387
|
-
t.is(isOneOf(isString, isNumber, isBoolean, isArray, isPlainObject)({}), true)
|
388
|
-
t.is(isOneOf(isString, isNumber, isBoolean, isArray, isPlainObject)(undefined), false)
|
389
|
-
})
|
390
|
-
|
391
|
-
test('type related tests', (t: any) => {
|
392
|
-
t.pass()
|
393
|
-
// const fn: string | ((k: number) => string) = (p) => 'a'
|
394
|
-
// if (!isFunction(fn)) {
|
395
|
-
// fn
|
396
|
-
// }
|
397
|
-
|
398
|
-
// const a: Record<string, number> = {}
|
399
|
-
|
400
|
-
// a[fn(1)] = fn(2)
|
401
|
-
|
402
|
-
// const myArray: string | string[] = ['a', 'b']
|
403
|
-
// if (!isArray(myArray)) {
|
404
|
-
// myArray
|
405
|
-
// }
|
406
|
-
|
407
|
-
// const a: Record<string, number> = {}
|
408
|
-
|
409
|
-
// a[myArray[1]] = myArray[0]
|
410
|
-
|
411
|
-
// const myArray: string | any[] = [1, 2, 'a', 'b']
|
412
|
-
// if (!isArray(myArray)) {
|
413
|
-
// myArray
|
414
|
-
// }
|
415
|
-
|
416
|
-
// const a: Record<string, number> = {}
|
417
|
-
|
418
|
-
// a[myArray[1]] = myArray[0]
|
419
|
-
})
|
package/tsconfig.json
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"baseUrl": ".",
|
4
|
-
"module": "ES2020",
|
5
|
-
"target": "ES2019",
|
6
|
-
"lib": ["ES2020", "DOM"],
|
7
|
-
"strict": true,
|
8
|
-
"moduleResolution": "node",
|
9
|
-
"isolatedModules": true,
|
10
|
-
"esModuleInterop": true,
|
11
|
-
"declaration": true,
|
12
|
-
"declarationDir": "./types/"
|
13
|
-
},
|
14
|
-
"include": ["src/**/*", "test/**/*"]
|
15
|
-
}
|