2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2021-01-02 15:17:01 +00:00
|
|
|
// This module is browser compatible.
|
2020-03-30 15:36:55 +00:00
|
|
|
|
2024-06-04 04:07:38 +00:00
|
|
|
import { common as _common } from "./_common/common.ts";
|
2024-01-18 05:54:39 +00:00
|
|
|
import { SEPARATOR } from "./constants.ts";
|
2020-03-30 15:36:55 +00:00
|
|
|
|
2024-06-02 02:46:36 +00:00
|
|
|
/**
|
2024-06-04 04:07:38 +00:00
|
|
|
* Determines the common path from a set of paths for the given OS.
|
2020-03-30 15:36:55 +00:00
|
|
|
*
|
2024-06-02 02:46:36 +00:00
|
|
|
* @param paths Paths to search for common path.
|
|
|
|
* @returns The common path.
|
|
|
|
*
|
|
|
|
* @example Usage
|
2021-09-12 15:14:54 +00:00
|
|
|
* ```ts
|
2024-06-02 02:46:36 +00:00
|
|
|
* import { common } from "@std/path/common";
|
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") {
|
|
|
|
* const path = common([
|
|
|
|
* "C:\\deno\\std\\path\\mod.ts",
|
|
|
|
* "C:\\deno\\std\\fs\\mod.ts"
|
|
|
|
* ]);
|
|
|
|
* assertEquals(path, "C:\\deno\\std\\");
|
|
|
|
* } else {
|
|
|
|
* const path = common([
|
|
|
|
* "./deno/std/path/mod.ts",
|
|
|
|
* "./deno/std/fs/mod.ts"
|
|
|
|
* ]);
|
|
|
|
* assertEquals(path, "./deno/std/");
|
|
|
|
* }
|
2021-09-12 15:14:54 +00:00
|
|
|
* ```
|
2020-03-30 15:36:55 +00:00
|
|
|
*/
|
2024-06-04 04:07:38 +00:00
|
|
|
export function common(paths: string[]): string {
|
|
|
|
return _common(paths, SEPARATOR);
|
2020-03-30 15:36:55 +00:00
|
|
|
}
|