UNPKG

1.84 kBJavaScriptView Raw
1import DataView from './_DataView.js';
2import Map from './_Map.js';
3import Promise from './_Promise.js';
4import Set from './_Set.js';
5import WeakMap from './_WeakMap.js';
6import baseGetTag from './_baseGetTag.js';
7import toSource from './_toSource.js';
8
9/** `Object#toString` result references. */
10var mapTag = '[object Map]',
11 objectTag = '[object Object]',
12 promiseTag = '[object Promise]',
13 setTag = '[object Set]',
14 weakMapTag = '[object WeakMap]';
15
16var dataViewTag = '[object DataView]';
17
18/** Used to detect maps, sets, and weakmaps. */
19var dataViewCtorString = toSource(DataView),
20 mapCtorString = toSource(Map),
21 promiseCtorString = toSource(Promise),
22 setCtorString = toSource(Set),
23 weakMapCtorString = toSource(WeakMap);
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 */
32var getTag = baseGetTag;
33
34// Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
35if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
36 (Map && getTag(new Map) != mapTag) ||
37 (Promise && getTag(Promise.resolve()) != promiseTag) ||
38 (Set && getTag(new Set) != setTag) ||
39 (WeakMap && getTag(new WeakMap) != weakMapTag)) {
40 getTag = function(value) {
41 var result = baseGetTag(value),
42 Ctor = result == objectTag ? value.constructor : undefined,
43 ctorString = Ctor ? toSource(Ctor) : '';
44
45 if (ctorString) {
46 switch (ctorString) {
47 case dataViewCtorString: return dataViewTag;
48 case mapCtorString: return mapTag;
49 case promiseCtorString: return promiseTag;
50 case setCtorString: return setTag;
51 case weakMapCtorString: return weakMapTag;
52 }
53 }
54 return result;
55 };
56}
57
58export default getTag;