source: imaps-frontend/node_modules/is-weakset/index.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.2 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4var callBound = require('call-bound');
5
6var $WeakSet = GetIntrinsic('%WeakSet%', true);
7
8/** @type {undefined | (<V>(thisArg: Set<V>, value: V) => boolean)} */
9var $setHas = callBound('WeakSet.prototype.has', true);
10
11if ($setHas) {
12 /** @type {undefined | (<K extends object, V>(thisArg: WeakMap<K, V>, key: K) => boolean)} */
13 var $mapHas = callBound('WeakMap.prototype.has', true);
14
15 /** @type {import('.')} */
16 module.exports = function isWeakSet(x) {
17 if (!x || typeof x !== 'object') {
18 return false;
19 }
20 try {
21 // @ts-expect-error TS can't figure out that $setHas is always truthy here
22 $setHas(x, $setHas);
23 if ($mapHas) {
24 try {
25 // @ts-expect-error this indeed might not be a weak collection
26 $mapHas(x, $mapHas);
27 } catch (e) {
28 return true;
29 }
30 }
31 // @ts-expect-error TS can't figure out that $WeakSet is always truthy here
32 return x instanceof $WeakSet; // core-js workaround, pre-v3
33 } catch (e) {}
34 return false;
35 };
36} else {
37 /** @type {import('.')} */
38 // @ts-expect-error
39 module.exports = function isWeakSet(x) { // eslint-disable-line no-unused-vars
40 // `WeakSet` does not exist, or does not have a `has` method
41 return false;
42 };
43}
Note: See TracBrowser for help on using the repository browser.