source: imaps-frontend/node_modules/is-map/index.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.0 KB
Line 
1'use strict';
2
3/** @const */
4var $Map = typeof Map === 'function' && Map.prototype ? Map : null;
5var $Set = typeof Set === 'function' && Set.prototype ? Set : null;
6
7var exported;
8
9if (!$Map) {
10 /** @type {import('.')} */
11 // eslint-disable-next-line no-unused-vars
12 exported = function isMap(x) {
13 // `Map` is not present in this environment.
14 return false;
15 };
16}
17
18var $mapHas = $Map ? Map.prototype.has : null;
19var $setHas = $Set ? Set.prototype.has : null;
20if (!exported && !$mapHas) {
21 /** @type {import('.')} */
22 // eslint-disable-next-line no-unused-vars
23 exported = function isMap(x) {
24 // `Map` does not have a `has` method
25 return false;
26 };
27}
28
29/** @type {import('.')} */
30module.exports = exported || function isMap(x) {
31 if (!x || typeof x !== 'object') {
32 return false;
33 }
34 try {
35 $mapHas.call(x);
36 if ($setHas) {
37 try {
38 $setHas.call(x);
39 } catch (e) {
40 return true;
41 }
42 }
43 // @ts-expect-error TS can't figure out that $Map is always truthy here
44 return x instanceof $Map; // core-js workaround, pre-v2.5.0
45 } catch (e) {}
46 return false;
47};
Note: See TracBrowser for help on using the repository browser.