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

import { isWindows } from "./_os.ts";
import type { ParsedPath } from "./_interface.ts";
import { parse as posixParse } from "./posix/parse.ts";
import { parse as windowsParse } from "./windows/parse.ts";

export type { ParsedPath } from "./_interface.ts";

/**
 * Return a `ParsedPath` object of the `path`. Use `format` to reverse the result.
 *
 * @example
 * ```ts
 * import { parse } from "@std/path";
 *
 * const parsedPathObj = parse("/path/to/dir/script.ts");
 * parsedPathObj.root; // "/"
 * parsedPathObj.dir; // "/path/to/dir"
 * parsedPathObj.base; // "script.ts"
 * parsedPathObj.ext; // ".ts"
 * parsedPathObj.name; // "script"
 * ```
 * @param path to process
 */
export function parse(path: string): ParsedPath {
  return isWindows ? windowsParse(path) : posixParse(path);
}

// denoCacheMetadata={"headers":{"x-content-type-options":"nosniff","server":"cloudflare","cache-control":"public, max-age=31536000, immutable","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-allow-origin":"*","x-robots-tag":"noindex","cross-origin-resource-policy":"cross-origin","cf-ray":"a223e6579a1d7db6-LAX","content-type":"text/typescript","content-length":"905","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","alt-svc":"h3=\":443\"; ma=86400","age":"44352","accept-ranges":"bytes","vary":"Origin","access-control-expose-headers":"*","x-jsr-backend":"modules","cf-cache-status":"HIT","etag":"\"635cbe49a2b98b463c0ccf01f26ef0f8\"","date":"Tue, 28 Jul 2026 12:31:15 GMT","set-cookie":"__cf_bm=8mnvFIcdn9Z5tCqeRposThhy.bo_nbWLY_eAjyTDbLE-1785241875.1414242-1.0.1.1-ytvwvNAtwoYMBFQI7Pu2JrniCzgFnZzIrt.FHktoP4l8Cfpw6u8IVJRq2AMch1XdZPV.LNSLsNJUZ.qw2J.yfuTGg3Z1NjPuhL6JXBcWhekOKL5YJ1IoZOOP4KnMZykY; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=rYjBycE3U5ergHf4rLehnL5piVLnQ%2Bi2T9ONOHZn7SWfthf2KoMbIwOf5c2VzpvqJOZlvCMz8R%2BHBdMXEEwVab2A90PPwJEWw%2BTkkYh2x5DDBKcjenSln5o%3D\"}]}"},"url":"https://jsr.io/@std/path/0.224.0/parse.ts","time":1785241875}