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

import { CHAR_COLON } from "../_common/constants.ts";
import { assertPath } from "../_common/assert_path.ts";
import { isPathSeparator, isWindowsDeviceRoot } from "./_util.ts";

/**
 * Verifies whether provided path is absolute
 * @param path to be verified as absolute
 */
export function isAbsolute(path: string): boolean {
  assertPath(path);

  const len = path.length;
  if (len === 0) return false;

  const code = path.charCodeAt(0);
  if (isPathSeparator(code)) {
    return true;
  } else if (isWindowsDeviceRoot(code)) {
    // Possible device root

    if (len > 2 && path.charCodeAt(1) === CHAR_COLON) {
      if (isPathSeparator(path.charCodeAt(2))) return true;
    }
  }
  return false;
}

// denoCacheMetadata={"headers":{"x-robots-tag":"noindex","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=Y5DJq7xqHBi73PkSCENV280YNtp5nE5JyIPqRYy9roWEKaJfEYw8CR%2BflKOW3JS5wTRP8pn9TrcjtkKUXVZvmJOteuU3IHsDK%2BL67RjClZTDRFXqH3mUn4I%3D\"}]}","cf-cache-status":"HIT","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","date":"Tue, 28 Jul 2026 12:31:15 GMT","access-control-allow-origin":"*","content-length":"818","x-jsr-backend":"modules","server":"cloudflare","cross-origin-resource-policy":"cross-origin","alt-svc":"h3=\":443\"; ma=86400","age":"4011063","vary":"Origin","access-control-expose-headers":"*","x-content-type-options":"nosniff","content-type":"text/typescript","etag":"\"b9be1ca91532dbb9bcc80bd73b5434fc\"","accept-ranges":"bytes","cache-control":"public, max-age=31536000, immutable","set-cookie":"__cf_bm=JQYp2qWPL20wt8KADgrG8.wU0hJuyZ2Gcj3M2u8cA0Q-1785241875.2333076-1.0.1.1-q1c_9.qlb1Ncr6LjJlAXyyI1W5wa.1UOKLXDe.CWCELhLFZFS02HfOq1kUpGFSqvZA8d3D6MLN2rYLKa3woaFX1C67F86I0BB.pEbPysgPqJ23QlTowqK_wtllzLWuR7; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","cf-ray":"a223e6582bae7db6-LAX","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';"},"url":"https://jsr.io/@std/path/0.224.0/windows/is_absolute.ts","time":1785241875}