function assertdimension
assertdimension(dim: unknown): asserts dim is Dimension

Asserts that a value is a valid dimension (0 or 1).

Throws a TypeError if the input is not 0 or 1. Uses TypeScript's type assertion to narrow the type.

Examples

Valid dimension 0

import { assertThrows } from "jsr:@std/assert";

assertdimension(0); // No error

Valid dimension 1

import { assertThrows } from "jsr:@std/assert";

assertdimension(1); // No error

Invalid dimension throws error

import { assertThrows } from "jsr:@std/assert";

assertThrows(() => assertdimension(2), TypeError, "Expected dimension 0 or 1, got 2");

Parameters

dim: unknown

The value to check

Return Type

asserts dim is Dimension

Throws

If dim is not 0 or 1

Usage

import assertdimension from "datatype/assertdimension.ts";