Skip to main content
Home

@std/bytes@1.0.6
Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
Downloads51,028/wk
Published8 months ago (1.0.6)

Utilities to manipulate Uint8Arrays that are not built-in to JavaScript

// Copyright 2018-2025 the Deno authors. MIT license. import { assert } from "jsr:@std/assert@^1.0.13"; import { startsWith } from "./starts_with.ts"; Deno.test("startsWith()", async (t) => { await t.step("`true` where `source` and `prefix` are identical", () => { assert(startsWith( new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 3]), )); }); await t.step("`true` where `source` starts with `prefix`", () => { assert(startsWith( new Uint8Array([0, 1, 2]), new Uint8Array([0, 1]), )); }); await t.step("`false` with a common but only partial prefix", () => { assert( !startsWith( new Uint8Array([0, 1, 2]), new Uint8Array([0, 2]), ), ); }); await t.step("`false` where `prefix` is longer", () => { assert( !startsWith( new Uint8Array([0, 1, 2]), new Uint8Array([0, 2, 3, 4]), ), ); }); await t.step("`false` where `prefix` starts with `source`", () => { assert( !startsWith( new Uint8Array([0, 1]), new Uint8Array([0, 1, 2]), ), ); }); });