UNPKG

1.09 kBJavaScriptView Raw
1'use strict';
2var TO_STRING_TAG_SUPPORT = require('../internals/to-string-tag-support');
3var isCallable = require('../internals/is-callable');
4var classofRaw = require('../internals/classof-raw');
5var wellKnownSymbol = require('../internals/well-known-symbol');
6
7var TO_STRING_TAG = wellKnownSymbol('toStringTag');
8var $Object = Object;
9
10// ES3 wrong here
11var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) === 'Arguments';
12
13// fallback for IE11 Script Access Denied error
14var tryGet = function (it, key) {
15 try {
16 return it[key];
17 } catch (error) { /* empty */ }
18};
19
20// getting tag from ES6+ `Object.prototype.toString`
21module.exports = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) {
22 var O, tag, result;
23 return it === undefined ? 'Undefined' : it === null ? 'Null'
24 // @@toStringTag case
25 : typeof (tag = tryGet(O = $Object(it), TO_STRING_TAG)) == 'string' ? tag
26 // builtinTag case
27 : CORRECT_ARGUMENTS ? classofRaw(O)
28 // ES3 arguments fallback
29 : (result = classofRaw(O)) === 'Object' && isCallable(O.callee) ? 'Arguments' : result;
30};