2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-08-07 07:45:33 +00:00
|
|
|
// This module is browser compatible.
|
|
|
|
|
2023-08-25 09:07:43 +00:00
|
|
|
import { isWindows } from "./_os.ts";
|
2023-09-28 10:54:53 +00:00
|
|
|
import { join as posixJoin } from "./posix/join.ts";
|
|
|
|
import { join as windowsJoin } from "./windows/join.ts";
|
2023-08-07 07:45:33 +00:00
|
|
|
|
|
|
|
/**
|
2024-06-04 12:53:29 +00:00
|
|
|
* Joins a sequence of paths, then normalizes the resulting path.
|
2024-06-02 02:46:36 +00:00
|
|
|
*
|
|
|
|
* @example Usage
|
|
|
|
* ```ts
|
|
|
|
* import { join } from "@std/path/join";
|
refactor(assert,async,bytes,cli,collections,crypto,csv,data-structures,datetime,dotenv,encoding,expect,fmt,front-matter,fs,html,http,ini,internal,io,json,jsonc,log,media-types,msgpack,net,path,semver,streams,testing,text,toml,ulid,url,uuid,webgpu,yaml): import from `@std/assert` (#5199)
* refactor: import from `@std/assert`
* update
2024-06-30 08:30:10 +00:00
|
|
|
* import { assertEquals } from "@std/assert";
|
2024-06-02 02:46:36 +00:00
|
|
|
*
|
|
|
|
* 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");
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
2024-09-12 10:41:45 +00:00
|
|
|
* Note: If you are working with file URLs,
|
|
|
|
* use the new version of `join` from `@std/path/unstable-join`.
|
|
|
|
*
|
2024-06-02 02:46:36 +00:00
|
|
|
* @param paths Paths to be joined and normalized.
|
|
|
|
* @returns The joined and normalized path.
|
2023-08-07 07:45:33 +00:00
|
|
|
*/
|
2024-09-12 07:32:06 +00:00
|
|
|
export function join(...paths: string[]): string {
|
|
|
|
return isWindows ? windowsJoin(...paths) : posixJoin(...paths);
|
2023-08-07 07:45:33 +00:00
|
|
|
}
|