function oneOf
oneOf<V extends string>(...values: V[]): XmlField<V>

A text field limited to known values, such as <parity>none</parity>.

Reading throws on a value outside the list, so a firmware that sends something new fails loudly instead of slipping past the type.

Examples

Read an enumerated value

import { assertEquals } from "@std/assert";
import { parse } from "@std/xml";
import { oneOf } from "@hertzg/reolink-api/protocol/xml";

const parity = oneOf("none", "odd", "even");

assertEquals(parity.decode("parity", parse("<p><parity>odd</parity></p>").root), "odd");

Type Parameters

V extends string

Parameters

...values: V[]

The accepted values.

Return Type

A field codec for the union of values.

Usage

import { oneOf } from "protocol/xml.ts";