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

x/bencodex/src/dict.ts>RecordView

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

A view of a RecordValue that implements Dictionary. It is a handy way to construct a Dictionary using JavaScript's object literal syntax.

Examples

Constructing a simple dictionary

const dict = new RecordView({
  foo: [1n, 2n, 3n],
  bar: {
    baz: "qux",
    quux: true,
  },
});

The above code is mostly equivalent to the following code:

const dict = new BencodexDictionary([
  ["foo", [1n, 2n, 3n]],
  [
    "bar",
    new BencodexDictionary([
      ["baz", "qux"],
      ["quux", true],
    ]),
  ],
])

Constructors

new
RecordView(record: RecordValue, keyEncoding: "text" | "utf8")

Creates a new RecordView instance.

Properties

readonly
keyEncoding: "text" | "utf8"

How the keys are encoded. If it is "text", the keys are encoded as Bencodex texts. If it is "utf8", the keys are encoded as Bencodex binary values with UTF-8 encoding.

readonly
size: number

{@inheritDoc Dictionary.size}

Methods

entries(): Iterable<[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<[Key, Value]>

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