Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion path/_common/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2018-2026 the Deno authors. MIT license.
// This module is browser compatible.

export function common(paths: string[], sep: string): string {
export function common(paths: readonly string[], sep: string): string {
const [first = "", ...remaining] = paths;
const parts = first.split(sep);

Expand Down
2 changes: 1 addition & 1 deletion path/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ import { SEPARATOR } from "./constants.ts";
* }
* ```
*/
export function common(paths: string[]): string {
export function common(paths: readonly string[]): string {
return _common(paths, SEPARATOR);
}
20 changes: 20 additions & 0 deletions path/common_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,23 @@ Deno.test({
assertEquals(actual, "file://deno/");
},
});

Deno.test({
name: "common() accepts readonly arrays",
fn() {
const posixPaths: readonly string[] = [
"./deno/std/path/mod.ts",
"./deno/std/fs/mod.ts",
];
assertEquals(posix.common(posixPaths), "./deno/std/");

const windowsPaths: readonly string[] = [
"C:\\deno\\std\\path\\mod.ts",
"C:\\deno\\std\\fs\\mod.ts",
];
assertEquals(windows.common(windowsPaths), "C:\\deno\\std\\");

const paths = ["./deno/std/path/mod.ts", "./deno/std/path/mod.ts"] as const;
assertEquals(common(paths), "./deno/std/path/mod.ts");
},
});
2 changes: 1 addition & 1 deletion path/posix/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ import { SEPARATOR } from "./constants.ts";
* @param paths The paths to compare.
* @returns The common path.
*/
export function common(paths: string[]): string {
export function common(paths: readonly string[]): string {
return _common(paths, SEPARATOR);
}
2 changes: 1 addition & 1 deletion path/windows/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ import { SEPARATOR } from "./constants.ts";
* @param paths The paths to compare.
* @returns The common path.
*/
export function common(paths: string[]): string {
export function common(paths: readonly string[]): string {
return _common(paths, SEPARATOR);
}
Loading