mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
388800f301
Co-authored-by: Nathan Whitaker <nathan@deno.com> Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
31 lines
958 B
TypeScript
31 lines
958 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
// This module is browser compatible.
|
|
|
|
import { isWindows } from "./_os.ts";
|
|
import { isAbsolute as posixIsAbsolute } from "./posix/is_absolute.ts";
|
|
import { isAbsolute as windowsIsAbsolute } from "./windows/is_absolute.ts";
|
|
|
|
/**
|
|
* Verifies whether provided path is absolute.
|
|
*
|
|
* @example Usage
|
|
* ```ts
|
|
* import { isAbsolute } from "@std/path/is-absolute";
|
|
* import { assert, assertFalse } from "@std/assert";
|
|
*
|
|
* if (Deno.build.os === "windows") {
|
|
* assert(isAbsolute("C:\\home\\foo"));
|
|
* assertFalse(isAbsolute("home\\foo"));
|
|
* } else {
|
|
* assert(isAbsolute("/home/foo"));
|
|
* assertFalse(isAbsolute("home/foo"));
|
|
* }
|
|
* ```
|
|
*
|
|
* @param path Path to be verified as absolute.
|
|
* @returns `true` if path is absolute, `false` otherwise
|
|
*/
|
|
export function isAbsolute(path: string): boolean {
|
|
return isWindows ? windowsIsAbsolute(path) : posixIsAbsolute(path);
|
|
}
|