@xylabs/typeof 5.0.33 → 5.0.35
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/typeof",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.35",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typeof",
|
|
@@ -39,7 +39,10 @@
|
|
|
39
39
|
"types": "./dist/neutral/index.d.ts",
|
|
40
40
|
"files": [
|
|
41
41
|
"dist",
|
|
42
|
-
"src"
|
|
42
|
+
"src",
|
|
43
|
+
"!**/*.bench.*",
|
|
44
|
+
"!**/*.spec.*",
|
|
45
|
+
"!**/*.test.*"
|
|
43
46
|
],
|
|
44
47
|
"devDependencies": {
|
|
45
48
|
"@xylabs/ts-scripts-yarn3": "~7.2.8",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/is.spec.ts"],"names":[],"mappings":""}
|
package/src/spec/is.spec.ts
DELETED
|
@@ -1,608 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-lines */
|
|
2
|
-
/* eslint-disable max-statements */
|
|
3
|
-
import {
|
|
4
|
-
describe, expect, expectTypeOf,
|
|
5
|
-
it,
|
|
6
|
-
} from 'vitest'
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
isArray,
|
|
10
|
-
isArrayBufferView,
|
|
11
|
-
isBigInt,
|
|
12
|
-
isBlob,
|
|
13
|
-
isBoolean,
|
|
14
|
-
isDataView,
|
|
15
|
-
isDate,
|
|
16
|
-
isDateString,
|
|
17
|
-
isDefined,
|
|
18
|
-
isDefinedNotNull,
|
|
19
|
-
isEmpty,
|
|
20
|
-
isEmptyArray,
|
|
21
|
-
isEmptyObject,
|
|
22
|
-
isEmptyString,
|
|
23
|
-
isError,
|
|
24
|
-
isFalsy,
|
|
25
|
-
isFile,
|
|
26
|
-
isFunction,
|
|
27
|
-
isMap,
|
|
28
|
-
isNull,
|
|
29
|
-
isNumber,
|
|
30
|
-
isObject,
|
|
31
|
-
isPopulatedArray,
|
|
32
|
-
isPromise,
|
|
33
|
-
isPromiseLike,
|
|
34
|
-
isRegExp,
|
|
35
|
-
isSet,
|
|
36
|
-
isString,
|
|
37
|
-
isSymbol,
|
|
38
|
-
isTruthy,
|
|
39
|
-
isUndefined,
|
|
40
|
-
isUndefinedOrNull,
|
|
41
|
-
isWeakMap,
|
|
42
|
-
isWeakSet,
|
|
43
|
-
} from '../is.ts'
|
|
44
|
-
|
|
45
|
-
const Undefined = undefined
|
|
46
|
-
|
|
47
|
-
describe('is.ts type guards', () => {
|
|
48
|
-
describe('isUndefined', () => {
|
|
49
|
-
it('correctly identifies undefined values', () => {
|
|
50
|
-
expect(isUndefined(Undefined)).toBe(true)
|
|
51
|
-
expect(isUndefined(void 0)).toBe(true)
|
|
52
|
-
|
|
53
|
-
expect(isUndefined(null)).toBe(false)
|
|
54
|
-
expect(isUndefined(0)).toBe(false)
|
|
55
|
-
expect(isUndefined('')).toBe(false)
|
|
56
|
-
expect(isUndefined(false)).toBe(false)
|
|
57
|
-
expect(isUndefined({})).toBe(false)
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
describe('isDefined', () => {
|
|
62
|
-
it('correctly identifies defined values', () => {
|
|
63
|
-
expect(isDefined(null)).toBe(true)
|
|
64
|
-
expect(isDefined(0)).toBe(true)
|
|
65
|
-
expect(isDefined('')).toBe(true)
|
|
66
|
-
expect(isDefined(false)).toBe(true)
|
|
67
|
-
expect(isDefined({})).toBe(true)
|
|
68
|
-
|
|
69
|
-
expect(isDefined(Undefined)).toBe(false)
|
|
70
|
-
expect(isDefined(void 0)).toBe(false)
|
|
71
|
-
})
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
describe('isNull', () => {
|
|
75
|
-
it('correctly identifies null values', () => {
|
|
76
|
-
expect(isNull(null)).toBe(true)
|
|
77
|
-
|
|
78
|
-
expect(isNull(Undefined)).toBe(false)
|
|
79
|
-
expect(isNull(0)).toBe(false)
|
|
80
|
-
expect(isNull('')).toBe(false)
|
|
81
|
-
expect(isNull(false)).toBe(false)
|
|
82
|
-
expect(isNull({})).toBe(false)
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
describe('isDefinedNotNull', () => {
|
|
87
|
-
it('correctly identifies values that are neither undefined nor null', () => {
|
|
88
|
-
expect(isDefinedNotNull(0)).toBe(true)
|
|
89
|
-
expect(isDefinedNotNull('')).toBe(true)
|
|
90
|
-
expect(isDefinedNotNull(false)).toBe(true)
|
|
91
|
-
expect(isDefinedNotNull({})).toBe(true)
|
|
92
|
-
|
|
93
|
-
expect(isDefinedNotNull(Undefined)).toBe(false)
|
|
94
|
-
expect(isDefinedNotNull(null)).toBe(false)
|
|
95
|
-
})
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
describe('isUndefinedOrNull', () => {
|
|
99
|
-
it('correctly identifies undefined or null values', () => {
|
|
100
|
-
expect(isUndefinedOrNull(Undefined)).toBe(true)
|
|
101
|
-
expect(isUndefinedOrNull(null)).toBe(true)
|
|
102
|
-
|
|
103
|
-
expect(isUndefinedOrNull(0)).toBe(false)
|
|
104
|
-
expect(isUndefinedOrNull('')).toBe(false)
|
|
105
|
-
expect(isUndefinedOrNull(false)).toBe(false)
|
|
106
|
-
expect(isUndefinedOrNull({})).toBe(false)
|
|
107
|
-
})
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
describe('isBigInt', () => {
|
|
111
|
-
it('correctly identifies BigInt values', () => {
|
|
112
|
-
expect(isBigInt(123n)).toBe(true)
|
|
113
|
-
expect(isBigInt(123n)).toBe(true)
|
|
114
|
-
|
|
115
|
-
expect(isBigInt(123)).toBe(false)
|
|
116
|
-
expect(isBigInt('123')).toBe(false)
|
|
117
|
-
expect(isBigInt(null)).toBe(false)
|
|
118
|
-
expect(isBigInt(Undefined)).toBe(false)
|
|
119
|
-
})
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
describe('isString', () => {
|
|
123
|
-
it('correctly identifies string values', () => {
|
|
124
|
-
expect(isString('')).toBe(true)
|
|
125
|
-
expect(isString('hello')).toBe(true)
|
|
126
|
-
expect(isString(String('test'))).toBe(true)
|
|
127
|
-
|
|
128
|
-
expect(isString(123)).toBe(false)
|
|
129
|
-
expect(isString(null)).toBe(false)
|
|
130
|
-
expect(isString(Undefined)).toBe(false)
|
|
131
|
-
})
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
describe('isNumber', () => {
|
|
135
|
-
it('correctly identifies number values', () => {
|
|
136
|
-
expect(isNumber(0)).toBe(true)
|
|
137
|
-
expect(isNumber(123)).toBe(true)
|
|
138
|
-
expect(isNumber(-456)).toBe(true)
|
|
139
|
-
expect(isNumber(Number.NaN)).toBe(true)
|
|
140
|
-
expect(isNumber(Infinity)).toBe(true)
|
|
141
|
-
|
|
142
|
-
expect(isNumber('123')).toBe(false)
|
|
143
|
-
expect(isNumber(null)).toBe(false)
|
|
144
|
-
expect(isNumber(Undefined)).toBe(false)
|
|
145
|
-
expect(isNumber(123n)).toBe(false)
|
|
146
|
-
})
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
describe('isObject', () => {
|
|
150
|
-
it('correctly identifies object values', () => {
|
|
151
|
-
expect(isObject({})).toBe(true)
|
|
152
|
-
expect(isObject({ key: 'value' })).toBe(true)
|
|
153
|
-
expect(isObject(new Date())).toBe(true)
|
|
154
|
-
expect(isObject(new Map())).toBe(true)
|
|
155
|
-
|
|
156
|
-
expect(isObject([])).toBe(false) // Arrays are not objects for this function
|
|
157
|
-
expect(isObject(null)).toBe(false)
|
|
158
|
-
expect(isObject(Undefined)).toBe(false)
|
|
159
|
-
expect(isObject('object')).toBe(false)
|
|
160
|
-
expect(isObject(123)).toBe(false)
|
|
161
|
-
})
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
describe('isArray', () => {
|
|
165
|
-
describe('narrowing', () => {
|
|
166
|
-
const takesTuple = (_x: [number, string]): void => {}
|
|
167
|
-
const takesReadonlyTuple = (_x: readonly [1, 2]): void => {}
|
|
168
|
-
const takesNumArray = (_x: number[]): void => {}
|
|
169
|
-
const takesReadonlyNumberArray = (_x: readonly number[]): void => {}
|
|
170
|
-
|
|
171
|
-
// NOTE: We're randomly generating a value for testing purposes
|
|
172
|
-
// using Math.random() so that TypeScript can't optimize away the
|
|
173
|
-
// narrowing prematurely by knowing the type the constant is initialized to.
|
|
174
|
-
it('narrows a union with a specific tuple', () => {
|
|
175
|
-
const v: string | [number, string] = Math.random() > 0.5 ? 'x' : [1, 'y']
|
|
176
|
-
|
|
177
|
-
if (isArray(v)) {
|
|
178
|
-
// should preserve the exact tuple type, not degrade to unknown[] or []
|
|
179
|
-
expectTypeOf(v).toEqualTypeOf<[number, string]>()
|
|
180
|
-
takesTuple(v)
|
|
181
|
-
|
|
182
|
-
// access index should be allowed (would fail if v were mistakenly narrowed to [])
|
|
183
|
-
const first: number = v[0]
|
|
184
|
-
expectTypeOf(first).toEqualTypeOf<number>()
|
|
185
|
-
const second: string = v[1]
|
|
186
|
-
expectTypeOf(second).toEqualTypeOf<string>()
|
|
187
|
-
} else {
|
|
188
|
-
expectTypeOf(v).toEqualTypeOf<string>()
|
|
189
|
-
// @ts-expect-error not an array in this branch
|
|
190
|
-
takesTuple(v)
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
it('narrows a union with a readonly tuple', () => {
|
|
195
|
-
const v: number | (readonly [1, 2]) = Math.random() > 0.5 ? 42 : [1, 2] as const
|
|
196
|
-
|
|
197
|
-
if (isArray(v)) {
|
|
198
|
-
// preserve readonly tuple-ness
|
|
199
|
-
expectTypeOf(v).toEqualTypeOf<readonly [1, 2]>()
|
|
200
|
-
takesReadonlyTuple(v)
|
|
201
|
-
|
|
202
|
-
// index access must compile (would fail if narrowed to empty tuple [])
|
|
203
|
-
const first: 1 = v[0]
|
|
204
|
-
expectTypeOf(first).toEqualTypeOf<1>()
|
|
205
|
-
const second: 2 = v[1]
|
|
206
|
-
expectTypeOf(second).toEqualTypeOf<2>()
|
|
207
|
-
} else {
|
|
208
|
-
expectTypeOf(v).toEqualTypeOf<number>()
|
|
209
|
-
// @ts-expect-error not an array here
|
|
210
|
-
takesReadonlyTuple(v)
|
|
211
|
-
}
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
it('narrows to mutable array when member is number[]', () => {
|
|
215
|
-
const v: { a: 1 } | number[] = Math.random() > 0.5 ? { a: 1 } : [1, 2, 3]
|
|
216
|
-
|
|
217
|
-
if (isArray(v)) {
|
|
218
|
-
expectTypeOf(v).toEqualTypeOf<number[]>()
|
|
219
|
-
takesNumArray(v)
|
|
220
|
-
|
|
221
|
-
// element access should be number (not never)
|
|
222
|
-
const n: number = v[0]
|
|
223
|
-
expectTypeOf(n).toEqualTypeOf<number>()
|
|
224
|
-
} else {
|
|
225
|
-
expectTypeOf(v).toEqualTypeOf<{ a: 1 }>()
|
|
226
|
-
// @ts-expect-error not an array here
|
|
227
|
-
takesNumArray(v)
|
|
228
|
-
}
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
it('preserves readonly array types', () => {
|
|
232
|
-
const v: string | readonly number[]
|
|
233
|
-
= Math.random() > 0.5 ? 'nope' : [1, 2, 3] as const
|
|
234
|
-
|
|
235
|
-
if (isArray(v)) {
|
|
236
|
-
// preserve readonly array
|
|
237
|
-
expectTypeOf(v).toEqualTypeOf<readonly number[]>()
|
|
238
|
-
takesReadonlyNumberArray(v)
|
|
239
|
-
|
|
240
|
-
// element access should still be number
|
|
241
|
-
const n: number = v[0]
|
|
242
|
-
expectTypeOf(n).toEqualTypeOf<number>()
|
|
243
|
-
} else {
|
|
244
|
-
expectTypeOf(v).toEqualTypeOf<string>()
|
|
245
|
-
// @ts-expect-error not an array here
|
|
246
|
-
takesReadonlyNumberArray(v)
|
|
247
|
-
}
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
it('does not narrow non-array tuples/objects', () => {
|
|
251
|
-
const v: { x: 1 } | 'hi' = Math.random() > 0.5 ? { x: 1 } : 'hi'
|
|
252
|
-
|
|
253
|
-
if (isArray(v)) {
|
|
254
|
-
// this branch must be impossible
|
|
255
|
-
// @ts-expect-error v cannot be an array here
|
|
256
|
-
expectTypeOf(v).toEqualTypeOf<readonly unknown[]>()
|
|
257
|
-
} else {
|
|
258
|
-
// remains original union minus arrays (i.e., unchanged)
|
|
259
|
-
expectTypeOf(v).toEqualTypeOf<{ x: 1 } | 'hi'>()
|
|
260
|
-
}
|
|
261
|
-
})
|
|
262
|
-
})
|
|
263
|
-
describe('usage', () => {
|
|
264
|
-
it('correctly identifies array values', () => {
|
|
265
|
-
expect(isArray([])).toBe(true)
|
|
266
|
-
expect(isArray([1, 2, 3])).toBe(true)
|
|
267
|
-
expect(isArray(Array.from({ length: 5 }))).toBe(true)
|
|
268
|
-
|
|
269
|
-
expect(isArray({})).toBe(false)
|
|
270
|
-
expect(isArray('array')).toBe(false)
|
|
271
|
-
expect(isArray(null)).toBe(false)
|
|
272
|
-
expect(isArray(Undefined)).toBe(false)
|
|
273
|
-
})
|
|
274
|
-
})
|
|
275
|
-
})
|
|
276
|
-
|
|
277
|
-
describe('isFunction', () => {
|
|
278
|
-
it('correctly identifies function values', () => {
|
|
279
|
-
expect(isFunction(() => {})).toBe(true)
|
|
280
|
-
expect(isFunction(function () {})).toBe(true)
|
|
281
|
-
expect(isFunction(Date)).toBe(true)
|
|
282
|
-
|
|
283
|
-
expect(isFunction({})).toBe(false)
|
|
284
|
-
expect(isFunction('function')).toBe(false)
|
|
285
|
-
expect(isFunction(null)).toBe(false)
|
|
286
|
-
expect(isFunction(Undefined)).toBe(false)
|
|
287
|
-
})
|
|
288
|
-
})
|
|
289
|
-
|
|
290
|
-
describe('isSymbol', () => {
|
|
291
|
-
it('correctly identifies symbol values', () => {
|
|
292
|
-
expect(isSymbol(Symbol())).toBe(true)
|
|
293
|
-
expect(isSymbol(Symbol('test'))).toBe(true)
|
|
294
|
-
|
|
295
|
-
expect(isSymbol('symbol')).toBe(false)
|
|
296
|
-
expect(isSymbol(null)).toBe(false)
|
|
297
|
-
expect(isSymbol(Undefined)).toBe(false)
|
|
298
|
-
expect(isSymbol({})).toBe(false)
|
|
299
|
-
})
|
|
300
|
-
})
|
|
301
|
-
|
|
302
|
-
describe('isEmptyObject', () => {
|
|
303
|
-
it('correctly identifies empty object values', () => {
|
|
304
|
-
expect(isEmptyObject({})).toBe(true)
|
|
305
|
-
expect(isEmptyObject(Object.create(null))).toBe(true)
|
|
306
|
-
|
|
307
|
-
expect(isEmptyObject({ key: 'value' })).toBe(false)
|
|
308
|
-
expect(isEmptyObject([])).toBe(false)
|
|
309
|
-
expect(isEmptyObject(null)).toBe(false)
|
|
310
|
-
expect(isEmptyObject(Undefined)).toBe(false)
|
|
311
|
-
})
|
|
312
|
-
})
|
|
313
|
-
|
|
314
|
-
describe('isEmptyString', () => {
|
|
315
|
-
it('correctly identifies empty string values', () => {
|
|
316
|
-
expect(isEmptyString('')).toBe(true)
|
|
317
|
-
|
|
318
|
-
expect(isEmptyString(' ')).toBe(false)
|
|
319
|
-
expect(isEmptyString('hello')).toBe(false)
|
|
320
|
-
expect(isEmptyString(null)).toBe(false)
|
|
321
|
-
expect(isEmptyString(Undefined)).toBe(false)
|
|
322
|
-
})
|
|
323
|
-
})
|
|
324
|
-
|
|
325
|
-
describe('isEmptyArray', () => {
|
|
326
|
-
it('correctly identifies empty array values', () => {
|
|
327
|
-
expect(isEmptyArray([])).toBe(true)
|
|
328
|
-
expect(isEmptyArray([])).toBe(true)
|
|
329
|
-
|
|
330
|
-
expect(isEmptyArray([1, 2, 3])).toBe(false)
|
|
331
|
-
expect(isEmptyArray({})).toBe(false)
|
|
332
|
-
expect(isEmptyArray(null)).toBe(false)
|
|
333
|
-
expect(isEmptyArray(Undefined)).toBe(false)
|
|
334
|
-
})
|
|
335
|
-
})
|
|
336
|
-
|
|
337
|
-
describe('isPopulatedArray', () => {
|
|
338
|
-
it('correctly identifies populated array values', () => {
|
|
339
|
-
expect(isPopulatedArray([1, 2, 3])).toBe(true)
|
|
340
|
-
expect(isPopulatedArray(['test'])).toBe(true)
|
|
341
|
-
|
|
342
|
-
expect(isPopulatedArray([])).toBe(false)
|
|
343
|
-
expect(isPopulatedArray({})).toBe(false)
|
|
344
|
-
expect(isPopulatedArray(null)).toBe(false)
|
|
345
|
-
expect(isPopulatedArray(Undefined)).toBe(false)
|
|
346
|
-
})
|
|
347
|
-
})
|
|
348
|
-
|
|
349
|
-
describe('isEmpty', () => {
|
|
350
|
-
it('correctly identifies empty values', () => {
|
|
351
|
-
expect(isEmpty('')).toBe(true)
|
|
352
|
-
expect(isEmpty([])).toBe(true)
|
|
353
|
-
expect(isEmpty({})).toBe(true)
|
|
354
|
-
|
|
355
|
-
expect(isEmpty('hello')).toBe(false)
|
|
356
|
-
expect(isEmpty([1, 2])).toBe(false)
|
|
357
|
-
expect(isEmpty({ key: 'value' })).toBe(false)
|
|
358
|
-
expect(isEmpty(0)).toBe(false)
|
|
359
|
-
expect(isEmpty(null)).toBe(false)
|
|
360
|
-
expect(isEmpty(Undefined)).toBe(false)
|
|
361
|
-
})
|
|
362
|
-
})
|
|
363
|
-
|
|
364
|
-
describe('isFalsy', () => {
|
|
365
|
-
it('correctly identifies falsy values', () => {
|
|
366
|
-
expect(isFalsy(false)).toBe(true)
|
|
367
|
-
expect(isFalsy(0)).toBe(true)
|
|
368
|
-
expect(isFalsy('')).toBe(true)
|
|
369
|
-
expect(isFalsy(null)).toBe(true)
|
|
370
|
-
expect(isFalsy(Undefined)).toBe(true)
|
|
371
|
-
expect(isFalsy(Number.NaN)).toBe(true)
|
|
372
|
-
expect(isFalsy(0n)).toBe(true)
|
|
373
|
-
|
|
374
|
-
expect(isFalsy(true)).toBe(false)
|
|
375
|
-
expect(isFalsy(1)).toBe(false)
|
|
376
|
-
expect(isFalsy('hello')).toBe(false)
|
|
377
|
-
expect(isFalsy({})).toBe(false)
|
|
378
|
-
expect(isFalsy([])).toBe(false)
|
|
379
|
-
})
|
|
380
|
-
})
|
|
381
|
-
|
|
382
|
-
describe('isTruthy', () => {
|
|
383
|
-
it('correctly identifies truthy values', () => {
|
|
384
|
-
expect(isTruthy(true)).toBe(true)
|
|
385
|
-
expect(isTruthy(1)).toBe(true)
|
|
386
|
-
expect(isTruthy('hello')).toBe(true)
|
|
387
|
-
expect(isTruthy({})).toBe(true)
|
|
388
|
-
expect(isTruthy([])).toBe(true)
|
|
389
|
-
|
|
390
|
-
expect(isTruthy(false)).toBe(false)
|
|
391
|
-
expect(isTruthy(0)).toBe(false)
|
|
392
|
-
expect(isTruthy('')).toBe(false)
|
|
393
|
-
expect(isTruthy(null)).toBe(false)
|
|
394
|
-
expect(isTruthy(Undefined)).toBe(false)
|
|
395
|
-
})
|
|
396
|
-
})
|
|
397
|
-
|
|
398
|
-
describe('isBoolean', () => {
|
|
399
|
-
it('correctly identifies boolean values', () => {
|
|
400
|
-
expect(isBoolean(true)).toBe(true)
|
|
401
|
-
expect(isBoolean(false)).toBe(true)
|
|
402
|
-
expect(isBoolean(Boolean(1))).toBe(true)
|
|
403
|
-
|
|
404
|
-
expect(isBoolean(0)).toBe(false)
|
|
405
|
-
expect(isBoolean(1)).toBe(false)
|
|
406
|
-
expect(isBoolean('true')).toBe(false)
|
|
407
|
-
expect(isBoolean(null)).toBe(false)
|
|
408
|
-
expect(isBoolean(Undefined)).toBe(false)
|
|
409
|
-
})
|
|
410
|
-
})
|
|
411
|
-
|
|
412
|
-
describe('isDateString', () => {
|
|
413
|
-
it('correctly identifies date string values', () => {
|
|
414
|
-
expect(isDateString('2023-01-01')).toBe(true)
|
|
415
|
-
expect(isDateString('01/01/2023')).toBe(true)
|
|
416
|
-
expect(isDateString('January 1, 2023')).toBe(true)
|
|
417
|
-
expect(isDateString('2023-01-01T00:00:00Z')).toBe(true)
|
|
418
|
-
|
|
419
|
-
expect(isDateString('not a date')).toBe(false)
|
|
420
|
-
expect(isDateString('')).toBe(false)
|
|
421
|
-
expect(isDateString(null)).toBe(false)
|
|
422
|
-
expect(isDateString(Undefined)).toBe(false)
|
|
423
|
-
expect(isDateString(new Date())).toBe(false)
|
|
424
|
-
})
|
|
425
|
-
})
|
|
426
|
-
|
|
427
|
-
describe('isDate', () => {
|
|
428
|
-
it('correctly identifies Date objects', () => {
|
|
429
|
-
expect(isDate(new Date())).toBe(true)
|
|
430
|
-
expect(isDate(new Date(2023, 0, 1))).toBe(true)
|
|
431
|
-
|
|
432
|
-
expect(isDate('2023-01-01')).toBe(false)
|
|
433
|
-
expect(isDate(Date.now())).toBe(false)
|
|
434
|
-
expect(isDate(null)).toBe(false)
|
|
435
|
-
expect(isDate(Undefined)).toBe(false)
|
|
436
|
-
})
|
|
437
|
-
})
|
|
438
|
-
|
|
439
|
-
describe('isRegExp', () => {
|
|
440
|
-
it('correctly identifies RegExp objects', () => {
|
|
441
|
-
expect(isRegExp(/test/)).toBe(true)
|
|
442
|
-
expect(isRegExp(new RegExp('test'))).toBe(true)
|
|
443
|
-
|
|
444
|
-
expect(isRegExp('/test/')).toBe(false)
|
|
445
|
-
expect(isRegExp('test')).toBe(false)
|
|
446
|
-
expect(isRegExp(null)).toBe(false)
|
|
447
|
-
expect(isRegExp(Undefined)).toBe(false)
|
|
448
|
-
})
|
|
449
|
-
})
|
|
450
|
-
|
|
451
|
-
describe('isError', () => {
|
|
452
|
-
it('correctly identifies Error objects', () => {
|
|
453
|
-
expect(isError(new Error('Test'))).toBe(true)
|
|
454
|
-
expect(isError(new TypeError('Test'))).toBe(true)
|
|
455
|
-
expect(isError(new SyntaxError('Test'))).toBe(true)
|
|
456
|
-
|
|
457
|
-
expect(isError('error')).toBe(false)
|
|
458
|
-
expect(isError({ message: 'Error' })).toBe(false)
|
|
459
|
-
expect(isError(null)).toBe(false)
|
|
460
|
-
expect(isError(Undefined)).toBe(false)
|
|
461
|
-
})
|
|
462
|
-
})
|
|
463
|
-
|
|
464
|
-
describe('isPromise', () => {
|
|
465
|
-
it('correctly identifies Promise objects', () => {
|
|
466
|
-
expect(isPromise(Promise.resolve())).toBe(true)
|
|
467
|
-
expect(isPromise(new Promise(() => {}))).toBe(true)
|
|
468
|
-
|
|
469
|
-
// eslint-disable-next-line unicorn/no-thenable
|
|
470
|
-
expect(isPromise({ then: () => {}, catch: () => {} })).toBe(false) // Not a real Promise instance
|
|
471
|
-
expect(isPromise({})).toBe(false)
|
|
472
|
-
expect(isPromise(null)).toBe(false)
|
|
473
|
-
expect(isPromise(Undefined)).toBe(false)
|
|
474
|
-
})
|
|
475
|
-
})
|
|
476
|
-
|
|
477
|
-
describe('isPromiseLike', () => {
|
|
478
|
-
it('correctly identifies Promise-like objects', () => {
|
|
479
|
-
expect(isPromiseLike(Promise.resolve())).toBe(true)
|
|
480
|
-
expect(isPromiseLike(new Promise(() => {}))).toBe(true)
|
|
481
|
-
// eslint-disable-next-line unicorn/no-thenable
|
|
482
|
-
expect(isPromiseLike({ then: () => {} })).toBe(true) // Thenable
|
|
483
|
-
|
|
484
|
-
expect(isPromiseLike({})).toBe(false)
|
|
485
|
-
// eslint-disable-next-line unicorn/no-thenable
|
|
486
|
-
expect(isPromiseLike({ then: 5 })).toBe(false) // 'then' must be a function
|
|
487
|
-
expect(isPromiseLike(null)).toBe(false)
|
|
488
|
-
expect(isPromiseLike(Undefined)).toBe(false)
|
|
489
|
-
})
|
|
490
|
-
})
|
|
491
|
-
|
|
492
|
-
describe('isMap', () => {
|
|
493
|
-
it('correctly identifies Map objects', () => {
|
|
494
|
-
expect(isMap(new Map())).toBe(true)
|
|
495
|
-
expect(isMap(new Map([['key', 'value']]))).toBe(true)
|
|
496
|
-
|
|
497
|
-
expect(isMap({})).toBe(false)
|
|
498
|
-
expect(isMap(new Set())).toBe(false)
|
|
499
|
-
expect(isMap(null)).toBe(false)
|
|
500
|
-
expect(isMap(Undefined)).toBe(false)
|
|
501
|
-
})
|
|
502
|
-
})
|
|
503
|
-
|
|
504
|
-
describe('isArrayBufferView', () => {
|
|
505
|
-
it('correctly identifies ArrayBufferView objects', () => {
|
|
506
|
-
expect(isArrayBufferView(new Uint8Array())).toBe(true)
|
|
507
|
-
expect(isArrayBufferView(new Int32Array())).toBe(true)
|
|
508
|
-
expect(isArrayBufferView(new Float64Array())).toBe(true)
|
|
509
|
-
expect(isArrayBufferView(new DataView(new ArrayBuffer(10)))).toBe(true)
|
|
510
|
-
|
|
511
|
-
expect(isArrayBufferView(new ArrayBuffer(10))).toBe(false)
|
|
512
|
-
expect(isArrayBufferView({})).toBe(false)
|
|
513
|
-
expect(isArrayBufferView(null)).toBe(false)
|
|
514
|
-
expect(isArrayBufferView(Undefined)).toBe(false)
|
|
515
|
-
})
|
|
516
|
-
})
|
|
517
|
-
|
|
518
|
-
describe('isSet', () => {
|
|
519
|
-
it('correctly identifies Set objects', () => {
|
|
520
|
-
expect(isSet(new Set())).toBe(true)
|
|
521
|
-
expect(isSet(new Set([1, 2, 3]))).toBe(true)
|
|
522
|
-
|
|
523
|
-
expect(isSet({})).toBe(false)
|
|
524
|
-
expect(isSet(new Map())).toBe(false)
|
|
525
|
-
expect(isSet(null)).toBe(false)
|
|
526
|
-
expect(isSet(Undefined)).toBe(false)
|
|
527
|
-
})
|
|
528
|
-
})
|
|
529
|
-
|
|
530
|
-
describe('isWeakMap', () => {
|
|
531
|
-
it('correctly identifies WeakMap objects', () => {
|
|
532
|
-
expect(isWeakMap(new WeakMap())).toBe(true)
|
|
533
|
-
|
|
534
|
-
const obj = {}
|
|
535
|
-
const wm = new WeakMap([[obj, 'value']])
|
|
536
|
-
expect(isWeakMap(wm)).toBe(true)
|
|
537
|
-
|
|
538
|
-
expect(isWeakMap(new Map())).toBe(false)
|
|
539
|
-
expect(isWeakMap({})).toBe(false)
|
|
540
|
-
expect(isWeakMap(null)).toBe(false)
|
|
541
|
-
expect(isWeakMap(Undefined)).toBe(false)
|
|
542
|
-
})
|
|
543
|
-
})
|
|
544
|
-
|
|
545
|
-
describe('isWeakSet', () => {
|
|
546
|
-
it('correctly identifies WeakSet objects', () => {
|
|
547
|
-
expect(isWeakSet(new WeakSet())).toBe(true)
|
|
548
|
-
|
|
549
|
-
const obj = {}
|
|
550
|
-
const ws = new WeakSet([obj])
|
|
551
|
-
expect(isWeakSet(ws)).toBe(true)
|
|
552
|
-
|
|
553
|
-
expect(isWeakSet(new Set())).toBe(false)
|
|
554
|
-
expect(isWeakSet({})).toBe(false)
|
|
555
|
-
expect(isWeakSet(null)).toBe(false)
|
|
556
|
-
expect(isWeakSet(Undefined)).toBe(false)
|
|
557
|
-
})
|
|
558
|
-
})
|
|
559
|
-
|
|
560
|
-
describe('isDataView', () => {
|
|
561
|
-
it('correctly identifies DataView objects', () => {
|
|
562
|
-
const buffer = new ArrayBuffer(10)
|
|
563
|
-
expect(isDataView(new DataView(buffer))).toBe(true)
|
|
564
|
-
|
|
565
|
-
expect(isDataView(buffer)).toBe(false)
|
|
566
|
-
expect(isDataView(new Uint8Array(buffer))).toBe(false)
|
|
567
|
-
expect(isDataView({})).toBe(false)
|
|
568
|
-
expect(isDataView(null)).toBe(false)
|
|
569
|
-
expect(isDataView(Undefined)).toBe(false)
|
|
570
|
-
})
|
|
571
|
-
})
|
|
572
|
-
|
|
573
|
-
describe('isBlob', () => {
|
|
574
|
-
it('correctly identifies Blob objects', () => {
|
|
575
|
-
// In a browser environment:
|
|
576
|
-
if (typeof Blob === 'undefined') {
|
|
577
|
-
// In Node.js without Blob:
|
|
578
|
-
expect(isBlob({})).toBe(false)
|
|
579
|
-
expect(isBlob(null)).toBe(false)
|
|
580
|
-
expect(isBlob(Undefined)).toBe(false)
|
|
581
|
-
} else {
|
|
582
|
-
expect(isBlob(new Blob(['content']))).toBe(true)
|
|
583
|
-
|
|
584
|
-
expect(isBlob({})).toBe(false)
|
|
585
|
-
expect(isBlob(null)).toBe(false)
|
|
586
|
-
expect(isBlob(Undefined)).toBe(false)
|
|
587
|
-
}
|
|
588
|
-
})
|
|
589
|
-
})
|
|
590
|
-
|
|
591
|
-
describe('isFile', () => {
|
|
592
|
-
it('correctly identifies File objects', () => {
|
|
593
|
-
// In a browser environment:
|
|
594
|
-
if (typeof File === 'undefined') {
|
|
595
|
-
// In Node.js without File:
|
|
596
|
-
expect(isFile({})).toBe(false)
|
|
597
|
-
expect(isFile(null)).toBe(false)
|
|
598
|
-
expect(isFile(Undefined)).toBe(false)
|
|
599
|
-
} else {
|
|
600
|
-
expect(isFile(new File(['content'], 'filename.txt'))).toBe(true)
|
|
601
|
-
|
|
602
|
-
expect(isFile({})).toBe(false)
|
|
603
|
-
expect(isFile(null)).toBe(false)
|
|
604
|
-
expect(isFile(Undefined)).toBe(false)
|
|
605
|
-
}
|
|
606
|
-
})
|
|
607
|
-
})
|
|
608
|
-
})
|