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

import { indexOfNeedle } from "./index_of_needle.ts";

/**
 * Determines whether the source array contains the needle array.
 *
 * The complexity of this function is `O(source.length * needle.length)`.
 *
 * @param source Source array to check.
 * @param needle Needle array to check for.
 * @param start Start index in the source array to begin the search. Defaults to
 * 0.
 * @returns `true` if the source array contains the needle array, `false`
 * otherwise.
 *
 * @example Basic usage
 * ```ts
 * import { includesNeedle } from "@std/bytes/includes-needle";
 *
 * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
 * const needle = new Uint8Array([1, 2]);
 *
 * includesNeedle(source, needle); // true
 * ```
 *
 * @example Start index
 * ```ts
 * import { includesNeedle } from "@std/bytes/includes-needle";
 *
 * const source = new Uint8Array([0, 1, 2, 1, 2, 1, 2, 3]);
 * const needle = new Uint8Array([1, 2]);
 *
 * includesNeedle(source, needle, 6); // false
 * ```
 * The search will start at the specified index in the source array.
 */
export function includesNeedle(
  source: Uint8Array,
  needle: Uint8Array,
  start = 0,
): boolean {
  return indexOfNeedle(source, needle, start) !== -1;
}

// denoCacheMetadata={"headers":{"date":"Tue, 28 Jul 2026 12:31:14 GMT","content-type":"text/typescript","etag":"\"c40930a66fdae6aa4907c3fb4e2e1d01\"","access-control-allow-origin":"*","set-cookie":"__cf_bm=kJvVF0pyFT_AC5Wxm9U.7H4jmFF1uXjylYC28bmDABw-1785241874.9457183-1.0.1.1-tmdtyKNuptQ2pHA4iVdUT2ISlXokcTHSUNzS.QupjQpwDgPadI.9sc93hzJgcw2rb2b_igk9V0qq0b9FZJ1c4zcm23teuBhotN6RjDFArk4Jay2kz2yqJ9E59oNOGeRI; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:14 GMT","accept-ranges":"bytes","alt-svc":"h3=\":443\"; ma=86400","cf-cache-status":"HIT","cache-control":"public, max-age=31536000, immutable","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","server":"cloudflare","age":"36641","vary":"Origin","content-length":"1329","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';","x-content-type-options":"nosniff","x-robots-tag":"noindex","access-control-expose-headers":"*","cf-ray":"a223e6564ed07db6-LAX","cross-origin-resource-policy":"cross-origin","x-jsr-backend":"modules","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=nuqRzMrIrPDZTJl%2Bg0nlkwXZY9sx%2FpOuujp3W1bCeEDN0gde%2FnelMiL%2Fr1TH%2F7dZM%2FzIFs55GnTwGSCCNWuCsqDR0gs5WbdVDybAWniphOkea9K%2F4OKfA%2BA%3D\"}]}"},"url":"https://jsr.io/@std/bytes/0.224.0/includes_needle.ts","time":1785241874}