main
Last change
on this file since 0c6b92a was d565449, checked in by stefan toskovski <stefantoska84@…>, 3 months ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | /** @const */
|
---|
| 4 | var $Map = typeof Map === 'function' && Map.prototype ? Map : null;
|
---|
| 5 | var $Set = typeof Set === 'function' && Set.prototype ? Set : null;
|
---|
| 6 |
|
---|
| 7 | var exported;
|
---|
| 8 |
|
---|
| 9 | if (!$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 |
|
---|
| 18 | var $mapHas = $Map ? Map.prototype.has : null;
|
---|
| 19 | var $setHas = $Set ? Set.prototype.has : null;
|
---|
| 20 | if (!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('.')} */
|
---|
| 30 | module.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.