startsWith

import { startsWith } from "jsr:@ende/bytes";

function

function startsWith(source: Uint8Array, prefix: Uint8Array): boolean

Returns true if the prefix array appears at the start of the source array, false otherwise.

The complexity of this function is O(prefix.length).

source: Uint8Array

Source array to check.

prefix: Uint8Array

Prefix array to check for.

Returns

true if the prefix array appears at the start of the source array, false otherwise.

Example: Basic usage

import { startsWith } from "@ende/bytes/starts-with";
import { assertEquals } from "@ende/assert";

const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
const prefix = new Uint8Array([0, 1, 2]);

assertEquals(startsWith(source, prefix), true);

Source