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