Skip to main content
Module

x/bettermap/mod.ts>BetterMap

An extension of the Map class with more Array-like features.
Go to Latest
class BetterMap
extends Map<K, V>
import { BetterMap } from "https://deno.land/x/bettermap@v1.1.0/mod.ts";

Constructors

new
BetterMap(name?: string)

Create a new BetterMap

Properties

name: string

Methods

Convert the map into an array of values

at(pos: number): V | undefined

Return the nth element of the map.

every(fn: (v: V, k: K) => boolean): boolean

Array#every but for a Map

filter(fn: (v: V, k: K) => boolean): BetterMap<K, V>

Array#filter but for a Map

find(fn: (v: V, k: K) => boolean): V | undefined
first(): V | undefined

Get the first element from the map.

firstKey(): K | undefined

Get the first element's key from the map.

json(): Record<string, V>

Convert the key-value pairs into key-value pairs... I mean a JavaScript object.

map<T>(fn: (v: V, k: K) => T): T[] | []

Map the Map into an Array.

random(): V | undefined

Get a random element from the BetterMap.

random(count: number): V[]
reduce<T>(fn: (acc: T, val: [K, V]) => T, first: T): T

Array#reduce but for a Map

some(fn: (val: V, key: K) => boolean): boolean

Array#some but for a Map

sort(fn?: (
v1: V,
v2: V,
k1: K,
k2: K,
) => number
): BetterMap<K, V>

Sort elements in the better map.

toJSON(): Record<string, V>

Duplicate of BetterMap#json

toString(): string

Static Methods

from<K1, V1>(data: Map<K1, V1> | [K1, V1][]): BetterMap<K1, V1>

Create a new map from an existing Map or an array of key-value pairs