source: imaps-frontend/node_modules/is-set/index.js

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