common-ancestor-path
Find the common ancestor of 2 or more paths on Windows or Unix
Last updated 5 months ago by isaacs .
BlueOak-1.0.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install common-ancestor-path 
SYNC missed versions from official npm registry.

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.

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.

Current Tags

  • 2.0.0                                ...           latest (5 months ago)

3 Versions

  • 2.0.0                                ...           5 months ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (6)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |