1516eca3923a1e89d4ebc131816efa661c3465bb
[yaffs-website] / node_modules / grunt-legacy-util / node_modules / lodash / _getTag.js
1 var Map = require('./_Map'),
2     Set = require('./_Set'),
3     WeakMap = require('./_WeakMap');
4
5 /** `Object#toString` result references. */
6 var mapTag = '[object Map]',
7     objectTag = '[object Object]',
8     setTag = '[object Set]',
9     weakMapTag = '[object WeakMap]';
10
11 /** Used for built-in method references. */
12 var objectProto = Object.prototype;
13
14 /** Used to resolve the decompiled source of functions. */
15 var funcToString = Function.prototype.toString;
16
17 /**
18  * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
19  * of values.
20  */
21 var objectToString = objectProto.toString;
22
23 /** Used to detect maps, sets, and weakmaps. */
24 var mapCtorString = Map ? funcToString.call(Map) : '',
25     setCtorString = Set ? funcToString.call(Set) : '',
26     weakMapCtorString = WeakMap ? funcToString.call(WeakMap) : '';
27
28 /**
29  * Gets the `toStringTag` of `value`.
30  *
31  * @private
32  * @param {*} value The value to query.
33  * @returns {string} Returns the `toStringTag`.
34  */
35 function getTag(value) {
36   return objectToString.call(value);
37 }
38
39 // Fallback for IE 11 providing `toStringTag` values for maps, sets, and weakmaps.
40 if ((Map && getTag(new Map) != mapTag) ||
41     (Set && getTag(new Set) != setTag) ||
42     (WeakMap && getTag(new WeakMap) != weakMapTag)) {
43   getTag = function(value) {
44     var result = objectToString.call(value),
45         Ctor = result == objectTag ? value.constructor : null,
46         ctorString = typeof Ctor == 'function' ? funcToString.call(Ctor) : '';
47
48     if (ctorString) {
49       switch (ctorString) {
50         case mapCtorString: return mapTag;
51         case setCtorString: return setTag;
52         case weakMapCtorString: return weakMapTag;
53       }
54     }
55     return result;
56   };
57 }
58
59 module.exports = getTag;