diff --git a/index.js b/index.js index 5b44368..d3d2d87 100644 --- a/index.js +++ b/index.js @@ -1,32 +1,14 @@ 'use strict'; -var $Map = typeof Map === 'function' && Map.prototype ? Map : null; -var $Set = typeof Set === 'function' && Set.prototype ? Set : null; +var $mapHas = typeof Map === 'function' && Map.prototype && Map.prototype.has; +var $setHas = typeof Set === 'function' && Set.prototype && Set.prototype.has; -if (!$Map) { - // eslint-disable-next-line no-unused-vars - module.exports = function isMap(x) { - // `Map` is not present in this environment. - return false; - }; - return; -} - -var $mapHas = $Map ? Map.prototype.has : null; -var $setHas = $Set ? Set.prototype.has : null; -if (!$mapHas) { - // eslint-disable-next-line no-unused-vars - module.exports = function isMap(x) { - // `Map` does not have a `has` method - return false; - }; - return; -} - -module.exports = function isMap(x) { - if (!x || typeof x !== 'object') { +module.exports = function isSet(x) { + if (!$mapHas || !x || typeof x !== 'object') { + // `Set` is either not present in this environment or does not have a `has` method, or the argument is of an incorrect type return false; } + try { $mapHas.call(x); if ($setHas) { @@ -36,7 +18,8 @@ module.exports = function isMap(x) { return true; } } - return x instanceof $Map; // core-js workaround, pre-v2.5.0 + return x instanceof Map; // core-js workaround, pre-v2.5.0 } catch (e) {} + return false; };