Huge news!Announcing our $20M Series A led by Andreessen Horowitz.Learn more
Socket
Socket
Log inDemoInstall

common-ancestor-path

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Issues
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

common-ancestor-path

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

    1.0.1latest
    GitHub
    npm

Version published
Maintainers
1
Weekly downloads
1,834,114
increased by4.77%

Weekly downloads

Readme

Source

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.

FAQs

Last updated on 25 May 2020

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install
SocketSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc