mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
94a7e1b34b
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
// 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";
|
|
*
|
|
* 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;
|
|
/**
|
|
* Join all given a sequence of `paths`, then normalizes the resulting path.
|
|
*
|
|
* @experimental **UNSTABLE**: New API, yet to be vetted.
|
|
*
|
|
* @example Usage
|
|
* ```ts
|
|
* import { join } from "@std/path/posix/join";
|
|
* import { assertEquals } from "@std/assert";
|
|
*
|
|
* const path = join(new URL("file:///foo"), "bar", "baz/asdf", "quux", "..");
|
|
* assertEquals(path, "/foo/bar/baz/asdf");
|
|
* ```
|
|
*
|
|
* @param path The path to join. This can be string or file URL.
|
|
* @param paths The paths to join.
|
|
* @returns The joined path.
|
|
*/
|
|
export function join(path?: URL | string, ...paths: string[]): string;
|
|
export function join(path?: URL | string, ...paths: string[]): string {
|
|
return isWindows ? windowsJoin(path, ...paths) : posixJoin(path, ...paths);
|
|
}
|