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

import { isWindows } from "./_os.ts";
import { join as posixJoin } from "./posix/join.ts";
import { join as windowsJoin } from "./windows/join.ts";

/**
 * Joins a sequence of paths, then normalizes the resulting path.
 *
 * @example Usage
 * ```ts
 * import { join } from "@std/path/join";
 * import { assertEquals } from "@std/assert/assert-equals";
 *
 * if (Deno.build.os === "windows") {
 *   assertEquals(join("C:\\foo", "bar", "baz\\quux", "garply", ".."), "C:\\foo\\bar\\baz\\quux");
 * } else {
 *   assertEquals(join("/foo", "bar", "baz/quux", "garply", ".."), "/foo/bar/baz/quux");
 * }
 * ```
 *
 * @param paths Paths to be joined and normalized.
 * @returns The joined and normalized path.
 */
export function join(...paths: string[]): string {
  return isWindows ? windowsJoin(...paths) : posixJoin(...paths);
}

// denoCacheMetadata={"headers":{"age":"126790","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","x-content-type-options":"nosniff","cache-control":"public, max-age=31536000, immutable","cf-ray":"a223e658bd557db6-LAX","cross-origin-resource-policy":"cross-origin","content-type":"text/typescript","access-control-allow-origin":"*","date":"Tue, 28 Jul 2026 12:31:15 GMT","etag":"\"62af3bba5f3d5b4c6f74ae3b59584aac\"","content-length":"940","alt-svc":"h3=\":443\"; ma=86400","cf-cache-status":"HIT","vary":"Origin","x-robots-tag":"noindex","x-jsr-backend":"modules","server":"cloudflare","accept-ranges":"bytes","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';","set-cookie":"__cf_bm=AP.16NzZ3uQJjSTyKC6XGVYz3z3wfUZhbJ8VuD6W8vY-1785241875.319815-1.0.1.1-5ZJJrz4qpgiYJj5.ICQ2iPgPNfguCEIEKtaXUCNJKrG5CzDEO6TVNLDxU44o0y5kkXeyH5rGTKQWKS3FUBmFNxKQfofmKSJKy6m9.c_T_uDFtwKuiN..GORT46rdCC03; 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=LfBmGvSrMzQGgDraIlq3iz44uIy%2F5hQInEu11Afdy35TY228uFsedG84JJGeT8E0uN1OPwEQRhSBoV20azYS60aFwkVllbNUVwTNLlQqvcU7wXyApRKS7gg%3D\"}]}","access-control-expose-headers":"*"},"url":"https://jsr.io/@std/path/1.0.0-rc.2/join.ts","time":1785241875}