// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// Copyright the Browserify authors. MIT License.

import { SEPARATOR } from "jsr:/@std/path@^0.224.0/constants";
import { toPathString } from "./_to_path_string.ts";

/**
 * Test whether or not `dest` is a sub-directory of `src`
 * @param src src file path
 * @param dest dest file path
 * @param sep path separator
 */
export function isSubdir(
  src: string | URL,
  dest: string | URL,
  sep = SEPARATOR,
): boolean {
  if (src === dest) {
    return false;
  }
  src = toPathString(src);
  const srcArray = src.split(sep);
  dest = toPathString(dest);
  const destArray = dest.split(sep);
  return srcArray.every((current, i) => destArray[i] === current);
}

// denoCacheMetadata={"headers":{"vary":"Origin","x-content-type-options":"nosniff","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=ZKoTBVR%2FvQrADrg0KUUXB1fol9cBH1Wxb1Z35F4PqAe8G0zddZpyDm3jly%2FH8eUoF063RAidDx0rfjzUfjLOIIZWdieIUPOO2jkmbK%2FYb0qCtSRDTztKnT0%3D\"}]}","cf-ray":"a223e657fb487db6-LAX","alt-svc":"h3=\":443\"; ma=86400","cross-origin-resource-policy":"cross-origin","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';","access-control-expose-headers":"*","cache-control":"public, max-age=31536000, immutable","x-robots-tag":"noindex","set-cookie":"__cf_bm=bUY6Go_MjEbrRLeTRHNGeQNY1yygBme2TpawvbW64PA-1785241875.2119398-1.0.1.1-G.bDV4aSABx1UGGGK4IptwQFuoH0Yr6GwQyUQ9yDXlUBfn8IG5Z8Wx0URCs1_RsHoI3sG1stq.QxH7o4OA1mfjKCaiqoBtr0Bq9NS9xnxrwq5wFvvFHzx7Bpno4iWp5s; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","server":"cloudflare","cf-cache-status":"HIT","x-jsr-backend":"modules","date":"Tue, 28 Jul 2026 12:31:15 GMT","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","etag":"\"16354d20751e434dc9a2071ae789a20c\"","content-type":"text/typescript","content-length":"738","access-control-allow-origin":"*","age":"44344","accept-ranges":"bytes"},"url":"https://jsr.io/@std/fs/0.224.0/_is_subdir.ts","time":1785241875}