Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

deep-eql.js 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.deepEqual = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. 'use strict';
  3. /* globals Symbol: false, Uint8Array: false, WeakMap: false */
  4. /*!
  5. * deep-eql
  6. * Copyright(c) 2013 Jake Luer <jake@alogicalparadox.com>
  7. * MIT Licensed
  8. */
  9. var type = require('type-detect');
  10. function FakeMap() {
  11. this._key = 'chai/deep-eql__' + Math.random() + Date.now();
  12. }
  13. FakeMap.prototype = {
  14. get: function getMap(key) {
  15. return key[this._key];
  16. },
  17. set: function setMap(key, value) {
  18. if (Object.isExtensible(key)) {
  19. Object.defineProperty(key, this._key, {
  20. value: value,
  21. configurable: true,
  22. });
  23. }
  24. },
  25. };
  26. var MemoizeMap = typeof WeakMap === 'function' ? WeakMap : FakeMap;
  27. /*!
  28. * Check to see if the MemoizeMap has recorded a result of the two operands
  29. *
  30. * @param {Mixed} leftHandOperand
  31. * @param {Mixed} rightHandOperand
  32. * @param {MemoizeMap} memoizeMap
  33. * @returns {Boolean|null} result
  34. */
  35. function memoizeCompare(leftHandOperand, rightHandOperand, memoizeMap) {
  36. // Technically, WeakMap keys can *only* be objects, not primitives.
  37. if (!memoizeMap || isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
  38. return null;
  39. }
  40. var leftHandMap = memoizeMap.get(leftHandOperand);
  41. if (leftHandMap) {
  42. var result = leftHandMap.get(rightHandOperand);
  43. if (typeof result === 'boolean') {
  44. return result;
  45. }
  46. }
  47. return null;
  48. }
  49. /*!
  50. * Set the result of the equality into the MemoizeMap
  51. *
  52. * @param {Mixed} leftHandOperand
  53. * @param {Mixed} rightHandOperand
  54. * @param {MemoizeMap} memoizeMap
  55. * @param {Boolean} result
  56. */
  57. function memoizeSet(leftHandOperand, rightHandOperand, memoizeMap, result) {
  58. // Technically, WeakMap keys can *only* be objects, not primitives.
  59. if (!memoizeMap || isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
  60. return;
  61. }
  62. var leftHandMap = memoizeMap.get(leftHandOperand);
  63. if (leftHandMap) {
  64. leftHandMap.set(rightHandOperand, result);
  65. } else {
  66. leftHandMap = new MemoizeMap();
  67. leftHandMap.set(rightHandOperand, result);
  68. memoizeMap.set(leftHandOperand, leftHandMap);
  69. }
  70. }
  71. /*!
  72. * Primary Export
  73. */
  74. module.exports = deepEqual;
  75. module.exports.MemoizeMap = MemoizeMap;
  76. /**
  77. * Assert deeply nested sameValue equality between two objects of any type.
  78. *
  79. * @param {Mixed} leftHandOperand
  80. * @param {Mixed} rightHandOperand
  81. * @param {Object} [options] (optional) Additional options
  82. * @param {Array} [options.comparator] (optional) Override default algorithm, determining custom equality.
  83. * @param {Array} [options.memoize] (optional) Provide a custom memoization object which will cache the results of
  84. complex objects for a speed boost. By passing `false` you can disable memoization, but this will cause circular
  85. references to blow the stack.
  86. * @return {Boolean} equal match
  87. */
  88. function deepEqual(leftHandOperand, rightHandOperand, options) {
  89. // If we have a comparator, we can't assume anything; so bail to its check first.
  90. if (options && options.comparator) {
  91. return extensiveDeepEqual(leftHandOperand, rightHandOperand, options);
  92. }
  93. var simpleResult = simpleEqual(leftHandOperand, rightHandOperand);
  94. if (simpleResult !== null) {
  95. return simpleResult;
  96. }
  97. // Deeper comparisons are pushed through to a larger function
  98. return extensiveDeepEqual(leftHandOperand, rightHandOperand, options);
  99. }
  100. /**
  101. * Many comparisons can be canceled out early via simple equality or primitive checks.
  102. * @param {Mixed} leftHandOperand
  103. * @param {Mixed} rightHandOperand
  104. * @return {Boolean|null} equal match
  105. */
  106. function simpleEqual(leftHandOperand, rightHandOperand) {
  107. // Equal references (except for Numbers) can be returned early
  108. if (leftHandOperand === rightHandOperand) {
  109. // Handle +-0 cases
  110. return leftHandOperand !== 0 || 1 / leftHandOperand === 1 / rightHandOperand;
  111. }
  112. // handle NaN cases
  113. if (
  114. leftHandOperand !== leftHandOperand && // eslint-disable-line no-self-compare
  115. rightHandOperand !== rightHandOperand // eslint-disable-line no-self-compare
  116. ) {
  117. return true;
  118. }
  119. // Anything that is not an 'object', i.e. symbols, functions, booleans, numbers,
  120. // strings, and undefined, can be compared by reference.
  121. if (isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
  122. // Easy out b/c it would have passed the first equality check
  123. return false;
  124. }
  125. return null;
  126. }
  127. /*!
  128. * The main logic of the `deepEqual` function.
  129. *
  130. * @param {Mixed} leftHandOperand
  131. * @param {Mixed} rightHandOperand
  132. * @param {Object} [options] (optional) Additional options
  133. * @param {Array} [options.comparator] (optional) Override default algorithm, determining custom equality.
  134. * @param {Array} [options.memoize] (optional) Provide a custom memoization object which will cache the results of
  135. complex objects for a speed boost. By passing `false` you can disable memoization, but this will cause circular
  136. references to blow the stack.
  137. * @return {Boolean} equal match
  138. */
  139. function extensiveDeepEqual(leftHandOperand, rightHandOperand, options) {
  140. options = options || {};
  141. options.memoize = options.memoize === false ? false : options.memoize || new MemoizeMap();
  142. var comparator = options && options.comparator;
  143. // Check if a memoized result exists.
  144. var memoizeResultLeft = memoizeCompare(leftHandOperand, rightHandOperand, options.memoize);
  145. if (memoizeResultLeft !== null) {
  146. return memoizeResultLeft;
  147. }
  148. var memoizeResultRight = memoizeCompare(rightHandOperand, leftHandOperand, options.memoize);
  149. if (memoizeResultRight !== null) {
  150. return memoizeResultRight;
  151. }
  152. // If a comparator is present, use it.
  153. if (comparator) {
  154. var comparatorResult = comparator(leftHandOperand, rightHandOperand);
  155. // Comparators may return null, in which case we want to go back to default behavior.
  156. if (comparatorResult === false || comparatorResult === true) {
  157. memoizeSet(leftHandOperand, rightHandOperand, options.memoize, comparatorResult);
  158. return comparatorResult;
  159. }
  160. // To allow comparators to override *any* behavior, we ran them first. Since it didn't decide
  161. // what to do, we need to make sure to return the basic tests first before we move on.
  162. var simpleResult = simpleEqual(leftHandOperand, rightHandOperand);
  163. if (simpleResult !== null) {
  164. // Don't memoize this, it takes longer to set/retrieve than to just compare.
  165. return simpleResult;
  166. }
  167. }
  168. var leftHandType = type(leftHandOperand);
  169. if (leftHandType !== type(rightHandOperand)) {
  170. memoizeSet(leftHandOperand, rightHandOperand, options.memoize, false);
  171. return false;
  172. }
  173. // Temporarily set the operands in the memoize object to prevent blowing the stack
  174. memoizeSet(leftHandOperand, rightHandOperand, options.memoize, true);
  175. var result = extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandType, options);
  176. memoizeSet(leftHandOperand, rightHandOperand, options.memoize, result);
  177. return result;
  178. }
  179. function extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandType, options) {
  180. switch (leftHandType) {
  181. case 'String':
  182. case 'Number':
  183. case 'Boolean':
  184. case 'Date':
  185. // If these types are their instance types (e.g. `new Number`) then re-deepEqual against their values
  186. return deepEqual(leftHandOperand.valueOf(), rightHandOperand.valueOf());
  187. case 'Promise':
  188. case 'Symbol':
  189. case 'function':
  190. case 'WeakMap':
  191. case 'WeakSet':
  192. case 'Error':
  193. return leftHandOperand === rightHandOperand;
  194. case 'Arguments':
  195. case 'Int8Array':
  196. case 'Uint8Array':
  197. case 'Uint8ClampedArray':
  198. case 'Int16Array':
  199. case 'Uint16Array':
  200. case 'Int32Array':
  201. case 'Uint32Array':
  202. case 'Float32Array':
  203. case 'Float64Array':
  204. case 'Array':
  205. return iterableEqual(leftHandOperand, rightHandOperand, options);
  206. case 'RegExp':
  207. return regexpEqual(leftHandOperand, rightHandOperand);
  208. case 'Generator':
  209. return generatorEqual(leftHandOperand, rightHandOperand, options);
  210. case 'DataView':
  211. return iterableEqual(new Uint8Array(leftHandOperand.buffer), new Uint8Array(rightHandOperand.buffer), options);
  212. case 'ArrayBuffer':
  213. return iterableEqual(new Uint8Array(leftHandOperand), new Uint8Array(rightHandOperand), options);
  214. case 'Set':
  215. return entriesEqual(leftHandOperand, rightHandOperand, options);
  216. case 'Map':
  217. return entriesEqual(leftHandOperand, rightHandOperand, options);
  218. default:
  219. return objectEqual(leftHandOperand, rightHandOperand, options);
  220. }
  221. }
  222. /*!
  223. * Compare two Regular Expressions for equality.
  224. *
  225. * @param {RegExp} leftHandOperand
  226. * @param {RegExp} rightHandOperand
  227. * @return {Boolean} result
  228. */
  229. function regexpEqual(leftHandOperand, rightHandOperand) {
  230. return leftHandOperand.toString() === rightHandOperand.toString();
  231. }
  232. /*!
  233. * Compare two Sets/Maps for equality. Faster than other equality functions.
  234. *
  235. * @param {Set} leftHandOperand
  236. * @param {Set} rightHandOperand
  237. * @param {Object} [options] (Optional)
  238. * @return {Boolean} result
  239. */
  240. function entriesEqual(leftHandOperand, rightHandOperand, options) {
  241. // IE11 doesn't support Set#entries or Set#@@iterator, so we need manually populate using Set#forEach
  242. if (leftHandOperand.size !== rightHandOperand.size) {
  243. return false;
  244. }
  245. if (leftHandOperand.size === 0) {
  246. return true;
  247. }
  248. var leftHandItems = [];
  249. var rightHandItems = [];
  250. leftHandOperand.forEach(function gatherEntries(key, value) {
  251. leftHandItems.push([ key, value ]);
  252. });
  253. rightHandOperand.forEach(function gatherEntries(key, value) {
  254. rightHandItems.push([ key, value ]);
  255. });
  256. return iterableEqual(leftHandItems.sort(), rightHandItems.sort(), options);
  257. }
  258. /*!
  259. * Simple equality for flat iterable objects such as Arrays, TypedArrays or Node.js buffers.
  260. *
  261. * @param {Iterable} leftHandOperand
  262. * @param {Iterable} rightHandOperand
  263. * @param {Object} [options] (Optional)
  264. * @return {Boolean} result
  265. */
  266. function iterableEqual(leftHandOperand, rightHandOperand, options) {
  267. var length = leftHandOperand.length;
  268. if (length !== rightHandOperand.length) {
  269. return false;
  270. }
  271. if (length === 0) {
  272. return true;
  273. }
  274. var index = -1;
  275. while (++index < length) {
  276. if (deepEqual(leftHandOperand[index], rightHandOperand[index], options) === false) {
  277. return false;
  278. }
  279. }
  280. return true;
  281. }
  282. /*!
  283. * Simple equality for generator objects such as those returned by generator functions.
  284. *
  285. * @param {Iterable} leftHandOperand
  286. * @param {Iterable} rightHandOperand
  287. * @param {Object} [options] (Optional)
  288. * @return {Boolean} result
  289. */
  290. function generatorEqual(leftHandOperand, rightHandOperand, options) {
  291. return iterableEqual(getGeneratorEntries(leftHandOperand), getGeneratorEntries(rightHandOperand), options);
  292. }
  293. /*!
  294. * Determine if the given object has an @@iterator function.
  295. *
  296. * @param {Object} target
  297. * @return {Boolean} `true` if the object has an @@iterator function.
  298. */
  299. function hasIteratorFunction(target) {
  300. return typeof Symbol !== 'undefined' &&
  301. typeof target === 'object' &&
  302. typeof Symbol.iterator !== 'undefined' &&
  303. typeof target[Symbol.iterator] === 'function';
  304. }
  305. /*!
  306. * Gets all iterator entries from the given Object. If the Object has no @@iterator function, returns an empty array.
  307. * This will consume the iterator - which could have side effects depending on the @@iterator implementation.
  308. *
  309. * @param {Object} target
  310. * @returns {Array} an array of entries from the @@iterator function
  311. */
  312. function getIteratorEntries(target) {
  313. if (hasIteratorFunction(target)) {
  314. try {
  315. return getGeneratorEntries(target[Symbol.iterator]());
  316. } catch (iteratorError) {
  317. return [];
  318. }
  319. }
  320. return [];
  321. }
  322. /*!
  323. * Gets all entries from a Generator. This will consume the generator - which could have side effects.
  324. *
  325. * @param {Generator} target
  326. * @returns {Array} an array of entries from the Generator.
  327. */
  328. function getGeneratorEntries(generator) {
  329. var generatorResult = generator.next();
  330. var accumulator = [ generatorResult.value ];
  331. while (generatorResult.done === false) {
  332. generatorResult = generator.next();
  333. accumulator.push(generatorResult.value);
  334. }
  335. return accumulator;
  336. }
  337. /*!
  338. * Gets all own and inherited enumerable keys from a target.
  339. *
  340. * @param {Object} target
  341. * @returns {Array} an array of own and inherited enumerable keys from the target.
  342. */
  343. function getEnumerableKeys(target) {
  344. var keys = [];
  345. for (var key in target) {
  346. keys.push(key);
  347. }
  348. return keys;
  349. }
  350. /*!
  351. * Determines if two objects have matching values, given a set of keys. Defers to deepEqual for the equality check of
  352. * each key. If any value of the given key is not equal, the function will return false (early).
  353. *
  354. * @param {Mixed} leftHandOperand
  355. * @param {Mixed} rightHandOperand
  356. * @param {Array} keys An array of keys to compare the values of leftHandOperand and rightHandOperand against
  357. * @param {Object} [options] (Optional)
  358. * @return {Boolean} result
  359. */
  360. function keysEqual(leftHandOperand, rightHandOperand, keys, options) {
  361. var length = keys.length;
  362. if (length === 0) {
  363. return true;
  364. }
  365. for (var i = 0; i < length; i += 1) {
  366. if (deepEqual(leftHandOperand[keys[i]], rightHandOperand[keys[i]], options) === false) {
  367. return false;
  368. }
  369. }
  370. return true;
  371. }
  372. /*!
  373. * Recursively check the equality of two Objects. Once basic sameness has been established it will defer to `deepEqual`
  374. * for each enumerable key in the object.
  375. *
  376. * @param {Mixed} leftHandOperand
  377. * @param {Mixed} rightHandOperand
  378. * @param {Object} [options] (Optional)
  379. * @return {Boolean} result
  380. */
  381. function objectEqual(leftHandOperand, rightHandOperand, options) {
  382. var leftHandKeys = getEnumerableKeys(leftHandOperand);
  383. var rightHandKeys = getEnumerableKeys(rightHandOperand);
  384. if (leftHandKeys.length && leftHandKeys.length === rightHandKeys.length) {
  385. leftHandKeys.sort();
  386. rightHandKeys.sort();
  387. if (iterableEqual(leftHandKeys, rightHandKeys) === false) {
  388. return false;
  389. }
  390. return keysEqual(leftHandOperand, rightHandOperand, leftHandKeys, options);
  391. }
  392. var leftHandEntries = getIteratorEntries(leftHandOperand);
  393. var rightHandEntries = getIteratorEntries(rightHandOperand);
  394. if (leftHandEntries.length && leftHandEntries.length === rightHandEntries.length) {
  395. leftHandEntries.sort();
  396. rightHandEntries.sort();
  397. return iterableEqual(leftHandEntries, rightHandEntries, options);
  398. }
  399. if (leftHandKeys.length === 0 &&
  400. leftHandEntries.length === 0 &&
  401. rightHandKeys.length === 0 &&
  402. rightHandEntries.length === 0) {
  403. return true;
  404. }
  405. return false;
  406. }
  407. /*!
  408. * Returns true if the argument is a primitive.
  409. *
  410. * This intentionally returns true for all objects that can be compared by reference,
  411. * including functions and symbols.
  412. *
  413. * @param {Mixed} value
  414. * @return {Boolean} result
  415. */
  416. function isPrimitive(value) {
  417. return value === null || typeof value !== 'object';
  418. }
  419. },{"type-detect":2}],2:[function(require,module,exports){
  420. (function (global){
  421. 'use strict';
  422. /* !
  423. * type-detect
  424. * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
  425. * MIT Licensed
  426. */
  427. var promiseExists = typeof Promise === 'function';
  428. var globalObject = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : self; // eslint-disable-line
  429. var isDom = 'location' in globalObject && 'document' in globalObject;
  430. var symbolExists = typeof Symbol !== 'undefined';
  431. var mapExists = typeof Map !== 'undefined';
  432. var setExists = typeof Set !== 'undefined';
  433. var weakMapExists = typeof WeakMap !== 'undefined';
  434. var weakSetExists = typeof WeakSet !== 'undefined';
  435. var dataViewExists = typeof DataView !== 'undefined';
  436. var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
  437. var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
  438. var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
  439. var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
  440. var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
  441. var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
  442. var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
  443. var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
  444. var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
  445. var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
  446. var toStringLeftSliceLength = 8;
  447. var toStringRightSliceLength = -1;
  448. /**
  449. * ### typeOf (obj)
  450. *
  451. * Uses `Object.prototype.toString` to determine the type of an object,
  452. * normalising behaviour across engine versions & well optimised.
  453. *
  454. * @param {Mixed} object
  455. * @return {String} object type
  456. * @api public
  457. */
  458. module.exports = function typeDetect(obj) {
  459. /* ! Speed optimisation
  460. * Pre:
  461. * string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
  462. * boolean literal x 1,424,138 ops/sec ±4.54% (75 runs sampled)
  463. * number literal x 1,653,153 ops/sec ±1.91% (82 runs sampled)
  464. * undefined x 9,978,660 ops/sec ±1.92% (75 runs sampled)
  465. * function x 2,556,769 ops/sec ±1.73% (77 runs sampled)
  466. * Post:
  467. * string literal x 38,564,796 ops/sec ±1.15% (79 runs sampled)
  468. * boolean literal x 31,148,940 ops/sec ±1.10% (79 runs sampled)
  469. * number literal x 32,679,330 ops/sec ±1.90% (78 runs sampled)
  470. * undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
  471. * function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
  472. */
  473. var typeofObj = typeof obj;
  474. if (typeofObj !== 'object') {
  475. return typeofObj;
  476. }
  477. /* ! Speed optimisation
  478. * Pre:
  479. * null x 28,645,765 ops/sec ±1.17% (82 runs sampled)
  480. * Post:
  481. * null x 36,428,962 ops/sec ±1.37% (84 runs sampled)
  482. */
  483. if (obj === null) {
  484. return 'null';
  485. }
  486. /* ! Spec Conformance
  487. * Test: `Object.prototype.toString.call(window)``
  488. * - Node === "[object global]"
  489. * - Chrome === "[object global]"
  490. * - Firefox === "[object Window]"
  491. * - PhantomJS === "[object Window]"
  492. * - Safari === "[object Window]"
  493. * - IE 11 === "[object Window]"
  494. * - IE Edge === "[object Window]"
  495. * Test: `Object.prototype.toString.call(this)``
  496. * - Chrome Worker === "[object global]"
  497. * - Firefox Worker === "[object DedicatedWorkerGlobalScope]"
  498. * - Safari Worker === "[object DedicatedWorkerGlobalScope]"
  499. * - IE 11 Worker === "[object WorkerGlobalScope]"
  500. * - IE Edge Worker === "[object WorkerGlobalScope]"
  501. */
  502. if (obj === globalObject) {
  503. return 'global';
  504. }
  505. /* ! Speed optimisation
  506. * Pre:
  507. * array literal x 2,888,352 ops/sec ±0.67% (82 runs sampled)
  508. * Post:
  509. * array literal x 22,479,650 ops/sec ±0.96% (81 runs sampled)
  510. */
  511. if (
  512. Array.isArray(obj) &&
  513. (symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
  514. ) {
  515. return 'Array';
  516. }
  517. if (isDom) {
  518. /* ! Spec Conformance
  519. * (https://html.spec.whatwg.org/multipage/browsers.html#location)
  520. * WhatWG HTML$7.7.3 - The `Location` interface
  521. * Test: `Object.prototype.toString.call(window.location)``
  522. * - IE <=11 === "[object Object]"
  523. * - IE Edge <=13 === "[object Object]"
  524. */
  525. if (obj === globalObject.location) {
  526. return 'Location';
  527. }
  528. /* ! Spec Conformance
  529. * (https://html.spec.whatwg.org/#document)
  530. * WhatWG HTML$3.1.1 - The `Document` object
  531. * Note: Most browsers currently adher to the W3C DOM Level 2 spec
  532. * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268)
  533. * which suggests that browsers should use HTMLTableCellElement for
  534. * both TD and TH elements. WhatWG separates these.
  535. * WhatWG HTML states:
  536. * > For historical reasons, Window objects must also have a
  537. * > writable, configurable, non-enumerable property named
  538. * > HTMLDocument whose value is the Document interface object.
  539. * Test: `Object.prototype.toString.call(document)``
  540. * - Chrome === "[object HTMLDocument]"
  541. * - Firefox === "[object HTMLDocument]"
  542. * - Safari === "[object HTMLDocument]"
  543. * - IE <=10 === "[object Document]"
  544. * - IE 11 === "[object HTMLDocument]"
  545. * - IE Edge <=13 === "[object HTMLDocument]"
  546. */
  547. if (obj === globalObject.document) {
  548. return 'Document';
  549. }
  550. /* ! Spec Conformance
  551. * (https://html.spec.whatwg.org/multipage/webappapis.html#mimetypearray)
  552. * WhatWG HTML$8.6.1.5 - Plugins - Interface MimeTypeArray
  553. * Test: `Object.prototype.toString.call(navigator.mimeTypes)``
  554. * - IE <=10 === "[object MSMimeTypesCollection]"
  555. */
  556. if (obj === (globalObject.navigator || {}).mimeTypes) {
  557. return 'MimeTypeArray';
  558. }
  559. /* ! Spec Conformance
  560. * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
  561. * WhatWG HTML$8.6.1.5 - Plugins - Interface PluginArray
  562. * Test: `Object.prototype.toString.call(navigator.plugins)``
  563. * - IE <=10 === "[object MSPluginsCollection]"
  564. */
  565. if (obj === (globalObject.navigator || {}).plugins) {
  566. return 'PluginArray';
  567. }
  568. /* ! Spec Conformance
  569. * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
  570. * WhatWG HTML$4.4.4 - The `blockquote` element - Interface `HTMLQuoteElement`
  571. * Test: `Object.prototype.toString.call(document.createElement('blockquote'))``
  572. * - IE <=10 === "[object HTMLBlockElement]"
  573. */
  574. if (obj instanceof HTMLElement && obj.tagName === 'BLOCKQUOTE') {
  575. return 'HTMLQuoteElement';
  576. }
  577. /* ! Spec Conformance
  578. * (https://html.spec.whatwg.org/#htmltabledatacellelement)
  579. * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableDataCellElement`
  580. * Note: Most browsers currently adher to the W3C DOM Level 2 spec
  581. * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
  582. * which suggests that browsers should use HTMLTableCellElement for
  583. * both TD and TH elements. WhatWG separates these.
  584. * Test: Object.prototype.toString.call(document.createElement('td'))
  585. * - Chrome === "[object HTMLTableCellElement]"
  586. * - Firefox === "[object HTMLTableCellElement]"
  587. * - Safari === "[object HTMLTableCellElement]"
  588. */
  589. if (obj instanceof HTMLElement && obj.tagName === 'TD') {
  590. return 'HTMLTableDataCellElement';
  591. }
  592. /* ! Spec Conformance
  593. * (https://html.spec.whatwg.org/#htmltableheadercellelement)
  594. * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableHeaderCellElement`
  595. * Note: Most browsers currently adher to the W3C DOM Level 2 spec
  596. * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
  597. * which suggests that browsers should use HTMLTableCellElement for
  598. * both TD and TH elements. WhatWG separates these.
  599. * Test: Object.prototype.toString.call(document.createElement('th'))
  600. * - Chrome === "[object HTMLTableCellElement]"
  601. * - Firefox === "[object HTMLTableCellElement]"
  602. * - Safari === "[object HTMLTableCellElement]"
  603. */
  604. if (obj instanceof HTMLElement && obj.tagName === 'TH') {
  605. return 'HTMLTableHeaderCellElement';
  606. }
  607. }
  608. /* ! Speed optimisation
  609. * Pre:
  610. * Float64Array x 625,644 ops/sec ±1.58% (80 runs sampled)
  611. * Float32Array x 1,279,852 ops/sec ±2.91% (77 runs sampled)
  612. * Uint32Array x 1,178,185 ops/sec ±1.95% (83 runs sampled)
  613. * Uint16Array x 1,008,380 ops/sec ±2.25% (80 runs sampled)
  614. * Uint8Array x 1,128,040 ops/sec ±2.11% (81 runs sampled)
  615. * Int32Array x 1,170,119 ops/sec ±2.88% (80 runs sampled)
  616. * Int16Array x 1,176,348 ops/sec ±5.79% (86 runs sampled)
  617. * Int8Array x 1,058,707 ops/sec ±4.94% (77 runs sampled)
  618. * Uint8ClampedArray x 1,110,633 ops/sec ±4.20% (80 runs sampled)
  619. * Post:
  620. * Float64Array x 7,105,671 ops/sec ±13.47% (64 runs sampled)
  621. * Float32Array x 5,887,912 ops/sec ±1.46% (82 runs sampled)
  622. * Uint32Array x 6,491,661 ops/sec ±1.76% (79 runs sampled)
  623. * Uint16Array x 6,559,795 ops/sec ±1.67% (82 runs sampled)
  624. * Uint8Array x 6,463,966 ops/sec ±1.43% (85 runs sampled)
  625. * Int32Array x 5,641,841 ops/sec ±3.49% (81 runs sampled)
  626. * Int16Array x 6,583,511 ops/sec ±1.98% (80 runs sampled)
  627. * Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
  628. * Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
  629. */
  630. var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
  631. if (typeof stringTag === 'string') {
  632. return stringTag;
  633. }
  634. var objPrototype = Object.getPrototypeOf(obj);
  635. /* ! Speed optimisation
  636. * Pre:
  637. * regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
  638. * regex constructor x 2,143,634 ops/sec ±2.46% (78 runs sampled)
  639. * Post:
  640. * regex literal x 3,928,009 ops/sec ±0.65% (78 runs sampled)
  641. * regex constructor x 3,931,108 ops/sec ±0.58% (84 runs sampled)
  642. */
  643. if (objPrototype === RegExp.prototype) {
  644. return 'RegExp';
  645. }
  646. /* ! Speed optimisation
  647. * Pre:
  648. * date x 2,130,074 ops/sec ±4.42% (68 runs sampled)
  649. * Post:
  650. * date x 3,953,779 ops/sec ±1.35% (77 runs sampled)
  651. */
  652. if (objPrototype === Date.prototype) {
  653. return 'Date';
  654. }
  655. /* ! Spec Conformance
  656. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag)
  657. * ES6$25.4.5.4 - Promise.prototype[@@toStringTag] should be "Promise":
  658. * Test: `Object.prototype.toString.call(Promise.resolve())``
  659. * - Chrome <=47 === "[object Object]"
  660. * - Edge <=20 === "[object Object]"
  661. * - Firefox 29-Latest === "[object Promise]"
  662. * - Safari 7.1-Latest === "[object Promise]"
  663. */
  664. if (promiseExists && objPrototype === Promise.prototype) {
  665. return 'Promise';
  666. }
  667. /* ! Speed optimisation
  668. * Pre:
  669. * set x 2,222,186 ops/sec ±1.31% (82 runs sampled)
  670. * Post:
  671. * set x 4,545,879 ops/sec ±1.13% (83 runs sampled)
  672. */
  673. if (setExists && objPrototype === Set.prototype) {
  674. return 'Set';
  675. }
  676. /* ! Speed optimisation
  677. * Pre:
  678. * map x 2,396,842 ops/sec ±1.59% (81 runs sampled)
  679. * Post:
  680. * map x 4,183,945 ops/sec ±6.59% (82 runs sampled)
  681. */
  682. if (mapExists && objPrototype === Map.prototype) {
  683. return 'Map';
  684. }
  685. /* ! Speed optimisation
  686. * Pre:
  687. * weakset x 1,323,220 ops/sec ±2.17% (76 runs sampled)
  688. * Post:
  689. * weakset x 4,237,510 ops/sec ±2.01% (77 runs sampled)
  690. */
  691. if (weakSetExists && objPrototype === WeakSet.prototype) {
  692. return 'WeakSet';
  693. }
  694. /* ! Speed optimisation
  695. * Pre:
  696. * weakmap x 1,500,260 ops/sec ±2.02% (78 runs sampled)
  697. * Post:
  698. * weakmap x 3,881,384 ops/sec ±1.45% (82 runs sampled)
  699. */
  700. if (weakMapExists && objPrototype === WeakMap.prototype) {
  701. return 'WeakMap';
  702. }
  703. /* ! Spec Conformance
  704. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag)
  705. * ES6$24.2.4.21 - DataView.prototype[@@toStringTag] should be "DataView":
  706. * Test: `Object.prototype.toString.call(new DataView(new ArrayBuffer(1)))``
  707. * - Edge <=13 === "[object Object]"
  708. */
  709. if (dataViewExists && objPrototype === DataView.prototype) {
  710. return 'DataView';
  711. }
  712. /* ! Spec Conformance
  713. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag)
  714. * ES6$23.1.5.2.2 - %MapIteratorPrototype%[@@toStringTag] should be "Map Iterator":
  715. * Test: `Object.prototype.toString.call(new Map().entries())``
  716. * - Edge <=13 === "[object Object]"
  717. */
  718. if (mapExists && objPrototype === mapIteratorPrototype) {
  719. return 'Map Iterator';
  720. }
  721. /* ! Spec Conformance
  722. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag)
  723. * ES6$23.2.5.2.2 - %SetIteratorPrototype%[@@toStringTag] should be "Set Iterator":
  724. * Test: `Object.prototype.toString.call(new Set().entries())``
  725. * - Edge <=13 === "[object Object]"
  726. */
  727. if (setExists && objPrototype === setIteratorPrototype) {
  728. return 'Set Iterator';
  729. }
  730. /* ! Spec Conformance
  731. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag)
  732. * ES6$22.1.5.2.2 - %ArrayIteratorPrototype%[@@toStringTag] should be "Array Iterator":
  733. * Test: `Object.prototype.toString.call([][Symbol.iterator]())``
  734. * - Edge <=13 === "[object Object]"
  735. */
  736. if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
  737. return 'Array Iterator';
  738. }
  739. /* ! Spec Conformance
  740. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag)
  741. * ES6$21.1.5.2.2 - %StringIteratorPrototype%[@@toStringTag] should be "String Iterator":
  742. * Test: `Object.prototype.toString.call(''[Symbol.iterator]())``
  743. * - Edge <=13 === "[object Object]"
  744. */
  745. if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
  746. return 'String Iterator';
  747. }
  748. /* ! Speed optimisation
  749. * Pre:
  750. * object from null x 2,424,320 ops/sec ±1.67% (76 runs sampled)
  751. * Post:
  752. * object from null x 5,838,000 ops/sec ±0.99% (84 runs sampled)
  753. */
  754. if (objPrototype === null) {
  755. return 'Object';
  756. }
  757. return Object
  758. .prototype
  759. .toString
  760. .call(obj)
  761. .slice(toStringLeftSliceLength, toStringRightSliceLength);
  762. };
  763. module.exports.typeDetect = module.exports;
  764. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  765. },{}]},{},[1])(1)
  766. });