# common-ancestor-path

> Find the common ancestor of 2 or more paths on Windows or Unix

Latest version **2.0.0** (published 2025-11-25) · BlueOak-1.0.0 license · 0 weekly downloads

## Install

```sh
npm install common-ancestor-path
pnpm add common-ancestor-path
yarn add common-ancestor-path
bun add common-ancestor-path
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2025-11-25 |
| First published | 2020-05-25 |
| Weekly downloads | 0 |
| License | BlueOak-1.0.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 18 |
| Dependencies | 0 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Isaac Z. Schlueter |
| Maintainers | isaacs |

## Links

- npm: https://www.npmjs.com/package/common-ancestor-path
- Repository: https://github.com/isaacs/common-ancestor-path
- Homepage: https://github.com/isaacs/common-ancestor-path#readme
- Issues: https://github.com/isaacs/common-ancestor-path/issues
- npm.io page: https://npm.io/package/common-ancestor-path

## Recent versions

- 2.0.0 (latest) — 2025-11-25
- 1.0.1 — 2020-05-25
- 1.0.0 — 2020-05-25

## README

# common-ancestor-path

Find the common ancestor of 2 or more paths on Windows or Unix

## USAGE

Give it two or more path strings, and it'll do the thing.

```ts
import { commonAncestorPath } from 'common-ancestor-path'
// or:
// const { commonAncestorPath } = require('common-ancestor-path')

// output /a/b
console.log(commonAncestorPath('/a/b/c/d', '/a/b/x/y/z', '/a/b/c/i/j/k'))

// normalizes separators, but NOT cases, since it matters sometimes
console.log(commonAncestorPath('C:\\a\\b\\c', 'C:\\a\\b\\x'))

// no common ancestor on different windows drive letters
// so, this returns null
console.log(commonAncestorPath('c:\\a\\b\\c', 'd:\\d\\e\\f'))
```

## API

`commonAncestorPath(...paths)`

Returns the nearest (deepest) common ancestor path, or `null` if on
different roots on Windows.

---
_Source: https://npm.io/package/common-ancestor-path · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
