-
Notifications
You must be signed in to change notification settings - Fork 0
map
Nicholas Berlette edited this page Jun 19, 2025
·
1 revision
function isMap<K = unknown, V = unknown>(it: unknown): it is Map<K, V>;Checks if a given value is a Map instance. This is a more reliable check than
it instanceof Map because it works across different realms, and it does not
require the Map constructor to be the same as the one in the current
environment that the code is running in.
It also is more strict than it instanceof Map, and does not consider any
objects created via Object.create(Map.prototype) (or similar constructs) as
valid Map instances, while they would pass the instanceof check.
| Name | Info |
|---|---|
it |
The value to check. |
true if the value is a Map instance, false otherwise.
Keyed Collections
import { isMap } from "jsr:@nick/is/map";
isMap(new Map()); // true
isMap(new WeakMap()); // false
isMap({}); // false
isMap(new Set()); // falseimport { isMap } from "jsr:@nick/is/map";
const fakeMap = Object.create(Map.prototype);
console.log(isMap(fakeMap)); // false
console.log(fakeMap instanceof Map); // true (?!)