Socket
Socket
Sign inDemoInstall

common-ancestor-path

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    common-ancestor-path

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


Version published
Weekly downloads
2M
decreased by-16.63%
Maintainers
1
Install size
3.55 kB
Created
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 for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • 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