index.js 904 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. var $Map = typeof Map === 'function' && Map.prototype ? Map : null;
  3. var $Set = typeof Set === 'function' && Set.prototype ? Set : null;
  4. var exported;
  5. if (!$Map) {
  6. // eslint-disable-next-line no-unused-vars
  7. exported = function isMap(x) {
  8. // `Map` is not present in this environment.
  9. return false;
  10. };
  11. }
  12. var $mapHas = $Map ? Map.prototype.has : null;
  13. var $setHas = $Set ? Set.prototype.has : null;
  14. if (!exported && !$mapHas) {
  15. // eslint-disable-next-line no-unused-vars
  16. exported = function isMap(x) {
  17. // `Map` does not have a `has` method
  18. return false;
  19. };
  20. }
  21. module.exports = exported || function isMap(x) {
  22. if (!x || typeof x !== 'object') {
  23. return false;
  24. }
  25. try {
  26. $mapHas.call(x);
  27. if ($setHas) {
  28. try {
  29. $setHas.call(x);
  30. } catch (e) {
  31. return true;
  32. }
  33. }
  34. return x instanceof $Map; // core-js workaround, pre-v2.5.0
  35. } catch (e) {}
  36. return false;
  37. };