mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 22:02:33 +00:00
![]() PR-URL: https://github.com/nodejs/node/pull/35474 Reviewed-By: Ruy Adorno <ruyadorno@github.com> Reviewed-By: Ujjwal Sharma <ryzokuken@disroot.org> Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> |
||
---|---|---|
.. | ||
index.js | ||
LICENSE | ||
package.json | ||
README.md |
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.
const ancestor = require('common-ancestor-path')
// output /a/b
console.log(ancestor('/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(ancestor('C:\\a\\b\\c', 'C:\\a\\b\\x'))
// no common ancestor on different windows drive letters
// so, this returns null
console.log(ancestor('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.