mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
d102a10235
* refactor: import from `@std/assert` * update
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
// 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";
|
|
*
|
|
* 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);
|
|
}
|