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

/** Test whether the given string is a glob */
export function isGlob(str: string): boolean {
  const chars: Record<string, string> = { "{": "}", "(": ")", "[": "]" };
  const regex =
    /\\(.)|(^!|\*|\?|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/;

  if (str === "") {
    return false;
  }

  let match: RegExpExecArray | null;

  while ((match = regex.exec(str))) {
    if (match[2]) return true;
    let idx = match.index + match[0].length;

    // if an open bracket/brace/paren is escaped,
    // set the index to the next closing character
    const open = match[1];
    const close = open ? chars[open] : null;
    if (open && close) {
      const n = str.indexOf(close, idx);
      if (n !== -1) {
        idx = n + 1;
      }
    }

    str = str.slice(idx);
  }

  return false;
}

// denoCacheMetadata={"headers":{"x-jsr-backend":"modules","set-cookie":"__cf_bm=skAufMtTdNc.zMIgNakfY5jdqone9VQ.xSrDpogKZcQ-1785241875.1527104-1.0.1.1-mAB7qBcnXD8FSN5sz4qjZaPUhp5PC2ctwUuUfvNZsRZgFFS_WXLrQSZrArtLgL52fafdbtIvqWuWLcolyRJ3oDDR5u8tOOlMP5t5SYXDim4MW0y7j2gUIkx.dcA4gFLu; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","access-control-allow-origin":"*","alt-svc":"h3=\":443\"; ma=86400","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=mnjnINZLu%2FacM8R4RkrvloKlnA0f08w%2F%2FeGcVLm%2BBGDaGw9R6HXw%2BsE6AU6NedlJGAsDBCYm%2FOM74nTiZCMTBxwBT%2BMaElPX1OCwmr7BpnTcq%2F%2Bh5c3h3XA%3D\"}]}","accept-ranges":"bytes","cache-control":"public, max-age=31536000, immutable","age":"3678828","access-control-expose-headers":"*","x-content-type-options":"nosniff","cf-ray":"a223e657ba477db6-LAX","content-length":"938","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';","etag":"\"aadbc2e32508ade85b7cadc05fb2b5d3\"","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","server":"cloudflare","cf-cache-status":"HIT","cross-origin-resource-policy":"cross-origin","x-robots-tag":"noindex","date":"Tue, 28 Jul 2026 12:31:15 GMT","content-type":"text/typescript","vary":"Origin"},"url":"https://jsr.io/@std/path/0.224.0/is_glob.ts","time":1785241875}