function assertarray
assertarray(x: unknown): asserts x is array

Asserts that a value is a 1D array.

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

Examples

Valid array

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

assertarray([1, 2, 3]); // No error

Invalid input throws error

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

assertThrows(() => assertarray(5), TypeError, "Expected array");

Matrix (2D array) throws error

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

assertThrows(() => assertarray([[1, 2], [3, 4]]), TypeError, "Expected array");

Parameters

x: unknown

The value to check

Return Type

asserts x is array

Throws

If x is not a 1D array

Usage

import assertarray from "datatype/assertarray.ts";