// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

import { _common } from "../_common/common.ts";
import { SEPARATOR } from "./constants.ts";

/** Determines the common path from a set of paths, using an optional separator,
 * which defaults to the OS default separator.
 *
 * ```ts
 *       import { common } from "@std/path";
 *       const p = common([
 *         "./deno/std/path/mod.ts",
 *         "./deno/std/fs/mod.ts",
 *       ]);
 *       console.log(p); // "./deno/std/"
 * ```
 */
export function common(
  paths: string[],
  sep: string = SEPARATOR,
): string {
  return _common(paths, sep);
}

// denoCacheMetadata={"headers":{"accept-ranges":"bytes","cf-ray":"a223e6585c1f7db6-LAX","date":"Tue, 28 Jul 2026 12:31:15 GMT","alt-svc":"h3=\":443\"; ma=86400","content-length":"672","cf-cache-status":"HIT","cache-control":"public, max-age=31536000, immutable","x-jsr-backend":"modules","content-type":"text/typescript","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=PG6TrYLCbblT78Sq88ThIZKvsuOwY3PeQXkdduTy%2B0wcfiY3tB0GAQiGcQJhKfwr217evWVxcFiTx86o%2BYgCa%2F1p6N5%2FJZY2lHah%2FHaLZLgtwhNI9XVxDIQ%3D\"}]}","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","access-control-expose-headers":"*","set-cookie":"__cf_bm=XEzWcKa6rq2VBNs1kV4YmbegAfmjhjhzqUq9aZK1DF0-1785241875.25961-1.0.1.1-_hr0zuFhTV2uQHiL4vQbH3dBiMyi7tajjnrNgiioYd7hhwcugMLuezUcLih_DqcwKzunfhOJaj2v_OF32z7ytUqd3Kv9YUYvMpX6ah8XAIzOlG7ILCFqFLj2lUSWI4rj; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","age":"44352","cross-origin-resource-policy":"cross-origin","server":"cloudflare","vary":"Origin","x-content-type-options":"nosniff","access-control-allow-origin":"*","etag":"\"c276490e553b4cc15809743a1d7426b5\"","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","x-robots-tag":"noindex"},"url":"https://jsr.io/@std/path/0.224.0/posix/common.ts","time":1785241875}