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

export function _common(paths: string[], sep: string): string {
  const [first = "", ...remaining] = paths;
  const parts = first.split(sep);

  let endOfPrefix = parts.length;
  let append = "";
  for (const path of remaining) {
    const compare = path.split(sep);
    if (compare.length <= endOfPrefix) {
      endOfPrefix = compare.length;
      append = "";
    }

    for (let i = 0; i < endOfPrefix; i++) {
      if (compare[i] !== parts[i]) {
        endOfPrefix = i;
        append = i === 0 ? "" : sep;
        break;
      }
    }
  }
  return parts.slice(0, endOfPrefix).join(sep) + append;
}

// denoCacheMetadata={"headers":{"content-type":"text/typescript","x-robots-tag":"noindex","cross-origin-resource-policy":"cross-origin","etag":"\"3f344ce1ba0c763cd04aa50dbbcb12aa\"","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","date":"Tue, 28 Jul 2026 12:31:15 GMT","server":"cloudflare","access-control-allow-origin":"*","cf-cache-status":"HIT","content-length":"719","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';","alt-svc":"h3=\":443\"; ma=86400","accept-ranges":"bytes","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=o8snkxc9LEOiyEQpL5W%2Ff1otoUfvVvweSzS4D%2BfYyyI6TlgAWgBPWZfrE1U1dauf%2BlVuhjgdsAvje5ntc3uweaSvQoqitVZ%2BYWlLuqlaY3JYNnMzF%2Brc%2BUw%3D\"}]}","x-jsr-backend":"modules","vary":"Origin","set-cookie":"__cf_bm=ukFvV.fcsQUh6eFwcBDVw3Hunpn2ALstRpnAeNEDSP4-1785241875.2670147-1.0.1.1-Scsv8YNpseB5dLFWAjBEtLHSQwbMjRAHIhzL0rb6jaooOhHdRTYUB8fZQn14A8YtHGKeJ16.shdMK941SPFtnzpxtCN3Sa_T0KXHlmBCtSjdBM6AcN2aG6R.sPOZMB5m; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","cache-control":"public, max-age=31536000, immutable","cf-ray":"a223e6586c3f7db6-LAX","x-content-type-options":"nosniff","age":"2759642","access-control-expose-headers":"*"},"url":"https://jsr.io/@std/path/0.224.0/_common/common.ts","time":1785241875}