Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/bencodex/src/dict.ts>BencodexDictionary

An alternative take on implementing Bencodex in TypeScript/JavaScript
Latest
class BencodexDictionary
implements Dictionary
import { BencodexDictionary } from "https://deno.land/x/bencodex@0.2.2/src/dict.ts";

A Dictionary implementation that complies with the Bencodex specification. Unlike Map, this implementation allows only keys of type Key and values of type Value, and in particular, it actually compares Uint8Array keys by their contents instead of their references.

Note that this implementation does not guarantee the stable order of entries; it can vary depending on the platform and the version of this library.

Examples

Constructing a dictionary

const dict = new BencodexDictionary([
  ["foo", 123n],
  ["bar", "baz"],
]);

Constructors

new
BencodexDictionary(entries?: Iterable<readonly [Key, Value]>)

Creates a new BencodexDictionary instance.

Properties

readonly
size

{@inheritDoc Dictionary.size}

Methods

entries(): Iterable<readonly [Key, Value]>

{@inheritDoc Dictionary.entries}

forEach(callback: (
value: Value,
key: Key,
dictionary: Dictionary,
) => void
, thisArg?: unknown
): void

{@inheritDoc Dictionary.forEach}

get(key: Key): Value | undefined

{@inheritDoc Dictionary.get}

has(key: Key): boolean

{@inheritDoc Dictionary.has}

keys(): Iterable<Key>

{@inheritDoc Dictionary.keys}

values(): Iterable<Value>

{@inheritDoc Dictionary.values}

[Symbol.for("Deno.customInspect")](inspect: (_: unknown, options: unknown) => string, options: { compact: boolean; depth: number; sorted: boolean; trailingComma: boolean; }): string
[Symbol.for("nodejs.util.inspect.custom")](
_: number,
options: { compact: number | boolean; depth: number; sorted: boolean; },
inspect: (_: unknown, options: unknown) => string,
): string
[Symbol.iterator](): Iterator<readonly [Key, Value]>

Gets an iterator which iterates over the key-value pairs in this dictionary. This method is equivalent to Dictionary.entries().