function isValidLength
isValidLength(length: number): boolean

Validates if a length value is valid for binary encoding.

A valid length must be a non-negative integer.

Examples

Example 1

import { assertEquals } from "@std/assert";
import { isValidLength } from "./length.ts";

assertEquals(isValidLength(0), true);      // Valid: zero
assertEquals(isValidLength(100), true);    // Valid: positive integer
assertEquals(isValidLength(-1), false);    // Invalid: negative
assertEquals(isValidLength(3.14), false);  // Invalid: not integer
assertEquals(isValidLength(NaN), false);   // Invalid: NaN

Parameters

length: number

The length value to validate

Return Type

boolean

True if the length is valid, false otherwise

Usage

import { isValidLength } from "mod.ts";