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.2.1/mod.ts";

Constructors

new
BetterMap(name?: string)

Create a new BetterMap

Properties

name: string

Methods

array(): V[]

Convert the map into an array of values / keys

array(keys: boolean): K[]
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
findKey(fn: (v: V, k: K) => boolean): K | undefined
first(): V | undefined

Get the first element(s) from the map.

first(n: number): V[]
firstKey(): K | undefined

Get the first (n) element's key from the map.

firstKey(n: number): K[]
json(): Record<string, V>

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

keyAt(pos: number): K | undefined

Return the nth key of the map.

last(): V | undefined

Get last value(s) in the Map.

last(n: number): V[]
lastKey(): K | undefined

Get last key(s) in the Map.

lastKey(n: number): K[]
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[]
randomKey(): K | undefined

Get a random key from the BetterMap.

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

Reduce data in the map.

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

Check if at least one entry from the Map passes the function.

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
transform<T>(fn: (v: V, k: K) => T): BetterMap<K, T>

Transform values of the map. Similar to map() but returns a BetterMap instead.

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