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

import { isWindows } from "./_os.ts";
import { resolve as posixResolve } from "./posix/resolve.ts";
import { resolve as windowsResolve } from "./windows/resolve.ts";

/**
 * Resolves path segments into a path.
 *
 * @example Usage
 * ```ts
 * import { resolve } from "@std/path/resolve";
 * import { assertEquals } from "@std/assert/assert-equals";
 *
 * if (Deno.build.os === "windows") {
 *   assertEquals(resolve("C:\\foo", "bar", "baz"), "C:\\foo\\bar\\baz");
 *   assertEquals(resolve("C:\\foo", "C:\\bar", "baz"), "C:\\bar\\baz");
 * } else {
 *   assertEquals(resolve("/foo", "bar", "baz"), "/foo/bar/baz");
 *   assertEquals(resolve("/foo", "/bar", "baz"), "/bar/baz");
 * }
 * ```
 *
 * @param pathSegments Path segments to process to path.
 * @returns The resolved path.
 */
export function resolve(...pathSegments: string[]): string {
  return isWindows
    ? windowsResolve(...pathSegments)
    : posixResolve(...pathSegments);
}

// denoCacheMetadata={"headers":{"x-jsr-backend":"modules","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=W%2B6Kk%2FXf2M01PNix1NNg0FGZh3qo5WaOLS%2F%2BEye117I7Kf3KPc52cdt8X%2FjsbHHcuTVBENIRwD3dll%2Fc2YEwMdtXxskA2NpNka%2FubOUewU%2BfORXYoYw8cpY%3D\"}]}","content-length":"1056","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","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';","cf-cache-status":"HIT","vary":"Origin","x-robots-tag":"noindex","age":"197965","content-type":"text/typescript","cross-origin-resource-policy":"cross-origin","server":"cloudflare","access-control-allow-origin":"*","cache-control":"public, max-age=31536000, immutable","cf-ray":"a223e658bd577db6-LAX","etag":"\"8a29938a66c6c0c4bd8d3cf204b5f8f1\"","date":"Tue, 28 Jul 2026 12:31:15 GMT","access-control-expose-headers":"*","alt-svc":"h3=\":443\"; ma=86400","set-cookie":"__cf_bm=DwY1VuZQ6rE48mkU63U9ksyQl9kNYDo9oSijrIIaDnk-1785241875.3203783-1.0.1.1-zSKII2ICPz10hFZOLcmBLX3rB0xTfVPxume9L0QeXhkb5WPukkoxRML0JKnFloJuAbEQ9DpJjdhET4fJNSwa.dJPKe5Sew5.rXPcIXXG2Y8KsSbPehTxGLH97m2fVyAv; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","x-content-type-options":"nosniff","accept-ranges":"bytes"},"url":"https://jsr.io/@std/path/1.0.0-rc.2/resolve.ts","time":1785241875}