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 { resolve as posixResolve } from "./posix/resolve.ts";
|
|
|
|
import { resolve as windowsResolve } from "./windows/resolve.ts";
|
2023-08-07 07:45:33 +00:00
|
|
|
|
|
|
|
/**
|
2024-06-02 02:46:36 +00:00
|
|
|
* Resolves path segments into a path.
|
|
|
|
*
|
|
|
|
* @example Usage
|
|
|
|
* ```ts
|
|
|
|
* import { resolve } from "@std/path/resolve";
|
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(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.
|
2023-08-07 07:45:33 +00:00
|
|
|
*/
|
|
|
|
export function resolve(...pathSegments: string[]): string {
|
|
|
|
return isWindows
|
|
|
|
? windowsResolve(...pathSegments)
|
|
|
|
: posixResolve(...pathSegments);
|
|
|
|
}
|