1
- 'use strict' ;
2
-
3
1
/* !
4
2
* type-detect
5
3
* Copyright(c) 2013 jake luer <[email protected] >
6
4
* MIT Licensed
7
5
*/
8
- var promiseExists = typeof Promise === 'function' ;
6
+ const promiseExists = typeof Promise === 'function' ;
9
7
10
8
/* eslint-disable no-undef */
11
- var globalObject = typeof self === 'object' ? self : global ; // eslint-disable-line id-blacklist
9
+ const globalObject = typeof self === 'object' ? self : global ; // eslint-disable-line id-blacklist
12
10
13
11
/*
14
12
* All of these attributes must be available on the global object for the current environment
15
13
* to be considered a DOM environment (browser)
16
14
*/
17
- var isDom = typeof window === 'object' &&
15
+ const isDom = typeof window === 'object' &&
18
16
'document' in window &&
19
17
'navigator' in window &&
20
18
'HTMLElement' in window ;
21
19
/* eslint-enable */
22
20
23
- var symbolExists = typeof Symbol !== 'undefined' ;
24
- var mapExists = typeof Map !== 'undefined' ;
25
- var setExists = typeof Set !== 'undefined' ;
26
- var weakMapExists = typeof WeakMap !== 'undefined' ;
27
- var weakSetExists = typeof WeakSet !== 'undefined' ;
28
- var dataViewExists = typeof DataView !== 'undefined' ;
29
- var symbolIteratorExists = symbolExists && typeof Symbol . iterator !== 'undefined' ;
30
- var symbolToStringTagExists = symbolExists && typeof Symbol . toStringTag !== 'undefined' ;
31
- var setEntriesExists = setExists && typeof Set . prototype . entries === 'function' ;
32
- var mapEntriesExists = mapExists && typeof Map . prototype . entries === 'function' ;
33
- var setIteratorPrototype = setEntriesExists && Object . getPrototypeOf ( new Set ( ) . entries ( ) ) ;
34
- var mapIteratorPrototype = mapEntriesExists && Object . getPrototypeOf ( new Map ( ) . entries ( ) ) ;
35
- var arrayIteratorExists = symbolIteratorExists && typeof Array . prototype [ Symbol . iterator ] === 'function' ;
36
- var arrayIteratorPrototype = arrayIteratorExists && Object . getPrototypeOf ( [ ] [ Symbol . iterator ] ( ) ) ;
37
- var stringIteratorExists = symbolIteratorExists && typeof String . prototype [ Symbol . iterator ] === 'function' ;
38
- var stringIteratorPrototype = stringIteratorExists && Object . getPrototypeOf ( '' [ Symbol . iterator ] ( ) ) ;
39
- var toStringLeftSliceLength = 8 ;
40
- var toStringRightSliceLength = - 1 ;
21
+ const symbolExists = typeof Symbol !== 'undefined' ;
22
+ const mapExists = typeof Map !== 'undefined' ;
23
+ const setExists = typeof Set !== 'undefined' ;
24
+ const weakMapExists = typeof WeakMap !== 'undefined' ;
25
+ const weakSetExists = typeof WeakSet !== 'undefined' ;
26
+ const dataViewExists = typeof DataView !== 'undefined' ;
27
+ const symbolIteratorExists = symbolExists && typeof Symbol . iterator !== 'undefined' ;
28
+ const symbolToStringTagExists = symbolExists && typeof Symbol . toStringTag !== 'undefined' ;
29
+ const setEntriesExists = setExists && typeof Set . prototype . entries === 'function' ;
30
+ const mapEntriesExists = mapExists && typeof Map . prototype . entries === 'function' ;
31
+ const setIteratorPrototype = setEntriesExists && Object . getPrototypeOf ( new Set ( ) . entries ( ) ) ;
32
+ const mapIteratorPrototype = mapEntriesExists && Object . getPrototypeOf ( new Map ( ) . entries ( ) ) ;
33
+ const arrayIteratorExists = symbolIteratorExists && typeof Array . prototype [ Symbol . iterator ] === 'function' ;
34
+ const arrayIteratorPrototype = arrayIteratorExists && Object . getPrototypeOf ( [ ] [ Symbol . iterator ] ( ) ) ;
35
+ const stringIteratorExists = symbolIteratorExists && typeof String . prototype [ Symbol . iterator ] === 'function' ;
36
+ const stringIteratorPrototype = stringIteratorExists && Object . getPrototypeOf ( '' [ Symbol . iterator ] ( ) ) ;
37
+ const toStringLeftSliceLength = 8 ;
38
+ const toStringRightSliceLength = - 1 ;
41
39
/**
42
40
* ### typeOf (obj)
43
41
*
@@ -48,7 +46,7 @@ var toStringRightSliceLength = -1;
48
46
* @return {String } object type
49
47
* @api public
50
48
*/
51
- module . exports = function typeDetect ( obj ) {
49
+ export default function typeDetect ( obj ) {
52
50
/* ! Speed optimisation
53
51
* Pre:
54
52
* string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
@@ -63,7 +61,7 @@ module.exports = function typeDetect(obj) {
63
61
* undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
64
62
* function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
65
63
*/
66
- var typeofObj = typeof obj ;
64
+ const typeofObj = typeof obj ;
67
65
if ( typeofObj !== 'object' ) {
68
66
return typeofObj ;
69
67
}
@@ -231,12 +229,12 @@ module.exports = function typeDetect(obj) {
231
229
* Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
232
230
* Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
233
231
*/
234
- var stringTag = ( symbolToStringTagExists && obj [ Symbol . toStringTag ] ) ;
232
+ const stringTag = ( symbolToStringTagExists && obj [ Symbol . toStringTag ] ) ;
235
233
if ( typeof stringTag === 'string' ) {
236
234
return stringTag ;
237
235
}
238
236
239
- var objPrototype = Object . getPrototypeOf ( obj ) ;
237
+ const objPrototype = Object . getPrototypeOf ( obj ) ;
240
238
/* ! Speed optimisation
241
239
* Pre:
242
240
* regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
@@ -377,6 +375,4 @@ module.exports = function typeDetect(obj) {
377
375
. toString
378
376
. call ( obj )
379
377
. slice ( toStringLeftSliceLength , toStringRightSliceLength ) ;
380
- } ;
381
-
382
- module . exports . typeDetect = module . exports ;
378
+ }
0 commit comments