// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
 * 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)`.
 *
 * @param source Source array to check.
 * @param prefix Prefix array to check for.
 * @returns `true` if the prefix array appears at the start of the source array,
 * `false` otherwise.
 *
 * @example Basic usage
 * ```ts
 * import { startsWith } from "@std/bytes/starts-with";
 *
 * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
 * const prefix = new Uint8Array([0, 1, 2]);
 *
 * startsWith(source, prefix); // true
 * ```
 */
export function startsWith(source: Uint8Array, prefix: Uint8Array): boolean {
  for (let i = 0; i < prefix.length; i++) {
    if (source[i] !== prefix[i]) return false;
  }
  return true;
}

// denoCacheMetadata={"headers":{"x-robots-tag":"noindex","content-type":"text/typescript","x-jsr-backend":"modules","set-cookie":"__cf_bm=fgxDPGki_7RKaDqta5sJzqd7Vz9Dbu2DW.qTbgxIWLk-1785241874.947447-1.0.1.1-1oZZSXxhBOsfPmo1ZKr0iPM5_9buF2ZRa_ibwpCXdtZrrM_dyet0z6Rzrr_VL7HSisAmQ59DE3FBREbCipDFEawLMu6qgSba.ZCpMzL81l4jhtwvtHkNqHWWK.OeUSiF; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:14 GMT","cf-cache-status":"HIT","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=HGt9G2lGKHXjmp4YErWQheCXP86KvVyQXLBN5pdgpaBVzxnOAIfmbpX2LYPifKusaJrRGfq5pATc4Zo909NUfnc%2FH%2BCHJ7EugwXLTullJ0G1hrLkuKPXZpw%3D\"}]}","alt-svc":"h3=\":443\"; ma=86400","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","cross-origin-resource-policy":"cross-origin","cf-ray":"a223e6564ed97db6-LAX","age":"5545","cache-control":"public, max-age=31536000, immutable","vary":"Origin","x-content-type-options":"nosniff","content-length":"914","access-control-allow-origin":"*","etag":"\"39910e50a377c867cee53774f813a112\"","date":"Tue, 28 Jul 2026 12:31:14 GMT","server":"cloudflare","access-control-expose-headers":"*","accept-ranges":"bytes"},"url":"https://jsr.io/@std/bytes/0.224.0/starts_with.ts","time":1785241874}