@xylabs/typeof 4.13.19 → 4.13.20
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/README.md +1 -1
- package/package.json +11 -5
- package/src/spec/is.spec.ts +520 -0
- package/typedoc.json +0 -4
- package/xy.config.ts +0 -10
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/typeof",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.20",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typeof",
|
|
@@ -29,15 +29,21 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
31
|
"types": "./dist/neutral/index.d.ts",
|
|
32
|
+
"source": "./src/index.ts",
|
|
32
33
|
"default": "./dist/neutral/index.mjs"
|
|
33
34
|
},
|
|
34
35
|
"./package.json": "./package.json"
|
|
35
36
|
},
|
|
36
|
-
"module": "dist/neutral/index.mjs",
|
|
37
|
-
"
|
|
37
|
+
"module": "./dist/neutral/index.mjs",
|
|
38
|
+
"source": "./src/index.ts",
|
|
39
|
+
"types": "./dist/neutral/index.d.ts",
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"src"
|
|
43
|
+
],
|
|
38
44
|
"devDependencies": {
|
|
39
|
-
"@xylabs/ts-scripts-yarn3": "^7.0.0
|
|
40
|
-
"@xylabs/tsconfig": "^7.0.0
|
|
45
|
+
"@xylabs/ts-scripts-yarn3": "^7.0.0",
|
|
46
|
+
"@xylabs/tsconfig": "^7.0.0",
|
|
41
47
|
"typescript": "^5.8.3",
|
|
42
48
|
"vitest": "^3.2.4"
|
|
43
49
|
},
|
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
2
|
+
import {
|
|
3
|
+
describe, expect, it,
|
|
4
|
+
} from 'vitest'
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
isArray,
|
|
8
|
+
isArrayBuffer,
|
|
9
|
+
isArrayBufferView,
|
|
10
|
+
isBigInt,
|
|
11
|
+
isBlob,
|
|
12
|
+
isBoolean,
|
|
13
|
+
isDataView,
|
|
14
|
+
isDate,
|
|
15
|
+
isDateString,
|
|
16
|
+
isDefined,
|
|
17
|
+
isDefinedNotNull,
|
|
18
|
+
isEmpty,
|
|
19
|
+
isEmptyArray,
|
|
20
|
+
isEmptyObject,
|
|
21
|
+
isEmptyString,
|
|
22
|
+
isError,
|
|
23
|
+
isFalsy,
|
|
24
|
+
isFile,
|
|
25
|
+
isFunction,
|
|
26
|
+
isMap,
|
|
27
|
+
isNull,
|
|
28
|
+
isNumber,
|
|
29
|
+
isObject,
|
|
30
|
+
isPopulatedArray,
|
|
31
|
+
isPromise,
|
|
32
|
+
isPromiseLike,
|
|
33
|
+
isRegExp,
|
|
34
|
+
isSet,
|
|
35
|
+
isString,
|
|
36
|
+
isSymbol,
|
|
37
|
+
isTruthy,
|
|
38
|
+
isUndefined,
|
|
39
|
+
isUndefinedOrNull,
|
|
40
|
+
isWeakMap,
|
|
41
|
+
isWeakSet,
|
|
42
|
+
} from '../is.ts'
|
|
43
|
+
|
|
44
|
+
const Undefined = undefined
|
|
45
|
+
|
|
46
|
+
describe('is.ts type guards', () => {
|
|
47
|
+
describe('isUndefined', () => {
|
|
48
|
+
it('correctly identifies undefined values', () => {
|
|
49
|
+
expect(isUndefined(Undefined)).toBe(true)
|
|
50
|
+
expect(isUndefined(void 0)).toBe(true)
|
|
51
|
+
|
|
52
|
+
expect(isUndefined(null)).toBe(false)
|
|
53
|
+
expect(isUndefined(0)).toBe(false)
|
|
54
|
+
expect(isUndefined('')).toBe(false)
|
|
55
|
+
expect(isUndefined(false)).toBe(false)
|
|
56
|
+
expect(isUndefined({})).toBe(false)
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
describe('isDefined', () => {
|
|
61
|
+
it('correctly identifies defined values', () => {
|
|
62
|
+
expect(isDefined(null)).toBe(true)
|
|
63
|
+
expect(isDefined(0)).toBe(true)
|
|
64
|
+
expect(isDefined('')).toBe(true)
|
|
65
|
+
expect(isDefined(false)).toBe(true)
|
|
66
|
+
expect(isDefined({})).toBe(true)
|
|
67
|
+
|
|
68
|
+
expect(isDefined(Undefined)).toBe(false)
|
|
69
|
+
expect(isDefined(void 0)).toBe(false)
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe('isNull', () => {
|
|
74
|
+
it('correctly identifies null values', () => {
|
|
75
|
+
expect(isNull(null)).toBe(true)
|
|
76
|
+
|
|
77
|
+
expect(isNull(Undefined)).toBe(false)
|
|
78
|
+
expect(isNull(0)).toBe(false)
|
|
79
|
+
expect(isNull('')).toBe(false)
|
|
80
|
+
expect(isNull(false)).toBe(false)
|
|
81
|
+
expect(isNull({})).toBe(false)
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
describe('isDefinedNotNull', () => {
|
|
86
|
+
it('correctly identifies values that are neither undefined nor null', () => {
|
|
87
|
+
expect(isDefinedNotNull(0)).toBe(true)
|
|
88
|
+
expect(isDefinedNotNull('')).toBe(true)
|
|
89
|
+
expect(isDefinedNotNull(false)).toBe(true)
|
|
90
|
+
expect(isDefinedNotNull({})).toBe(true)
|
|
91
|
+
|
|
92
|
+
expect(isDefinedNotNull(Undefined)).toBe(false)
|
|
93
|
+
expect(isDefinedNotNull(null)).toBe(false)
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
describe('isUndefinedOrNull', () => {
|
|
98
|
+
it('correctly identifies undefined or null values', () => {
|
|
99
|
+
expect(isUndefinedOrNull(Undefined)).toBe(true)
|
|
100
|
+
expect(isUndefinedOrNull(null)).toBe(true)
|
|
101
|
+
|
|
102
|
+
expect(isUndefinedOrNull(0)).toBe(false)
|
|
103
|
+
expect(isUndefinedOrNull('')).toBe(false)
|
|
104
|
+
expect(isUndefinedOrNull(false)).toBe(false)
|
|
105
|
+
expect(isUndefinedOrNull({})).toBe(false)
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
describe('isBigInt', () => {
|
|
110
|
+
it('correctly identifies BigInt values', () => {
|
|
111
|
+
expect(isBigInt(BigInt(123))).toBe(true)
|
|
112
|
+
expect(isBigInt(123n)).toBe(true)
|
|
113
|
+
|
|
114
|
+
expect(isBigInt(123)).toBe(false)
|
|
115
|
+
expect(isBigInt('123')).toBe(false)
|
|
116
|
+
expect(isBigInt(null)).toBe(false)
|
|
117
|
+
expect(isBigInt(Undefined)).toBe(false)
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
describe('isString', () => {
|
|
122
|
+
it('correctly identifies string values', () => {
|
|
123
|
+
expect(isString('')).toBe(true)
|
|
124
|
+
expect(isString('hello')).toBe(true)
|
|
125
|
+
expect(isString(String('test'))).toBe(true)
|
|
126
|
+
|
|
127
|
+
expect(isString(123)).toBe(false)
|
|
128
|
+
expect(isString(null)).toBe(false)
|
|
129
|
+
expect(isString(Undefined)).toBe(false)
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
describe('isNumber', () => {
|
|
134
|
+
it('correctly identifies number values', () => {
|
|
135
|
+
expect(isNumber(0)).toBe(true)
|
|
136
|
+
expect(isNumber(123)).toBe(true)
|
|
137
|
+
expect(isNumber(-456)).toBe(true)
|
|
138
|
+
expect(isNumber(Number.NaN)).toBe(true)
|
|
139
|
+
expect(isNumber(Infinity)).toBe(true)
|
|
140
|
+
|
|
141
|
+
expect(isNumber('123')).toBe(false)
|
|
142
|
+
expect(isNumber(null)).toBe(false)
|
|
143
|
+
expect(isNumber(Undefined)).toBe(false)
|
|
144
|
+
expect(isNumber(123n)).toBe(false)
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
describe('isObject', () => {
|
|
149
|
+
it('correctly identifies object values', () => {
|
|
150
|
+
expect(isObject({})).toBe(true)
|
|
151
|
+
expect(isObject({ key: 'value' })).toBe(true)
|
|
152
|
+
expect(isObject(new Date())).toBe(true)
|
|
153
|
+
expect(isObject(new Map())).toBe(true)
|
|
154
|
+
|
|
155
|
+
expect(isObject([])).toBe(false) // Arrays are not objects for this function
|
|
156
|
+
expect(isObject(null)).toBe(false)
|
|
157
|
+
expect(isObject(Undefined)).toBe(false)
|
|
158
|
+
expect(isObject('object')).toBe(false)
|
|
159
|
+
expect(isObject(123)).toBe(false)
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
describe('isArray', () => {
|
|
164
|
+
it('correctly identifies array values', () => {
|
|
165
|
+
expect(isArray([])).toBe(true)
|
|
166
|
+
expect(isArray([1, 2, 3])).toBe(true)
|
|
167
|
+
expect(isArray(Array.from({ length: 5 }))).toBe(true)
|
|
168
|
+
|
|
169
|
+
expect(isArray({})).toBe(false)
|
|
170
|
+
expect(isArray('array')).toBe(false)
|
|
171
|
+
expect(isArray(null)).toBe(false)
|
|
172
|
+
expect(isArray(Undefined)).toBe(false)
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
describe('isFunction', () => {
|
|
177
|
+
it('correctly identifies function values', () => {
|
|
178
|
+
expect(isFunction(() => {})).toBe(true)
|
|
179
|
+
expect(isFunction(function () {})).toBe(true)
|
|
180
|
+
expect(isFunction(Date)).toBe(true)
|
|
181
|
+
|
|
182
|
+
expect(isFunction({})).toBe(false)
|
|
183
|
+
expect(isFunction('function')).toBe(false)
|
|
184
|
+
expect(isFunction(null)).toBe(false)
|
|
185
|
+
expect(isFunction(Undefined)).toBe(false)
|
|
186
|
+
})
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
describe('isSymbol', () => {
|
|
190
|
+
it('correctly identifies symbol values', () => {
|
|
191
|
+
expect(isSymbol(Symbol())).toBe(true)
|
|
192
|
+
expect(isSymbol(Symbol('test'))).toBe(true)
|
|
193
|
+
|
|
194
|
+
expect(isSymbol('symbol')).toBe(false)
|
|
195
|
+
expect(isSymbol(null)).toBe(false)
|
|
196
|
+
expect(isSymbol(Undefined)).toBe(false)
|
|
197
|
+
expect(isSymbol({})).toBe(false)
|
|
198
|
+
})
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
describe('isEmptyObject', () => {
|
|
202
|
+
it('correctly identifies empty object values', () => {
|
|
203
|
+
expect(isEmptyObject({})).toBe(true)
|
|
204
|
+
expect(isEmptyObject(Object.create(null))).toBe(true)
|
|
205
|
+
|
|
206
|
+
expect(isEmptyObject({ key: 'value' })).toBe(false)
|
|
207
|
+
expect(isEmptyObject([])).toBe(false)
|
|
208
|
+
expect(isEmptyObject(null)).toBe(false)
|
|
209
|
+
expect(isEmptyObject(Undefined)).toBe(false)
|
|
210
|
+
})
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
describe('isEmptyString', () => {
|
|
214
|
+
it('correctly identifies empty string values', () => {
|
|
215
|
+
expect(isEmptyString('')).toBe(true)
|
|
216
|
+
|
|
217
|
+
expect(isEmptyString(' ')).toBe(false)
|
|
218
|
+
expect(isEmptyString('hello')).toBe(false)
|
|
219
|
+
expect(isEmptyString(null)).toBe(false)
|
|
220
|
+
expect(isEmptyString(Undefined)).toBe(false)
|
|
221
|
+
})
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
describe('isEmptyArray', () => {
|
|
225
|
+
it('correctly identifies empty array values', () => {
|
|
226
|
+
expect(isEmptyArray([])).toBe(true)
|
|
227
|
+
expect(isEmptyArray([])).toBe(true)
|
|
228
|
+
|
|
229
|
+
expect(isEmptyArray([1, 2, 3])).toBe(false)
|
|
230
|
+
expect(isEmptyArray({})).toBe(false)
|
|
231
|
+
expect(isEmptyArray(null)).toBe(false)
|
|
232
|
+
expect(isEmptyArray(Undefined)).toBe(false)
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
describe('isPopulatedArray', () => {
|
|
237
|
+
it('correctly identifies populated array values', () => {
|
|
238
|
+
expect(isPopulatedArray([1, 2, 3])).toBe(true)
|
|
239
|
+
expect(isPopulatedArray(['test'])).toBe(true)
|
|
240
|
+
|
|
241
|
+
expect(isPopulatedArray([])).toBe(false)
|
|
242
|
+
expect(isPopulatedArray({})).toBe(false)
|
|
243
|
+
expect(isPopulatedArray(null)).toBe(false)
|
|
244
|
+
expect(isPopulatedArray(Undefined)).toBe(false)
|
|
245
|
+
})
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
describe('isEmpty', () => {
|
|
249
|
+
it('correctly identifies empty values', () => {
|
|
250
|
+
expect(isEmpty('')).toBe(true)
|
|
251
|
+
expect(isEmpty([])).toBe(true)
|
|
252
|
+
expect(isEmpty({})).toBe(true)
|
|
253
|
+
|
|
254
|
+
expect(isEmpty('hello')).toBe(false)
|
|
255
|
+
expect(isEmpty([1, 2])).toBe(false)
|
|
256
|
+
expect(isEmpty({ key: 'value' })).toBe(false)
|
|
257
|
+
expect(isEmpty(0)).toBe(false)
|
|
258
|
+
expect(isEmpty(null)).toBe(false)
|
|
259
|
+
expect(isEmpty(Undefined)).toBe(false)
|
|
260
|
+
})
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
describe('isFalsy', () => {
|
|
264
|
+
it('correctly identifies falsy values', () => {
|
|
265
|
+
expect(isFalsy(false)).toBe(true)
|
|
266
|
+
expect(isFalsy(0)).toBe(true)
|
|
267
|
+
expect(isFalsy('')).toBe(true)
|
|
268
|
+
expect(isFalsy(null)).toBe(true)
|
|
269
|
+
expect(isFalsy(Undefined)).toBe(true)
|
|
270
|
+
expect(isFalsy(Number.NaN)).toBe(true)
|
|
271
|
+
expect(isFalsy(0n)).toBe(true)
|
|
272
|
+
|
|
273
|
+
expect(isFalsy(true)).toBe(false)
|
|
274
|
+
expect(isFalsy(1)).toBe(false)
|
|
275
|
+
expect(isFalsy('hello')).toBe(false)
|
|
276
|
+
expect(isFalsy({})).toBe(false)
|
|
277
|
+
expect(isFalsy([])).toBe(false)
|
|
278
|
+
})
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
describe('isTruthy', () => {
|
|
282
|
+
it('correctly identifies truthy values', () => {
|
|
283
|
+
expect(isTruthy(true)).toBe(true)
|
|
284
|
+
expect(isTruthy(1)).toBe(true)
|
|
285
|
+
expect(isTruthy('hello')).toBe(true)
|
|
286
|
+
expect(isTruthy({})).toBe(true)
|
|
287
|
+
expect(isTruthy([])).toBe(true)
|
|
288
|
+
|
|
289
|
+
expect(isTruthy(false)).toBe(false)
|
|
290
|
+
expect(isTruthy(0)).toBe(false)
|
|
291
|
+
expect(isTruthy('')).toBe(false)
|
|
292
|
+
expect(isTruthy(null)).toBe(false)
|
|
293
|
+
expect(isTruthy(Undefined)).toBe(false)
|
|
294
|
+
})
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
describe('isBoolean', () => {
|
|
298
|
+
it('correctly identifies boolean values', () => {
|
|
299
|
+
expect(isBoolean(true)).toBe(true)
|
|
300
|
+
expect(isBoolean(false)).toBe(true)
|
|
301
|
+
expect(isBoolean(Boolean(1))).toBe(true)
|
|
302
|
+
|
|
303
|
+
expect(isBoolean(0)).toBe(false)
|
|
304
|
+
expect(isBoolean(1)).toBe(false)
|
|
305
|
+
expect(isBoolean('true')).toBe(false)
|
|
306
|
+
expect(isBoolean(null)).toBe(false)
|
|
307
|
+
expect(isBoolean(Undefined)).toBe(false)
|
|
308
|
+
})
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
describe('isDateString', () => {
|
|
312
|
+
it('correctly identifies date string values', () => {
|
|
313
|
+
expect(isDateString('2023-01-01')).toBe(true)
|
|
314
|
+
expect(isDateString('01/01/2023')).toBe(true)
|
|
315
|
+
expect(isDateString('January 1, 2023')).toBe(true)
|
|
316
|
+
expect(isDateString('2023-01-01T00:00:00Z')).toBe(true)
|
|
317
|
+
|
|
318
|
+
expect(isDateString('not a date')).toBe(false)
|
|
319
|
+
expect(isDateString('')).toBe(false)
|
|
320
|
+
expect(isDateString(null)).toBe(false)
|
|
321
|
+
expect(isDateString(Undefined)).toBe(false)
|
|
322
|
+
expect(isDateString(new Date())).toBe(false)
|
|
323
|
+
})
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
describe('isDate', () => {
|
|
327
|
+
it('correctly identifies Date objects', () => {
|
|
328
|
+
expect(isDate(new Date())).toBe(true)
|
|
329
|
+
expect(isDate(new Date(2023, 0, 1))).toBe(true)
|
|
330
|
+
|
|
331
|
+
expect(isDate('2023-01-01')).toBe(false)
|
|
332
|
+
expect(isDate(Date.now())).toBe(false)
|
|
333
|
+
expect(isDate(null)).toBe(false)
|
|
334
|
+
expect(isDate(Undefined)).toBe(false)
|
|
335
|
+
})
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
describe('isRegExp', () => {
|
|
339
|
+
it('correctly identifies RegExp objects', () => {
|
|
340
|
+
expect(isRegExp(/test/)).toBe(true)
|
|
341
|
+
expect(isRegExp(new RegExp('test'))).toBe(true)
|
|
342
|
+
|
|
343
|
+
expect(isRegExp('/test/')).toBe(false)
|
|
344
|
+
expect(isRegExp('test')).toBe(false)
|
|
345
|
+
expect(isRegExp(null)).toBe(false)
|
|
346
|
+
expect(isRegExp(Undefined)).toBe(false)
|
|
347
|
+
})
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
describe('isError', () => {
|
|
351
|
+
it('correctly identifies Error objects', () => {
|
|
352
|
+
expect(isError(new Error('Test'))).toBe(true)
|
|
353
|
+
expect(isError(new TypeError('Test'))).toBe(true)
|
|
354
|
+
expect(isError(new SyntaxError('Test'))).toBe(true)
|
|
355
|
+
|
|
356
|
+
expect(isError('error')).toBe(false)
|
|
357
|
+
expect(isError({ message: 'Error' })).toBe(false)
|
|
358
|
+
expect(isError(null)).toBe(false)
|
|
359
|
+
expect(isError(Undefined)).toBe(false)
|
|
360
|
+
})
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
describe('isPromise', () => {
|
|
364
|
+
it('correctly identifies Promise objects', () => {
|
|
365
|
+
expect(isPromise(Promise.resolve())).toBe(true)
|
|
366
|
+
expect(isPromise(new Promise(() => {}))).toBe(true)
|
|
367
|
+
|
|
368
|
+
// eslint-disable-next-line unicorn/no-thenable
|
|
369
|
+
expect(isPromise({ then: () => {}, catch: () => {} })).toBe(false) // Not a real Promise instance
|
|
370
|
+
expect(isPromise({})).toBe(false)
|
|
371
|
+
expect(isPromise(null)).toBe(false)
|
|
372
|
+
expect(isPromise(Undefined)).toBe(false)
|
|
373
|
+
})
|
|
374
|
+
})
|
|
375
|
+
|
|
376
|
+
describe('isPromiseLike', () => {
|
|
377
|
+
it('correctly identifies Promise-like objects', () => {
|
|
378
|
+
expect(isPromiseLike(Promise.resolve())).toBe(true)
|
|
379
|
+
expect(isPromiseLike(new Promise(() => {}))).toBe(true)
|
|
380
|
+
// eslint-disable-next-line unicorn/no-thenable
|
|
381
|
+
expect(isPromiseLike({ then: () => {} })).toBe(true) // Thenable
|
|
382
|
+
|
|
383
|
+
expect(isPromiseLike({})).toBe(false)
|
|
384
|
+
// eslint-disable-next-line unicorn/no-thenable
|
|
385
|
+
expect(isPromiseLike({ then: 5 })).toBe(false) // 'then' must be a function
|
|
386
|
+
expect(isPromiseLike(null)).toBe(false)
|
|
387
|
+
expect(isPromiseLike(Undefined)).toBe(false)
|
|
388
|
+
})
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
describe('isMap', () => {
|
|
392
|
+
it('correctly identifies Map objects', () => {
|
|
393
|
+
expect(isMap(new Map())).toBe(true)
|
|
394
|
+
expect(isMap(new Map([['key', 'value']]))).toBe(true)
|
|
395
|
+
|
|
396
|
+
expect(isMap({})).toBe(false)
|
|
397
|
+
expect(isMap(new Set())).toBe(false)
|
|
398
|
+
expect(isMap(null)).toBe(false)
|
|
399
|
+
expect(isMap(Undefined)).toBe(false)
|
|
400
|
+
})
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
describe('isArrayBufferView', () => {
|
|
404
|
+
it('correctly identifies ArrayBufferView objects', () => {
|
|
405
|
+
expect(isArrayBufferView(new Uint8Array())).toBe(true)
|
|
406
|
+
expect(isArrayBufferView(new Int32Array())).toBe(true)
|
|
407
|
+
expect(isArrayBufferView(new Float64Array())).toBe(true)
|
|
408
|
+
expect(isArrayBufferView(new DataView(new ArrayBuffer(10)))).toBe(true)
|
|
409
|
+
|
|
410
|
+
expect(isArrayBufferView(new ArrayBuffer(10))).toBe(false)
|
|
411
|
+
expect(isArrayBufferView({})).toBe(false)
|
|
412
|
+
expect(isArrayBufferView(null)).toBe(false)
|
|
413
|
+
expect(isArrayBufferView(Undefined)).toBe(false)
|
|
414
|
+
})
|
|
415
|
+
})
|
|
416
|
+
|
|
417
|
+
describe('isSet', () => {
|
|
418
|
+
it('correctly identifies Set objects', () => {
|
|
419
|
+
expect(isSet(new Set())).toBe(true)
|
|
420
|
+
expect(isSet(new Set([1, 2, 3]))).toBe(true)
|
|
421
|
+
|
|
422
|
+
expect(isSet({})).toBe(false)
|
|
423
|
+
expect(isSet(new Map())).toBe(false)
|
|
424
|
+
expect(isSet(null)).toBe(false)
|
|
425
|
+
expect(isSet(Undefined)).toBe(false)
|
|
426
|
+
})
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
describe('isWeakMap', () => {
|
|
430
|
+
it('correctly identifies WeakMap objects', () => {
|
|
431
|
+
expect(isWeakMap(new WeakMap())).toBe(true)
|
|
432
|
+
|
|
433
|
+
const obj = {}
|
|
434
|
+
const wm = new WeakMap()
|
|
435
|
+
wm.set(obj, 'value')
|
|
436
|
+
expect(isWeakMap(wm)).toBe(true)
|
|
437
|
+
|
|
438
|
+
expect(isWeakMap(new Map())).toBe(false)
|
|
439
|
+
expect(isWeakMap({})).toBe(false)
|
|
440
|
+
expect(isWeakMap(null)).toBe(false)
|
|
441
|
+
expect(isWeakMap(Undefined)).toBe(false)
|
|
442
|
+
})
|
|
443
|
+
})
|
|
444
|
+
|
|
445
|
+
describe('isWeakSet', () => {
|
|
446
|
+
it('correctly identifies WeakSet objects', () => {
|
|
447
|
+
expect(isWeakSet(new WeakSet())).toBe(true)
|
|
448
|
+
|
|
449
|
+
const obj = {}
|
|
450
|
+
const ws = new WeakSet()
|
|
451
|
+
ws.add(obj)
|
|
452
|
+
expect(isWeakSet(ws)).toBe(true)
|
|
453
|
+
|
|
454
|
+
expect(isWeakSet(new Set())).toBe(false)
|
|
455
|
+
expect(isWeakSet({})).toBe(false)
|
|
456
|
+
expect(isWeakSet(null)).toBe(false)
|
|
457
|
+
expect(isWeakSet(Undefined)).toBe(false)
|
|
458
|
+
})
|
|
459
|
+
})
|
|
460
|
+
|
|
461
|
+
describe('isArrayBuffer', () => {
|
|
462
|
+
it('correctly identifies ArrayBuffer objects', () => {
|
|
463
|
+
expect(isArrayBuffer(new ArrayBuffer(10))).toBe(true)
|
|
464
|
+
|
|
465
|
+
expect(isArrayBuffer(new Uint8Array())).toBe(false)
|
|
466
|
+
expect(isArrayBuffer({})).toBe(false)
|
|
467
|
+
expect(isArrayBuffer(null)).toBe(false)
|
|
468
|
+
expect(isArrayBuffer(Undefined)).toBe(false)
|
|
469
|
+
})
|
|
470
|
+
})
|
|
471
|
+
|
|
472
|
+
describe('isDataView', () => {
|
|
473
|
+
it('correctly identifies DataView objects', () => {
|
|
474
|
+
const buffer = new ArrayBuffer(10)
|
|
475
|
+
expect(isDataView(new DataView(buffer))).toBe(true)
|
|
476
|
+
|
|
477
|
+
expect(isDataView(buffer)).toBe(false)
|
|
478
|
+
expect(isDataView(new Uint8Array(buffer))).toBe(false)
|
|
479
|
+
expect(isDataView({})).toBe(false)
|
|
480
|
+
expect(isDataView(null)).toBe(false)
|
|
481
|
+
expect(isDataView(Undefined)).toBe(false)
|
|
482
|
+
})
|
|
483
|
+
})
|
|
484
|
+
|
|
485
|
+
describe('isBlob', () => {
|
|
486
|
+
it('correctly identifies Blob objects', () => {
|
|
487
|
+
// In a browser environment:
|
|
488
|
+
if (typeof Blob === 'undefined') {
|
|
489
|
+
// In Node.js without Blob:
|
|
490
|
+
expect(isBlob({})).toBe(false)
|
|
491
|
+
expect(isBlob(null)).toBe(false)
|
|
492
|
+
expect(isBlob(Undefined)).toBe(false)
|
|
493
|
+
} else {
|
|
494
|
+
expect(isBlob(new Blob(['content']))).toBe(true)
|
|
495
|
+
|
|
496
|
+
expect(isBlob({})).toBe(false)
|
|
497
|
+
expect(isBlob(null)).toBe(false)
|
|
498
|
+
expect(isBlob(Undefined)).toBe(false)
|
|
499
|
+
}
|
|
500
|
+
})
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
describe('isFile', () => {
|
|
504
|
+
it('correctly identifies File objects', () => {
|
|
505
|
+
// In a browser environment:
|
|
506
|
+
if (typeof File === 'undefined') {
|
|
507
|
+
// In Node.js without File:
|
|
508
|
+
expect(isFile({})).toBe(false)
|
|
509
|
+
expect(isFile(null)).toBe(false)
|
|
510
|
+
expect(isFile(Undefined)).toBe(false)
|
|
511
|
+
} else {
|
|
512
|
+
expect(isFile(new File(['content'], 'filename.txt'))).toBe(true)
|
|
513
|
+
|
|
514
|
+
expect(isFile({})).toBe(false)
|
|
515
|
+
expect(isFile(null)).toBe(false)
|
|
516
|
+
expect(isFile(Undefined)).toBe(false)
|
|
517
|
+
}
|
|
518
|
+
})
|
|
519
|
+
})
|
|
520
|
+
})
|
package/typedoc.json
DELETED