added unit testing, and started implementing unit tests...phew
This commit is contained in:
19
node_modules/type-detect/LICENSE
generated
vendored
Normal file
19
node_modules/type-detect/LICENSE
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2013 Jake Luer <jake@alogicalparadox.com> (http://alogicalparadox.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
228
node_modules/type-detect/README.md
generated
vendored
Normal file
228
node_modules/type-detect/README.md
generated
vendored
Normal file
@ -0,0 +1,228 @@
|
||||
<h1 align=center>
|
||||
<a href="http://chaijs.com" title="Chai Documentation">
|
||||
<img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png"/> type-detect
|
||||
</a>
|
||||
</h1>
|
||||
<br>
|
||||
<p align=center>
|
||||
Improved typeof detection for <a href="http://nodejs.org">node</a> and the browser.
|
||||
</p>
|
||||
|
||||
<p align=center>
|
||||
<a href="./LICENSE">
|
||||
<img
|
||||
alt="license:mit"
|
||||
src="https://img.shields.io/badge/license-mit-green.svg?style=flat-square"
|
||||
/>
|
||||
</a>
|
||||
<a href="https://github.com/chaijs/type-detect/releases">
|
||||
<img
|
||||
alt="tag:?"
|
||||
src="https://img.shields.io/github/tag/chaijs/type-detect.svg?style=flat-square"
|
||||
/>
|
||||
</a>
|
||||
<a href="https://travis-ci.org/chaijs/type-detect">
|
||||
<img
|
||||
alt="build:?"
|
||||
src="https://img.shields.io/travis/chaijs/type-detect/master.svg?style=flat-square"
|
||||
/>
|
||||
</a>
|
||||
<a href="https://coveralls.io/r/chaijs/type-detect">
|
||||
<img
|
||||
alt="coverage:?"
|
||||
src="https://img.shields.io/coveralls/chaijs/type-detect/master.svg?style=flat-square"
|
||||
/>
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/packages/type-detect">
|
||||
<img
|
||||
alt="npm:?"
|
||||
src="https://img.shields.io/npm/v/type-detect.svg?style=flat-square"
|
||||
/>
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/packages/type-detect">
|
||||
<img
|
||||
alt="dependencies:?"
|
||||
src="https://img.shields.io/npm/dm/type-detect.svg?style=flat-square"
|
||||
/>
|
||||
</a>
|
||||
<a href="">
|
||||
<img
|
||||
alt="devDependencies:?"
|
||||
src="https://img.shields.io/david/chaijs/type-detect.svg?style=flat-square"
|
||||
/>
|
||||
</a>
|
||||
<br/>
|
||||
<table>
|
||||
<tr><th colspan=6>Supported Browsers</th></tr> <tr>
|
||||
<th align=center><img src="https://camo.githubusercontent.com/ab586f11dfcb49bf5f2c2fa9adadc5e857de122a/687474703a2f2f73766773686172652e636f6d2f692f3278532e737667" alt=""> Chrome</th>
|
||||
<th align=center><img src="https://camo.githubusercontent.com/98cca3108c18dcfaa62667b42046540c6822cdac/687474703a2f2f73766773686172652e636f6d2f692f3279352e737667" alt=""> Edge</th>
|
||||
<th align=center><img src="https://camo.githubusercontent.com/acdcb09840a9e1442cbaf1b684f95ab3c3f41cf4/687474703a2f2f73766773686172652e636f6d2f692f3279462e737667" alt=""> Firefox</th>
|
||||
<th align=center><img src="https://camo.githubusercontent.com/728f8cb0bee9ed58ab85e39266f1152c53e0dffd/687474703a2f2f73766773686172652e636f6d2f692f3278342e737667" alt=""> Safari</th>
|
||||
<th align=center><img src="https://camo.githubusercontent.com/96a2317034dee0040d0a762e7a30c3c650c45aac/687474703a2f2f73766773686172652e636f6d2f692f3279532e737667" alt=""> IE</th>
|
||||
</tr><tr>
|
||||
<td align=center>✅</td>
|
||||
<td align=center>✅</td>
|
||||
<td align=center>✅</td>
|
||||
<td align=center>✅</td>
|
||||
<td align=center>9, 10, 11</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br>
|
||||
<a href="https://chai-slack.herokuapp.com/">
|
||||
<img
|
||||
alt="Join the Slack chat"
|
||||
src="https://img.shields.io/badge/slack-join%20chat-E2206F.svg?style=flat-square"
|
||||
/>
|
||||
</a>
|
||||
<a href="https://gitter.im/chaijs/chai">
|
||||
<img
|
||||
alt="Join the Gitter chat"
|
||||
src="https://img.shields.io/badge/gitter-join%20chat-D0104D.svg?style=flat-square"
|
||||
/>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
## What is Type-Detect?
|
||||
|
||||
Type Detect is a module which you can use to detect the type of a given object. It returns a string representation of the object's type, either using [`typeof`](http://www.ecma-international.org/ecma-262/6.0/index.html#sec-typeof-operator) or [`@@toStringTag`](http://www.ecma-international.org/ecma-262/6.0/index.html#sec-symbol.tostringtag). It also normalizes some object names for consistency among browsers.
|
||||
|
||||
## Why?
|
||||
|
||||
The `typeof` operator will only specify primitive values; everything else is `"object"` (including `null`, arrays, regexps, etc). Many developers use `Object.prototype.toString()` - which is a fine alternative and returns many more types (null returns `[object Null]`, Arrays as `[object Array]`, regexps as `[object RegExp]` etc).
|
||||
|
||||
Sadly, `Object.prototype.toString` is slow, and buggy. By slow - we mean it is slower than `typeof`. By buggy - we mean that some values (like Promises, the global object, iterators, dataviews, a bunch of HTML elements) all report different things in different browsers.
|
||||
|
||||
`type-detect` fixes all of the shortcomings with `Object.prototype.toString`. We have extra code to speed up checks of JS and DOM objects, as much as 20-30x faster for some values. `type-detect` also fixes any consistencies with these objects.
|
||||
|
||||
## Installation
|
||||
|
||||
### Node.js
|
||||
|
||||
`type-detect` is available on [npm](http://npmjs.org). To install it, type:
|
||||
|
||||
$ npm install type-detect
|
||||
|
||||
### Browsers
|
||||
|
||||
You can also use it within the browser; install via npm and use the `type-detect.js` file found within the download. For example:
|
||||
|
||||
```html
|
||||
<script src="./node_modules/type-detect/type-detect.js"></script>
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
The primary export of `type-detect` is function that can serve as a replacement for `typeof`. The results of this function will be more specific than that of native `typeof`.
|
||||
|
||||
```js
|
||||
var type = require('type-detect');
|
||||
```
|
||||
|
||||
#### array
|
||||
|
||||
```js
|
||||
assert(type([]) === 'Array');
|
||||
assert(type(new Array()) === 'Array');
|
||||
```
|
||||
|
||||
#### regexp
|
||||
|
||||
```js
|
||||
assert(type(/a-z/gi) === 'RegExp');
|
||||
assert(type(new RegExp('a-z')) === 'RegExp');
|
||||
```
|
||||
|
||||
#### function
|
||||
|
||||
```js
|
||||
assert(type(function () {}) === 'function');
|
||||
```
|
||||
|
||||
#### arguments
|
||||
|
||||
```js
|
||||
(function () {
|
||||
assert(type(arguments) === 'Arguments');
|
||||
})();
|
||||
```
|
||||
|
||||
#### date
|
||||
|
||||
```js
|
||||
assert(type(new Date) === 'Date');
|
||||
```
|
||||
|
||||
#### number
|
||||
|
||||
```js
|
||||
assert(type(1) === 'number');
|
||||
assert(type(1.234) === 'number');
|
||||
assert(type(-1) === 'number');
|
||||
assert(type(-1.234) === 'number');
|
||||
assert(type(Infinity) === 'number');
|
||||
assert(type(NaN) === 'number');
|
||||
assert(type(new Number(1)) === 'Number'); // note - the object version has a capital N
|
||||
```
|
||||
|
||||
#### string
|
||||
|
||||
```js
|
||||
assert(type('hello world') === 'string');
|
||||
assert(type(new String('hello')) === 'String'); // note - the object version has a capital S
|
||||
```
|
||||
|
||||
#### null
|
||||
|
||||
```js
|
||||
assert(type(null) === 'null');
|
||||
assert(type(undefined) !== 'null');
|
||||
```
|
||||
|
||||
#### undefined
|
||||
|
||||
```js
|
||||
assert(type(undefined) === 'undefined');
|
||||
assert(type(null) !== 'undefined');
|
||||
```
|
||||
|
||||
#### object
|
||||
|
||||
```js
|
||||
var Noop = function () {};
|
||||
assert(type({}) === 'Object');
|
||||
assert(type(Noop) !== 'Object');
|
||||
assert(type(new Noop) === 'Object');
|
||||
assert(type(new Object) === 'Object');
|
||||
```
|
||||
|
||||
#### ECMA6 Types
|
||||
|
||||
All new ECMAScript 2015 objects are also supported, such as Promises and Symbols:
|
||||
|
||||
```js
|
||||
assert(type(new Map() === 'Map');
|
||||
assert(type(new WeakMap()) === 'WeakMap');
|
||||
assert(type(new Set()) === 'Set');
|
||||
assert(type(new WeakSet()) === 'WeakSet');
|
||||
assert(type(Symbol()) === 'symbol');
|
||||
assert(type(new Promise(callback) === 'Promise');
|
||||
assert(type(new Int8Array()) === 'Int8Array');
|
||||
assert(type(new Uint8Array()) === 'Uint8Array');
|
||||
assert(type(new UInt8ClampedArray()) === 'Uint8ClampedArray');
|
||||
assert(type(new Int16Array()) === 'Int16Array');
|
||||
assert(type(new Uint16Array()) === 'Uint16Array');
|
||||
assert(type(new Int32Array()) === 'Int32Array');
|
||||
assert(type(new UInt32Array()) === 'Uint32Array');
|
||||
assert(type(new Float32Array()) === 'Float32Array');
|
||||
assert(type(new Float64Array()) === 'Float64Array');
|
||||
assert(type(new ArrayBuffer()) === 'ArrayBuffer');
|
||||
assert(type(new DataView(arrayBuffer)) === 'DataView');
|
||||
```
|
||||
|
||||
Also, if you use `Symbol.toStringTag` to change an Objects return value of the `toString()` Method, `type()` will return this value, e.g:
|
||||
|
||||
```js
|
||||
var myObject = {};
|
||||
myObject[Symbol.toStringTag] = 'myCustomType';
|
||||
assert(type(myObject) === 'myCustomType');
|
||||
```
|
378
node_modules/type-detect/index.js
generated
vendored
Normal file
378
node_modules/type-detect/index.js
generated
vendored
Normal file
@ -0,0 +1,378 @@
|
||||
/* !
|
||||
* type-detect
|
||||
* Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
const promiseExists = typeof Promise === 'function';
|
||||
|
||||
/* eslint-disable no-undef */
|
||||
const globalObject = typeof self === 'object' ? self : global; // eslint-disable-line id-blacklist
|
||||
|
||||
const symbolExists = typeof Symbol !== 'undefined';
|
||||
const mapExists = typeof Map !== 'undefined';
|
||||
const setExists = typeof Set !== 'undefined';
|
||||
const weakMapExists = typeof WeakMap !== 'undefined';
|
||||
const weakSetExists = typeof WeakSet !== 'undefined';
|
||||
const dataViewExists = typeof DataView !== 'undefined';
|
||||
const symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
|
||||
const symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
|
||||
const setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
|
||||
const mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
|
||||
const setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
|
||||
const mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
|
||||
const arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
|
||||
const arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
|
||||
const stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
|
||||
const stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
|
||||
const toStringLeftSliceLength = 8;
|
||||
const toStringRightSliceLength = -1;
|
||||
/**
|
||||
* ### typeOf (obj)
|
||||
*
|
||||
* Uses `Object.prototype.toString` to determine the type of an object,
|
||||
* normalising behaviour across engine versions & well optimised.
|
||||
*
|
||||
* @param {Mixed} object
|
||||
* @return {String} object type
|
||||
* @api public
|
||||
*/
|
||||
export default function typeDetect(obj) {
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
|
||||
* boolean literal x 1,424,138 ops/sec ±4.54% (75 runs sampled)
|
||||
* number literal x 1,653,153 ops/sec ±1.91% (82 runs sampled)
|
||||
* undefined x 9,978,660 ops/sec ±1.92% (75 runs sampled)
|
||||
* function x 2,556,769 ops/sec ±1.73% (77 runs sampled)
|
||||
* Post:
|
||||
* string literal x 38,564,796 ops/sec ±1.15% (79 runs sampled)
|
||||
* boolean literal x 31,148,940 ops/sec ±1.10% (79 runs sampled)
|
||||
* number literal x 32,679,330 ops/sec ±1.90% (78 runs sampled)
|
||||
* undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
|
||||
* function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
|
||||
*/
|
||||
const typeofObj = typeof obj;
|
||||
if (typeofObj !== 'object') {
|
||||
return typeofObj;
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* null x 28,645,765 ops/sec ±1.17% (82 runs sampled)
|
||||
* Post:
|
||||
* null x 36,428,962 ops/sec ±1.37% (84 runs sampled)
|
||||
*/
|
||||
if (obj === null) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* Test: `Object.prototype.toString.call(window)``
|
||||
* - Node === "[object global]"
|
||||
* - Chrome === "[object global]"
|
||||
* - Firefox === "[object Window]"
|
||||
* - PhantomJS === "[object Window]"
|
||||
* - Safari === "[object Window]"
|
||||
* - IE 11 === "[object Window]"
|
||||
* - IE Edge === "[object Window]"
|
||||
* Test: `Object.prototype.toString.call(this)``
|
||||
* - Chrome Worker === "[object global]"
|
||||
* - Firefox Worker === "[object DedicatedWorkerGlobalScope]"
|
||||
* - Safari Worker === "[object DedicatedWorkerGlobalScope]"
|
||||
* - IE 11 Worker === "[object WorkerGlobalScope]"
|
||||
* - IE Edge Worker === "[object WorkerGlobalScope]"
|
||||
*/
|
||||
if (obj === globalObject) {
|
||||
return 'global';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* array literal x 2,888,352 ops/sec ±0.67% (82 runs sampled)
|
||||
* Post:
|
||||
* array literal x 22,479,650 ops/sec ±0.96% (81 runs sampled)
|
||||
*/
|
||||
if (
|
||||
Array.isArray(obj) &&
|
||||
(symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
|
||||
) {
|
||||
return 'Array';
|
||||
}
|
||||
|
||||
// Not caching existence of `window` and related properties due to potential
|
||||
// for `window` to be unset before tests in quasi-browser environments.
|
||||
if (typeof window === 'object' && window !== null) {
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/multipage/browsers.html#location)
|
||||
* WhatWG HTML$7.7.3 - The `Location` interface
|
||||
* Test: `Object.prototype.toString.call(window.location)``
|
||||
* - IE <=11 === "[object Object]"
|
||||
* - IE Edge <=13 === "[object Object]"
|
||||
*/
|
||||
if (typeof window.location === 'object' && obj === window.location) {
|
||||
return 'Location';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/#document)
|
||||
* WhatWG HTML$3.1.1 - The `Document` object
|
||||
* Note: Most browsers currently adher to the W3C DOM Level 2 spec
|
||||
* (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268)
|
||||
* which suggests that browsers should use HTMLTableCellElement for
|
||||
* both TD and TH elements. WhatWG separates these.
|
||||
* WhatWG HTML states:
|
||||
* > For historical reasons, Window objects must also have a
|
||||
* > writable, configurable, non-enumerable property named
|
||||
* > HTMLDocument whose value is the Document interface object.
|
||||
* Test: `Object.prototype.toString.call(document)``
|
||||
* - Chrome === "[object HTMLDocument]"
|
||||
* - Firefox === "[object HTMLDocument]"
|
||||
* - Safari === "[object HTMLDocument]"
|
||||
* - IE <=10 === "[object Document]"
|
||||
* - IE 11 === "[object HTMLDocument]"
|
||||
* - IE Edge <=13 === "[object HTMLDocument]"
|
||||
*/
|
||||
if (typeof window.document === 'object' && obj === window.document) {
|
||||
return 'Document';
|
||||
}
|
||||
|
||||
if (typeof window.navigator === 'object') {
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/multipage/webappapis.html#mimetypearray)
|
||||
* WhatWG HTML$8.6.1.5 - Plugins - Interface MimeTypeArray
|
||||
* Test: `Object.prototype.toString.call(navigator.mimeTypes)``
|
||||
* - IE <=10 === "[object MSMimeTypesCollection]"
|
||||
*/
|
||||
if (typeof window.navigator.mimeTypes === 'object' &&
|
||||
obj === window.navigator.mimeTypes) {
|
||||
return 'MimeTypeArray';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
|
||||
* WhatWG HTML$8.6.1.5 - Plugins - Interface PluginArray
|
||||
* Test: `Object.prototype.toString.call(navigator.plugins)``
|
||||
* - IE <=10 === "[object MSPluginsCollection]"
|
||||
*/
|
||||
if (typeof window.navigator.plugins === 'object' &&
|
||||
obj === window.navigator.plugins) {
|
||||
return 'PluginArray';
|
||||
}
|
||||
}
|
||||
|
||||
if ((typeof window.HTMLElement === 'function' ||
|
||||
typeof window.HTMLElement === 'object') &&
|
||||
obj instanceof window.HTMLElement) {
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
|
||||
* WhatWG HTML$4.4.4 - The `blockquote` element - Interface `HTMLQuoteElement`
|
||||
* Test: `Object.prototype.toString.call(document.createElement('blockquote'))``
|
||||
* - IE <=10 === "[object HTMLBlockElement]"
|
||||
*/
|
||||
if (obj.tagName === 'BLOCKQUOTE') {
|
||||
return 'HTMLQuoteElement';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/#htmltabledatacellelement)
|
||||
* WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableDataCellElement`
|
||||
* Note: Most browsers currently adher to the W3C DOM Level 2 spec
|
||||
* (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
|
||||
* which suggests that browsers should use HTMLTableCellElement for
|
||||
* both TD and TH elements. WhatWG separates these.
|
||||
* Test: Object.prototype.toString.call(document.createElement('td'))
|
||||
* - Chrome === "[object HTMLTableCellElement]"
|
||||
* - Firefox === "[object HTMLTableCellElement]"
|
||||
* - Safari === "[object HTMLTableCellElement]"
|
||||
*/
|
||||
if (obj.tagName === 'TD') {
|
||||
return 'HTMLTableDataCellElement';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/#htmltableheadercellelement)
|
||||
* WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableHeaderCellElement`
|
||||
* Note: Most browsers currently adher to the W3C DOM Level 2 spec
|
||||
* (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
|
||||
* which suggests that browsers should use HTMLTableCellElement for
|
||||
* both TD and TH elements. WhatWG separates these.
|
||||
* Test: Object.prototype.toString.call(document.createElement('th'))
|
||||
* - Chrome === "[object HTMLTableCellElement]"
|
||||
* - Firefox === "[object HTMLTableCellElement]"
|
||||
* - Safari === "[object HTMLTableCellElement]"
|
||||
*/
|
||||
if (obj.tagName === 'TH') {
|
||||
return 'HTMLTableHeaderCellElement';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* Float64Array x 625,644 ops/sec ±1.58% (80 runs sampled)
|
||||
* Float32Array x 1,279,852 ops/sec ±2.91% (77 runs sampled)
|
||||
* Uint32Array x 1,178,185 ops/sec ±1.95% (83 runs sampled)
|
||||
* Uint16Array x 1,008,380 ops/sec ±2.25% (80 runs sampled)
|
||||
* Uint8Array x 1,128,040 ops/sec ±2.11% (81 runs sampled)
|
||||
* Int32Array x 1,170,119 ops/sec ±2.88% (80 runs sampled)
|
||||
* Int16Array x 1,176,348 ops/sec ±5.79% (86 runs sampled)
|
||||
* Int8Array x 1,058,707 ops/sec ±4.94% (77 runs sampled)
|
||||
* Uint8ClampedArray x 1,110,633 ops/sec ±4.20% (80 runs sampled)
|
||||
* Post:
|
||||
* Float64Array x 7,105,671 ops/sec ±13.47% (64 runs sampled)
|
||||
* Float32Array x 5,887,912 ops/sec ±1.46% (82 runs sampled)
|
||||
* Uint32Array x 6,491,661 ops/sec ±1.76% (79 runs sampled)
|
||||
* Uint16Array x 6,559,795 ops/sec ±1.67% (82 runs sampled)
|
||||
* Uint8Array x 6,463,966 ops/sec ±1.43% (85 runs sampled)
|
||||
* Int32Array x 5,641,841 ops/sec ±3.49% (81 runs sampled)
|
||||
* Int16Array x 6,583,511 ops/sec ±1.98% (80 runs sampled)
|
||||
* Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
|
||||
* Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
|
||||
*/
|
||||
const stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
|
||||
if (typeof stringTag === 'string') {
|
||||
return stringTag;
|
||||
}
|
||||
|
||||
const objPrototype = Object.getPrototypeOf(obj);
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
|
||||
* regex constructor x 2,143,634 ops/sec ±2.46% (78 runs sampled)
|
||||
* Post:
|
||||
* regex literal x 3,928,009 ops/sec ±0.65% (78 runs sampled)
|
||||
* regex constructor x 3,931,108 ops/sec ±0.58% (84 runs sampled)
|
||||
*/
|
||||
if (objPrototype === RegExp.prototype) {
|
||||
return 'RegExp';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* date x 2,130,074 ops/sec ±4.42% (68 runs sampled)
|
||||
* Post:
|
||||
* date x 3,953,779 ops/sec ±1.35% (77 runs sampled)
|
||||
*/
|
||||
if (objPrototype === Date.prototype) {
|
||||
return 'Date';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag)
|
||||
* ES6$25.4.5.4 - Promise.prototype[@@toStringTag] should be "Promise":
|
||||
* Test: `Object.prototype.toString.call(Promise.resolve())``
|
||||
* - Chrome <=47 === "[object Object]"
|
||||
* - Edge <=20 === "[object Object]"
|
||||
* - Firefox 29-Latest === "[object Promise]"
|
||||
* - Safari 7.1-Latest === "[object Promise]"
|
||||
*/
|
||||
if (promiseExists && objPrototype === Promise.prototype) {
|
||||
return 'Promise';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* set x 2,222,186 ops/sec ±1.31% (82 runs sampled)
|
||||
* Post:
|
||||
* set x 4,545,879 ops/sec ±1.13% (83 runs sampled)
|
||||
*/
|
||||
if (setExists && objPrototype === Set.prototype) {
|
||||
return 'Set';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* map x 2,396,842 ops/sec ±1.59% (81 runs sampled)
|
||||
* Post:
|
||||
* map x 4,183,945 ops/sec ±6.59% (82 runs sampled)
|
||||
*/
|
||||
if (mapExists && objPrototype === Map.prototype) {
|
||||
return 'Map';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* weakset x 1,323,220 ops/sec ±2.17% (76 runs sampled)
|
||||
* Post:
|
||||
* weakset x 4,237,510 ops/sec ±2.01% (77 runs sampled)
|
||||
*/
|
||||
if (weakSetExists && objPrototype === WeakSet.prototype) {
|
||||
return 'WeakSet';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* weakmap x 1,500,260 ops/sec ±2.02% (78 runs sampled)
|
||||
* Post:
|
||||
* weakmap x 3,881,384 ops/sec ±1.45% (82 runs sampled)
|
||||
*/
|
||||
if (weakMapExists && objPrototype === WeakMap.prototype) {
|
||||
return 'WeakMap';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag)
|
||||
* ES6$24.2.4.21 - DataView.prototype[@@toStringTag] should be "DataView":
|
||||
* Test: `Object.prototype.toString.call(new DataView(new ArrayBuffer(1)))``
|
||||
* - Edge <=13 === "[object Object]"
|
||||
*/
|
||||
if (dataViewExists && objPrototype === DataView.prototype) {
|
||||
return 'DataView';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag)
|
||||
* ES6$23.1.5.2.2 - %MapIteratorPrototype%[@@toStringTag] should be "Map Iterator":
|
||||
* Test: `Object.prototype.toString.call(new Map().entries())``
|
||||
* - Edge <=13 === "[object Object]"
|
||||
*/
|
||||
if (mapExists && objPrototype === mapIteratorPrototype) {
|
||||
return 'Map Iterator';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag)
|
||||
* ES6$23.2.5.2.2 - %SetIteratorPrototype%[@@toStringTag] should be "Set Iterator":
|
||||
* Test: `Object.prototype.toString.call(new Set().entries())``
|
||||
* - Edge <=13 === "[object Object]"
|
||||
*/
|
||||
if (setExists && objPrototype === setIteratorPrototype) {
|
||||
return 'Set Iterator';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag)
|
||||
* ES6$22.1.5.2.2 - %ArrayIteratorPrototype%[@@toStringTag] should be "Array Iterator":
|
||||
* Test: `Object.prototype.toString.call([][Symbol.iterator]())``
|
||||
* - Edge <=13 === "[object Object]"
|
||||
*/
|
||||
if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
|
||||
return 'Array Iterator';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag)
|
||||
* ES6$21.1.5.2.2 - %StringIteratorPrototype%[@@toStringTag] should be "String Iterator":
|
||||
* Test: `Object.prototype.toString.call(''[Symbol.iterator]())``
|
||||
* - Edge <=13 === "[object Object]"
|
||||
*/
|
||||
if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
|
||||
return 'String Iterator';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* object from null x 2,424,320 ops/sec ±1.67% (76 runs sampled)
|
||||
* Post:
|
||||
* object from null x 5,838,000 ops/sec ±0.99% (84 runs sampled)
|
||||
*/
|
||||
if (objPrototype === null) {
|
||||
return 'Object';
|
||||
}
|
||||
|
||||
return Object
|
||||
.prototype
|
||||
.toString
|
||||
.call(obj)
|
||||
.slice(toStringLeftSliceLength, toStringRightSliceLength);
|
||||
}
|
169
node_modules/type-detect/package.json
generated
vendored
Normal file
169
node_modules/type-detect/package.json
generated
vendored
Normal file
@ -0,0 +1,169 @@
|
||||
{
|
||||
"_from": "type-detect@^4.0.5",
|
||||
"_id": "type-detect@4.0.8",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
|
||||
"_location": "/type-detect",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "type-detect@^4.0.5",
|
||||
"name": "type-detect",
|
||||
"escapedName": "type-detect",
|
||||
"rawSpec": "^4.0.5",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^4.0.5"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/chai",
|
||||
"/deep-eql"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
|
||||
"_shasum": "7646fb5f18871cfbb7749e69bd39a6388eb7450c",
|
||||
"_spec": "type-detect@^4.0.5",
|
||||
"_where": "/Users/josh.burman/Projects/braid/node_modules/chai",
|
||||
"author": {
|
||||
"name": "Jake Luer",
|
||||
"email": "jake@alogicalparadox.com",
|
||||
"url": "http://alogicalparadox.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/chaijs/type-detect/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Keith Cirkel",
|
||||
"url": "https://github.com/keithamus"
|
||||
},
|
||||
{
|
||||
"name": "David Losert",
|
||||
"url": "https://github.com/davelosert"
|
||||
},
|
||||
{
|
||||
"name": "Aleksey Shvayka",
|
||||
"url": "https://github.com/shvaikalesh"
|
||||
},
|
||||
{
|
||||
"name": "Lucas Fernandes da Costa",
|
||||
"url": "https://github.com/lucasfcosta"
|
||||
},
|
||||
{
|
||||
"name": "Grant Snodgrass",
|
||||
"url": "https://github.com/meeber"
|
||||
},
|
||||
{
|
||||
"name": "Jeremy Tice",
|
||||
"url": "https://github.com/jetpacmonkey"
|
||||
},
|
||||
{
|
||||
"name": "Edward Betts",
|
||||
"url": "https://github.com/EdwardBetts"
|
||||
},
|
||||
{
|
||||
"name": "dvlsg",
|
||||
"url": "https://github.com/dvlsg"
|
||||
},
|
||||
{
|
||||
"name": "Amila Welihinda",
|
||||
"url": "https://github.com/amilajack"
|
||||
},
|
||||
{
|
||||
"name": "Jake Champion",
|
||||
"url": "https://github.com/JakeChampion"
|
||||
},
|
||||
{
|
||||
"name": "Miroslav Bajtoš",
|
||||
"url": "https://github.com/bajtos"
|
||||
}
|
||||
],
|
||||
"deprecated": false,
|
||||
"description": "Improved typeof detection for node.js and the browser.",
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^4.2.2",
|
||||
"benchmark": "^2.1.0",
|
||||
"buble": "^0.16.0",
|
||||
"codecov": "^3.0.0",
|
||||
"commitlint-config-angular": "^4.2.1",
|
||||
"cross-env": "^5.1.1",
|
||||
"eslint": "^4.10.0",
|
||||
"eslint-config-strict": "^14.0.0",
|
||||
"eslint-plugin-filenames": "^1.2.0",
|
||||
"husky": "^0.14.3",
|
||||
"karma": "^1.7.1",
|
||||
"karma-chrome-launcher": "^2.2.0",
|
||||
"karma-coverage": "^1.1.1",
|
||||
"karma-detect-browsers": "^2.2.5",
|
||||
"karma-edge-launcher": "^0.4.2",
|
||||
"karma-firefox-launcher": "^1.0.1",
|
||||
"karma-ie-launcher": "^1.0.0",
|
||||
"karma-mocha": "^1.3.0",
|
||||
"karma-opera-launcher": "^1.0.0",
|
||||
"karma-safari-launcher": "^1.0.0",
|
||||
"karma-safaritechpreview-launcher": "0.0.6",
|
||||
"karma-sauce-launcher": "^1.2.0",
|
||||
"mocha": "^4.0.1",
|
||||
"nyc": "^11.3.0",
|
||||
"rollup": "^0.50.0",
|
||||
"rollup-plugin-buble": "^0.16.0",
|
||||
"rollup-plugin-commonjs": "^8.2.6",
|
||||
"rollup-plugin-istanbul": "^1.1.0",
|
||||
"rollup-plugin-node-resolve": "^3.0.0",
|
||||
"semantic-release": "^8.2.0",
|
||||
"simple-assert": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"env": {
|
||||
"es6": true
|
||||
},
|
||||
"extends": [
|
||||
"strict/es6"
|
||||
],
|
||||
"globals": {
|
||||
"HTMLElement": false
|
||||
},
|
||||
"rules": {
|
||||
"complexity": 0,
|
||||
"max-statements": 0,
|
||||
"prefer-rest-params": 0
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"type-detect.js"
|
||||
],
|
||||
"homepage": "https://github.com/chaijs/type-detect#readme",
|
||||
"keywords": [
|
||||
"type",
|
||||
"typeof",
|
||||
"types"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./type-detect.js",
|
||||
"name": "type-detect",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/chaijs/type-detect.git"
|
||||
},
|
||||
"scripts": {
|
||||
"bench": "node bench",
|
||||
"build": "rollup -c rollup.conf.js",
|
||||
"commit-msg": "commitlint -x angular",
|
||||
"lint": "eslint --ignore-path .gitignore .",
|
||||
"posttest:browser": "npm run upload-coverage",
|
||||
"posttest:node": "nyc report --report-dir \"coverage/node-$(node --version)\" --reporter=lcovonly && npm run upload-coverage",
|
||||
"prepare": "cross-env NODE_ENV=production npm run build",
|
||||
"pretest:browser": "cross-env NODE_ENV=test npm run build",
|
||||
"pretest:node": "cross-env NODE_ENV=test npm run build",
|
||||
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
|
||||
"test": "npm run test:node && npm run test:browser",
|
||||
"test:browser": "karma start --singleRun=true",
|
||||
"test:node": "nyc mocha type-detect.test.js",
|
||||
"upload-coverage": "codecov"
|
||||
},
|
||||
"version": "4.0.8"
|
||||
}
|
388
node_modules/type-detect/type-detect.js
generated
vendored
Normal file
388
node_modules/type-detect/type-detect.js
generated
vendored
Normal file
@ -0,0 +1,388 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global.typeDetect = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
/* !
|
||||
* type-detect
|
||||
* Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
var promiseExists = typeof Promise === 'function';
|
||||
|
||||
/* eslint-disable no-undef */
|
||||
var globalObject = typeof self === 'object' ? self : global; // eslint-disable-line id-blacklist
|
||||
|
||||
var symbolExists = typeof Symbol !== 'undefined';
|
||||
var mapExists = typeof Map !== 'undefined';
|
||||
var setExists = typeof Set !== 'undefined';
|
||||
var weakMapExists = typeof WeakMap !== 'undefined';
|
||||
var weakSetExists = typeof WeakSet !== 'undefined';
|
||||
var dataViewExists = typeof DataView !== 'undefined';
|
||||
var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
|
||||
var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
|
||||
var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
|
||||
var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
|
||||
var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
|
||||
var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
|
||||
var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
|
||||
var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
|
||||
var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
|
||||
var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
|
||||
var toStringLeftSliceLength = 8;
|
||||
var toStringRightSliceLength = -1;
|
||||
/**
|
||||
* ### typeOf (obj)
|
||||
*
|
||||
* Uses `Object.prototype.toString` to determine the type of an object,
|
||||
* normalising behaviour across engine versions & well optimised.
|
||||
*
|
||||
* @param {Mixed} object
|
||||
* @return {String} object type
|
||||
* @api public
|
||||
*/
|
||||
function typeDetect(obj) {
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
|
||||
* boolean literal x 1,424,138 ops/sec ±4.54% (75 runs sampled)
|
||||
* number literal x 1,653,153 ops/sec ±1.91% (82 runs sampled)
|
||||
* undefined x 9,978,660 ops/sec ±1.92% (75 runs sampled)
|
||||
* function x 2,556,769 ops/sec ±1.73% (77 runs sampled)
|
||||
* Post:
|
||||
* string literal x 38,564,796 ops/sec ±1.15% (79 runs sampled)
|
||||
* boolean literal x 31,148,940 ops/sec ±1.10% (79 runs sampled)
|
||||
* number literal x 32,679,330 ops/sec ±1.90% (78 runs sampled)
|
||||
* undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
|
||||
* function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
|
||||
*/
|
||||
var typeofObj = typeof obj;
|
||||
if (typeofObj !== 'object') {
|
||||
return typeofObj;
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* null x 28,645,765 ops/sec ±1.17% (82 runs sampled)
|
||||
* Post:
|
||||
* null x 36,428,962 ops/sec ±1.37% (84 runs sampled)
|
||||
*/
|
||||
if (obj === null) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* Test: `Object.prototype.toString.call(window)``
|
||||
* - Node === "[object global]"
|
||||
* - Chrome === "[object global]"
|
||||
* - Firefox === "[object Window]"
|
||||
* - PhantomJS === "[object Window]"
|
||||
* - Safari === "[object Window]"
|
||||
* - IE 11 === "[object Window]"
|
||||
* - IE Edge === "[object Window]"
|
||||
* Test: `Object.prototype.toString.call(this)``
|
||||
* - Chrome Worker === "[object global]"
|
||||
* - Firefox Worker === "[object DedicatedWorkerGlobalScope]"
|
||||
* - Safari Worker === "[object DedicatedWorkerGlobalScope]"
|
||||
* - IE 11 Worker === "[object WorkerGlobalScope]"
|
||||
* - IE Edge Worker === "[object WorkerGlobalScope]"
|
||||
*/
|
||||
if (obj === globalObject) {
|
||||
return 'global';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* array literal x 2,888,352 ops/sec ±0.67% (82 runs sampled)
|
||||
* Post:
|
||||
* array literal x 22,479,650 ops/sec ±0.96% (81 runs sampled)
|
||||
*/
|
||||
if (
|
||||
Array.isArray(obj) &&
|
||||
(symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
|
||||
) {
|
||||
return 'Array';
|
||||
}
|
||||
|
||||
// Not caching existence of `window` and related properties due to potential
|
||||
// for `window` to be unset before tests in quasi-browser environments.
|
||||
if (typeof window === 'object' && window !== null) {
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/multipage/browsers.html#location)
|
||||
* WhatWG HTML$7.7.3 - The `Location` interface
|
||||
* Test: `Object.prototype.toString.call(window.location)``
|
||||
* - IE <=11 === "[object Object]"
|
||||
* - IE Edge <=13 === "[object Object]"
|
||||
*/
|
||||
if (typeof window.location === 'object' && obj === window.location) {
|
||||
return 'Location';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/#document)
|
||||
* WhatWG HTML$3.1.1 - The `Document` object
|
||||
* Note: Most browsers currently adher to the W3C DOM Level 2 spec
|
||||
* (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268)
|
||||
* which suggests that browsers should use HTMLTableCellElement for
|
||||
* both TD and TH elements. WhatWG separates these.
|
||||
* WhatWG HTML states:
|
||||
* > For historical reasons, Window objects must also have a
|
||||
* > writable, configurable, non-enumerable property named
|
||||
* > HTMLDocument whose value is the Document interface object.
|
||||
* Test: `Object.prototype.toString.call(document)``
|
||||
* - Chrome === "[object HTMLDocument]"
|
||||
* - Firefox === "[object HTMLDocument]"
|
||||
* - Safari === "[object HTMLDocument]"
|
||||
* - IE <=10 === "[object Document]"
|
||||
* - IE 11 === "[object HTMLDocument]"
|
||||
* - IE Edge <=13 === "[object HTMLDocument]"
|
||||
*/
|
||||
if (typeof window.document === 'object' && obj === window.document) {
|
||||
return 'Document';
|
||||
}
|
||||
|
||||
if (typeof window.navigator === 'object') {
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/multipage/webappapis.html#mimetypearray)
|
||||
* WhatWG HTML$8.6.1.5 - Plugins - Interface MimeTypeArray
|
||||
* Test: `Object.prototype.toString.call(navigator.mimeTypes)``
|
||||
* - IE <=10 === "[object MSMimeTypesCollection]"
|
||||
*/
|
||||
if (typeof window.navigator.mimeTypes === 'object' &&
|
||||
obj === window.navigator.mimeTypes) {
|
||||
return 'MimeTypeArray';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
|
||||
* WhatWG HTML$8.6.1.5 - Plugins - Interface PluginArray
|
||||
* Test: `Object.prototype.toString.call(navigator.plugins)``
|
||||
* - IE <=10 === "[object MSPluginsCollection]"
|
||||
*/
|
||||
if (typeof window.navigator.plugins === 'object' &&
|
||||
obj === window.navigator.plugins) {
|
||||
return 'PluginArray';
|
||||
}
|
||||
}
|
||||
|
||||
if ((typeof window.HTMLElement === 'function' ||
|
||||
typeof window.HTMLElement === 'object') &&
|
||||
obj instanceof window.HTMLElement) {
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
|
||||
* WhatWG HTML$4.4.4 - The `blockquote` element - Interface `HTMLQuoteElement`
|
||||
* Test: `Object.prototype.toString.call(document.createElement('blockquote'))``
|
||||
* - IE <=10 === "[object HTMLBlockElement]"
|
||||
*/
|
||||
if (obj.tagName === 'BLOCKQUOTE') {
|
||||
return 'HTMLQuoteElement';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/#htmltabledatacellelement)
|
||||
* WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableDataCellElement`
|
||||
* Note: Most browsers currently adher to the W3C DOM Level 2 spec
|
||||
* (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
|
||||
* which suggests that browsers should use HTMLTableCellElement for
|
||||
* both TD and TH elements. WhatWG separates these.
|
||||
* Test: Object.prototype.toString.call(document.createElement('td'))
|
||||
* - Chrome === "[object HTMLTableCellElement]"
|
||||
* - Firefox === "[object HTMLTableCellElement]"
|
||||
* - Safari === "[object HTMLTableCellElement]"
|
||||
*/
|
||||
if (obj.tagName === 'TD') {
|
||||
return 'HTMLTableDataCellElement';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (https://html.spec.whatwg.org/#htmltableheadercellelement)
|
||||
* WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableHeaderCellElement`
|
||||
* Note: Most browsers currently adher to the W3C DOM Level 2 spec
|
||||
* (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
|
||||
* which suggests that browsers should use HTMLTableCellElement for
|
||||
* both TD and TH elements. WhatWG separates these.
|
||||
* Test: Object.prototype.toString.call(document.createElement('th'))
|
||||
* - Chrome === "[object HTMLTableCellElement]"
|
||||
* - Firefox === "[object HTMLTableCellElement]"
|
||||
* - Safari === "[object HTMLTableCellElement]"
|
||||
*/
|
||||
if (obj.tagName === 'TH') {
|
||||
return 'HTMLTableHeaderCellElement';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* Float64Array x 625,644 ops/sec ±1.58% (80 runs sampled)
|
||||
* Float32Array x 1,279,852 ops/sec ±2.91% (77 runs sampled)
|
||||
* Uint32Array x 1,178,185 ops/sec ±1.95% (83 runs sampled)
|
||||
* Uint16Array x 1,008,380 ops/sec ±2.25% (80 runs sampled)
|
||||
* Uint8Array x 1,128,040 ops/sec ±2.11% (81 runs sampled)
|
||||
* Int32Array x 1,170,119 ops/sec ±2.88% (80 runs sampled)
|
||||
* Int16Array x 1,176,348 ops/sec ±5.79% (86 runs sampled)
|
||||
* Int8Array x 1,058,707 ops/sec ±4.94% (77 runs sampled)
|
||||
* Uint8ClampedArray x 1,110,633 ops/sec ±4.20% (80 runs sampled)
|
||||
* Post:
|
||||
* Float64Array x 7,105,671 ops/sec ±13.47% (64 runs sampled)
|
||||
* Float32Array x 5,887,912 ops/sec ±1.46% (82 runs sampled)
|
||||
* Uint32Array x 6,491,661 ops/sec ±1.76% (79 runs sampled)
|
||||
* Uint16Array x 6,559,795 ops/sec ±1.67% (82 runs sampled)
|
||||
* Uint8Array x 6,463,966 ops/sec ±1.43% (85 runs sampled)
|
||||
* Int32Array x 5,641,841 ops/sec ±3.49% (81 runs sampled)
|
||||
* Int16Array x 6,583,511 ops/sec ±1.98% (80 runs sampled)
|
||||
* Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
|
||||
* Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
|
||||
*/
|
||||
var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
|
||||
if (typeof stringTag === 'string') {
|
||||
return stringTag;
|
||||
}
|
||||
|
||||
var objPrototype = Object.getPrototypeOf(obj);
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
|
||||
* regex constructor x 2,143,634 ops/sec ±2.46% (78 runs sampled)
|
||||
* Post:
|
||||
* regex literal x 3,928,009 ops/sec ±0.65% (78 runs sampled)
|
||||
* regex constructor x 3,931,108 ops/sec ±0.58% (84 runs sampled)
|
||||
*/
|
||||
if (objPrototype === RegExp.prototype) {
|
||||
return 'RegExp';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* date x 2,130,074 ops/sec ±4.42% (68 runs sampled)
|
||||
* Post:
|
||||
* date x 3,953,779 ops/sec ±1.35% (77 runs sampled)
|
||||
*/
|
||||
if (objPrototype === Date.prototype) {
|
||||
return 'Date';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag)
|
||||
* ES6$25.4.5.4 - Promise.prototype[@@toStringTag] should be "Promise":
|
||||
* Test: `Object.prototype.toString.call(Promise.resolve())``
|
||||
* - Chrome <=47 === "[object Object]"
|
||||
* - Edge <=20 === "[object Object]"
|
||||
* - Firefox 29-Latest === "[object Promise]"
|
||||
* - Safari 7.1-Latest === "[object Promise]"
|
||||
*/
|
||||
if (promiseExists && objPrototype === Promise.prototype) {
|
||||
return 'Promise';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* set x 2,222,186 ops/sec ±1.31% (82 runs sampled)
|
||||
* Post:
|
||||
* set x 4,545,879 ops/sec ±1.13% (83 runs sampled)
|
||||
*/
|
||||
if (setExists && objPrototype === Set.prototype) {
|
||||
return 'Set';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* map x 2,396,842 ops/sec ±1.59% (81 runs sampled)
|
||||
* Post:
|
||||
* map x 4,183,945 ops/sec ±6.59% (82 runs sampled)
|
||||
*/
|
||||
if (mapExists && objPrototype === Map.prototype) {
|
||||
return 'Map';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* weakset x 1,323,220 ops/sec ±2.17% (76 runs sampled)
|
||||
* Post:
|
||||
* weakset x 4,237,510 ops/sec ±2.01% (77 runs sampled)
|
||||
*/
|
||||
if (weakSetExists && objPrototype === WeakSet.prototype) {
|
||||
return 'WeakSet';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* weakmap x 1,500,260 ops/sec ±2.02% (78 runs sampled)
|
||||
* Post:
|
||||
* weakmap x 3,881,384 ops/sec ±1.45% (82 runs sampled)
|
||||
*/
|
||||
if (weakMapExists && objPrototype === WeakMap.prototype) {
|
||||
return 'WeakMap';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag)
|
||||
* ES6$24.2.4.21 - DataView.prototype[@@toStringTag] should be "DataView":
|
||||
* Test: `Object.prototype.toString.call(new DataView(new ArrayBuffer(1)))``
|
||||
* - Edge <=13 === "[object Object]"
|
||||
*/
|
||||
if (dataViewExists && objPrototype === DataView.prototype) {
|
||||
return 'DataView';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag)
|
||||
* ES6$23.1.5.2.2 - %MapIteratorPrototype%[@@toStringTag] should be "Map Iterator":
|
||||
* Test: `Object.prototype.toString.call(new Map().entries())``
|
||||
* - Edge <=13 === "[object Object]"
|
||||
*/
|
||||
if (mapExists && objPrototype === mapIteratorPrototype) {
|
||||
return 'Map Iterator';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag)
|
||||
* ES6$23.2.5.2.2 - %SetIteratorPrototype%[@@toStringTag] should be "Set Iterator":
|
||||
* Test: `Object.prototype.toString.call(new Set().entries())``
|
||||
* - Edge <=13 === "[object Object]"
|
||||
*/
|
||||
if (setExists && objPrototype === setIteratorPrototype) {
|
||||
return 'Set Iterator';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag)
|
||||
* ES6$22.1.5.2.2 - %ArrayIteratorPrototype%[@@toStringTag] should be "Array Iterator":
|
||||
* Test: `Object.prototype.toString.call([][Symbol.iterator]())``
|
||||
* - Edge <=13 === "[object Object]"
|
||||
*/
|
||||
if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
|
||||
return 'Array Iterator';
|
||||
}
|
||||
|
||||
/* ! Spec Conformance
|
||||
* (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag)
|
||||
* ES6$21.1.5.2.2 - %StringIteratorPrototype%[@@toStringTag] should be "String Iterator":
|
||||
* Test: `Object.prototype.toString.call(''[Symbol.iterator]())``
|
||||
* - Edge <=13 === "[object Object]"
|
||||
*/
|
||||
if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
|
||||
return 'String Iterator';
|
||||
}
|
||||
|
||||
/* ! Speed optimisation
|
||||
* Pre:
|
||||
* object from null x 2,424,320 ops/sec ±1.67% (76 runs sampled)
|
||||
* Post:
|
||||
* object from null x 5,838,000 ops/sec ±0.99% (84 runs sampled)
|
||||
*/
|
||||
if (objPrototype === null) {
|
||||
return 'Object';
|
||||
}
|
||||
|
||||
return Object
|
||||
.prototype
|
||||
.toString
|
||||
.call(obj)
|
||||
.slice(toStringLeftSliceLength, toStringRightSliceLength);
|
||||
}
|
||||
|
||||
return typeDetect;
|
||||
|
||||
})));
|
Reference in New Issue
Block a user