@ende/bytes

ende add jsr:@ende/bytes

Version 2026.10.15 on JSR.

Helper functions for working with Uint8Array byte slices.

import { concat, indexOfNeedle, endsWith } from "@ende/bytes";
import { assertEquals } from "@ende/assert";

const a = new Uint8Array([0, 1, 2]);
const b = new Uint8Array([3, 4, 5]);

const c = concat([a, b]);

assertEquals(c, new Uint8Array([0, 1, 2, 3, 4, 5]));

assertEquals(indexOfNeedle(c, new Uint8Array([2, 3])), 2);

assertEquals(endsWith(c, b), true);

Modules

Exports

  • concat — Concatenate an array of byte slices into a single slice.
  • copy — Copy bytes from the source array to the destination array and returns the number of bytes copied.
  • endsWith — Returns `true` if the suffix array appears at the end of the source array, `false` otherwise.
  • equals — Check whether byte slices are equal to each other.
  • includesNeedle — Determines whether the source array contains the needle array.
  • indexOfNeedle — Returns the index of the first occurrence of the needle array in the source array, or -1 if it is not present.
  • lastIndexOfNeedle — Returns the index of the last occurrence of the needle array in the source array, or -1 if it is not present.
  • repeat — Returns a new byte slice composed of `count` repetitions of the `source` array.
  • startsWith — Returns `true` if the prefix array appears at the start of the source array, `false` otherwise.
  • Uint8Array_ — Proxy type of {@code Uint8Array<ArrayBuffer>} or {@code Uint8Array} in TypeScript 5.7 or below respectively.