Function startsWith

  • 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).

    Parameters

    • source: Uint8Array

      Source array to check.

    • prefix: Uint8Array

      Prefix array to check for.

    Returns boolean

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

    import { startsWith } from "@std/bytes/starts-with";
    import { assertEquals } from "@std/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);