4
4
* Copyright(c) 2013 jake luer <[email protected] >
5
5
* MIT Licensed
6
6
*/
7
- var getPrototypeOfExists = typeof Object . getPrototypeOf === 'function' ;
8
7
var promiseExists = typeof Promise === 'function' ;
9
8
var globalObject = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : self ; // eslint-disable-line
10
9
var isDom = 'location' in globalObject && 'document' in globalObject ;
11
- var htmlElementExists = typeof HTMLElement !== 'undefined' ;
12
- var isArrayExists = typeof Array . isArray === 'function' ;
13
10
var symbolExists = typeof Symbol !== 'undefined' ;
14
11
var mapExists = typeof Map !== 'undefined' ;
15
12
var setExists = typeof Set !== 'undefined' ;
@@ -20,8 +17,8 @@ var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined
20
17
var symbolToStringTagExists = symbolExists && typeof Symbol . toStringTag !== 'undefined' ;
21
18
var setEntriesExists = setExists && typeof Set . prototype . entries === 'function' ;
22
19
var mapEntriesExists = mapExists && typeof Map . prototype . entries === 'function' ;
23
- var setIteratorPrototype = getPrototypeOfExists && setEntriesExists && Object . getPrototypeOf ( new Set ( ) . entries ( ) ) ;
24
- var mapIteratorPrototype = getPrototypeOfExists && mapEntriesExists && Object . getPrototypeOf ( new Map ( ) . entries ( ) ) ;
20
+ var setIteratorPrototype = setEntriesExists && Object . getPrototypeOf ( new Set ( ) . entries ( ) ) ;
21
+ var mapIteratorPrototype = mapEntriesExists && Object . getPrototypeOf ( new Map ( ) . entries ( ) ) ;
25
22
var arrayIteratorExists = symbolIteratorExists && typeof Array . prototype [ Symbol . iterator ] === 'function' ;
26
23
var arrayIteratorPrototype = arrayIteratorExists && Object . getPrototypeOf ( [ ] [ Symbol . iterator ] ( ) ) ;
27
24
var stringIteratorExists = symbolIteratorExists && typeof Array . prototype [ Symbol . iterator ] === 'function' ;
@@ -94,7 +91,7 @@ module.exports = function typeDetect(obj) {
94
91
* Post:
95
92
* array literal x 22,479,650 ops/sec ±0.96% (81 runs sampled)
96
93
*/
97
- if ( isArrayExists && Array . isArray ( obj ) ) {
94
+ if ( Array . isArray ( obj ) ) {
98
95
return 'Array' ;
99
96
}
100
97
@@ -159,7 +156,7 @@ module.exports = function typeDetect(obj) {
159
156
* Test: `Object.prototype.toString.call(document.createElement('blockquote'))``
160
157
* - IE <=10 === "[object HTMLBlockElement]"
161
158
*/
162
- if ( htmlElementExists && obj instanceof HTMLElement && obj . tagName === 'BLOCKQUOTE' ) {
159
+ if ( obj instanceof HTMLElement && obj . tagName === 'BLOCKQUOTE' ) {
163
160
return 'HTMLQuoteElement' ;
164
161
}
165
162
@@ -175,7 +172,7 @@ module.exports = function typeDetect(obj) {
175
172
* - Firefox === "[object HTMLTableCellElement]"
176
173
* - Safari === "[object HTMLTableCellElement]"
177
174
*/
178
- if ( htmlElementExists && obj instanceof HTMLElement && obj . tagName === 'TD' ) {
175
+ if ( obj instanceof HTMLElement && obj . tagName === 'TD' ) {
179
176
return 'HTMLTableDataCellElement' ;
180
177
}
181
178
@@ -191,7 +188,7 @@ module.exports = function typeDetect(obj) {
191
188
* - Firefox === "[object HTMLTableCellElement]"
192
189
* - Safari === "[object HTMLTableCellElement]"
193
190
*/
194
- if ( htmlElementExists && obj instanceof HTMLElement && obj . tagName === 'TH' ) {
191
+ if ( obj instanceof HTMLElement && obj . tagName === 'TH' ) {
195
192
return 'HTMLTableHeaderCellElement' ;
196
193
}
197
194
}
@@ -223,142 +220,140 @@ module.exports = function typeDetect(obj) {
223
220
return stringTag ;
224
221
}
225
222
226
- if ( getPrototypeOfExists ) {
227
- var objPrototype = Object . getPrototypeOf ( obj ) ;
228
- /* ! Speed optimisation
229
- * Pre:
230
- * regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
231
- * regex constructor x 2,143,634 ops/sec ±2.46% (78 runs sampled)
232
- * Post:
233
- * regex literal x 3,928,009 ops/sec ±0.65% (78 runs sampled)
234
- * regex constructor x 3,931,108 ops/sec ±0.58% (84 runs sampled)
235
- */
236
- if ( objPrototype === RegExp . prototype ) {
237
- return 'RegExp' ;
238
- }
223
+ var objPrototype = Object . getPrototypeOf ( obj ) ;
224
+ /* ! Speed optimisation
225
+ * Pre:
226
+ * regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
227
+ * regex constructor x 2,143,634 ops/sec ±2.46% (78 runs sampled)
228
+ * Post:
229
+ * regex literal x 3,928,009 ops/sec ±0.65% (78 runs sampled)
230
+ * regex constructor x 3,931,108 ops/sec ±0.58% (84 runs sampled)
231
+ */
232
+ if ( objPrototype === RegExp . prototype ) {
233
+ return 'RegExp' ;
234
+ }
239
235
240
- /* ! Speed optimisation
241
- * Pre:
242
- * date x 2,130,074 ops/sec ±4.42% (68 runs sampled)
243
- * Post:
244
- * date x 3,953,779 ops/sec ±1.35% (77 runs sampled)
245
- */
246
- if ( objPrototype === Date . prototype ) {
247
- return 'Date' ;
248
- }
236
+ /* ! Speed optimisation
237
+ * Pre:
238
+ * date x 2,130,074 ops/sec ±4.42% (68 runs sampled)
239
+ * Post:
240
+ * date x 3,953,779 ops/sec ±1.35% (77 runs sampled)
241
+ */
242
+ if ( objPrototype === Date . prototype ) {
243
+ return 'Date' ;
244
+ }
249
245
250
- /* ! Spec Conformance
251
- * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag)
252
- * ES6$25.4.5.4 - Promise.prototype[@@toStringTag] should be "Promise":
253
- * Test: `Object.prototype.toString.call(Promise.resolve())``
254
- * - Chrome <=47 === "[object Object]"
255
- * - Edge <=20 === "[object Object]"
256
- * - Firefox 29-Latest === "[object Promise]"
257
- * - Safari 7.1-Latest === "[object Promise]"
258
- */
259
- if ( promiseExists && objPrototype === Promise . prototype ) {
260
- return 'Promise' ;
261
- }
246
+ /* ! Spec Conformance
247
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag)
248
+ * ES6$25.4.5.4 - Promise.prototype[@@toStringTag] should be "Promise":
249
+ * Test: `Object.prototype.toString.call(Promise.resolve())``
250
+ * - Chrome <=47 === "[object Object]"
251
+ * - Edge <=20 === "[object Object]"
252
+ * - Firefox 29-Latest === "[object Promise]"
253
+ * - Safari 7.1-Latest === "[object Promise]"
254
+ */
255
+ if ( promiseExists && objPrototype === Promise . prototype ) {
256
+ return 'Promise' ;
257
+ }
262
258
263
- /* ! Speed optimisation
264
- * Pre:
265
- * set x 2,222,186 ops/sec ±1.31% (82 runs sampled)
266
- * Post:
267
- * set x 4,545,879 ops/sec ±1.13% (83 runs sampled)
268
- */
269
- if ( setExists && objPrototype === Set . prototype ) {
270
- return 'Set' ;
271
- }
259
+ /* ! Speed optimisation
260
+ * Pre:
261
+ * set x 2,222,186 ops/sec ±1.31% (82 runs sampled)
262
+ * Post:
263
+ * set x 4,545,879 ops/sec ±1.13% (83 runs sampled)
264
+ */
265
+ if ( setExists && objPrototype === Set . prototype ) {
266
+ return 'Set' ;
267
+ }
272
268
273
- /* ! Speed optimisation
274
- * Pre:
275
- * map x 2,396,842 ops/sec ±1.59% (81 runs sampled)
276
- * Post:
277
- * map x 4,183,945 ops/sec ±6.59% (82 runs sampled)
278
- */
279
- if ( mapExists && objPrototype === Map . prototype ) {
280
- return 'Map' ;
281
- }
269
+ /* ! Speed optimisation
270
+ * Pre:
271
+ * map x 2,396,842 ops/sec ±1.59% (81 runs sampled)
272
+ * Post:
273
+ * map x 4,183,945 ops/sec ±6.59% (82 runs sampled)
274
+ */
275
+ if ( mapExists && objPrototype === Map . prototype ) {
276
+ return 'Map' ;
277
+ }
282
278
283
- /* ! Speed optimisation
284
- * Pre:
285
- * weakset x 1,323,220 ops/sec ±2.17% (76 runs sampled)
286
- * Post:
287
- * weakset x 4,237,510 ops/sec ±2.01% (77 runs sampled)
288
- */
289
- if ( weakSetExists && objPrototype === WeakSet . prototype ) {
290
- return 'WeakSet' ;
291
- }
279
+ /* ! Speed optimisation
280
+ * Pre:
281
+ * weakset x 1,323,220 ops/sec ±2.17% (76 runs sampled)
282
+ * Post:
283
+ * weakset x 4,237,510 ops/sec ±2.01% (77 runs sampled)
284
+ */
285
+ if ( weakSetExists && objPrototype === WeakSet . prototype ) {
286
+ return 'WeakSet' ;
287
+ }
292
288
293
- /* ! Speed optimisation
294
- * Pre:
295
- * weakmap x 1,500,260 ops/sec ±2.02% (78 runs sampled)
296
- * Post:
297
- * weakmap x 3,881,384 ops/sec ±1.45% (82 runs sampled)
298
- */
299
- if ( weakMapExists && objPrototype === WeakMap . prototype ) {
300
- return 'WeakMap' ;
301
- }
289
+ /* ! Speed optimisation
290
+ * Pre:
291
+ * weakmap x 1,500,260 ops/sec ±2.02% (78 runs sampled)
292
+ * Post:
293
+ * weakmap x 3,881,384 ops/sec ±1.45% (82 runs sampled)
294
+ */
295
+ if ( weakMapExists && objPrototype === WeakMap . prototype ) {
296
+ return 'WeakMap' ;
297
+ }
302
298
303
- /* ! Spec Conformance
304
- * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag)
305
- * ES6$24.2.4.21 - DataView.prototype[@@toStringTag] should be "DataView":
306
- * Test: `Object.prototype.toString.call(new DataView(new ArrayBuffer(1)))``
307
- * - Edge <=13 === "[object Object]"
308
- */
309
- if ( dataViewExists && objPrototype === DataView . prototype ) {
310
- return 'DataView' ;
311
- }
299
+ /* ! Spec Conformance
300
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag)
301
+ * ES6$24.2.4.21 - DataView.prototype[@@toStringTag] should be "DataView":
302
+ * Test: `Object.prototype.toString.call(new DataView(new ArrayBuffer(1)))``
303
+ * - Edge <=13 === "[object Object]"
304
+ */
305
+ if ( dataViewExists && objPrototype === DataView . prototype ) {
306
+ return 'DataView' ;
307
+ }
312
308
313
- /* ! Spec Conformance
314
- * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag)
315
- * ES6$23.1.5.2.2 - %MapIteratorPrototype%[@@toStringTag] should be "Map Iterator":
316
- * Test: `Object.prototype.toString.call(new Map().entries())``
317
- * - Edge <=13 === "[object Object]"
318
- */
319
- if ( mapExists && objPrototype === mapIteratorPrototype ) {
320
- return 'Map Iterator' ;
321
- }
309
+ /* ! Spec Conformance
310
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag)
311
+ * ES6$23.1.5.2.2 - %MapIteratorPrototype%[@@toStringTag] should be "Map Iterator":
312
+ * Test: `Object.prototype.toString.call(new Map().entries())``
313
+ * - Edge <=13 === "[object Object]"
314
+ */
315
+ if ( mapExists && objPrototype === mapIteratorPrototype ) {
316
+ return 'Map Iterator' ;
317
+ }
322
318
323
- /* ! Spec Conformance
324
- * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag)
325
- * ES6$23.2.5.2.2 - %SetIteratorPrototype%[@@toStringTag] should be "Set Iterator":
326
- * Test: `Object.prototype.toString.call(new Set().entries())``
327
- * - Edge <=13 === "[object Object]"
328
- */
329
- if ( setExists && objPrototype === setIteratorPrototype ) {
330
- return 'Set Iterator' ;
331
- }
319
+ /* ! Spec Conformance
320
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag)
321
+ * ES6$23.2.5.2.2 - %SetIteratorPrototype%[@@toStringTag] should be "Set Iterator":
322
+ * Test: `Object.prototype.toString.call(new Set().entries())``
323
+ * - Edge <=13 === "[object Object]"
324
+ */
325
+ if ( setExists && objPrototype === setIteratorPrototype ) {
326
+ return 'Set Iterator' ;
327
+ }
332
328
333
- /* ! Spec Conformance
334
- * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag)
335
- * ES6$22.1.5.2.2 - %ArrayIteratorPrototype%[@@toStringTag] should be "Array Iterator":
336
- * Test: `Object.prototype.toString.call([][Symbol.iterator]())``
337
- * - Edge <=13 === "[object Object]"
338
- */
339
- if ( arrayIteratorExists && objPrototype === arrayIteratorPrototype ) {
340
- return 'Array Iterator' ;
341
- }
329
+ /* ! Spec Conformance
330
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag)
331
+ * ES6$22.1.5.2.2 - %ArrayIteratorPrototype%[@@toStringTag] should be "Array Iterator":
332
+ * Test: `Object.prototype.toString.call([][Symbol.iterator]())``
333
+ * - Edge <=13 === "[object Object]"
334
+ */
335
+ if ( arrayIteratorExists && objPrototype === arrayIteratorPrototype ) {
336
+ return 'Array Iterator' ;
337
+ }
342
338
343
- /* ! Spec Conformance
344
- * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag)
345
- * ES6$21.1.5.2.2 - %StringIteratorPrototype%[@@toStringTag] should be "String Iterator":
346
- * Test: `Object.prototype.toString.call(''[Symbol.iterator]())``
347
- * - Edge <=13 === "[object Object]"
348
- */
349
- if ( stringIteratorExists && objPrototype === stringIteratorPrototype ) {
350
- return 'String Iterator' ;
351
- }
339
+ /* ! Spec Conformance
340
+ * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag)
341
+ * ES6$21.1.5.2.2 - %StringIteratorPrototype%[@@toStringTag] should be "String Iterator":
342
+ * Test: `Object.prototype.toString.call(''[Symbol.iterator]())``
343
+ * - Edge <=13 === "[object Object]"
344
+ */
345
+ if ( stringIteratorExists && objPrototype === stringIteratorPrototype ) {
346
+ return 'String Iterator' ;
347
+ }
352
348
353
- /* ! Speed optimisation
354
- * Pre:
355
- * object from null x 2,424,320 ops/sec ±1.67% (76 runs sampled)
356
- * Post:
357
- * object from null x 5,838,000 ops/sec ±0.99% (84 runs sampled)
358
- */
359
- if ( objPrototype === null ) {
360
- return 'Object' ;
361
- }
349
+ /* ! Speed optimisation
350
+ * Pre:
351
+ * object from null x 2,424,320 ops/sec ±1.67% (76 runs sampled)
352
+ * Post:
353
+ * object from null x 5,838,000 ops/sec ±0.99% (84 runs sampled)
354
+ */
355
+ if ( objPrototype === null ) {
356
+ return 'Object' ;
362
357
}
363
358
364
359
return Object
0 commit comments