Product
Introducing Ruby Support in Socket
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
The commondir npm package is a simple utility that helps you find the common parent directory among an array of file paths. This can be particularly useful in file system operations where you need to determine the shared base directory for a group of files.
Finding common directory
This feature allows you to find the common parent directory from an array of file paths. In the provided code, the common directory for '/usr/lib/node_modules' and '/usr/lib/node' is calculated, which results in '/usr/lib'.
const commondir = require('commondir');
const paths = ['/usr/lib/node_modules', '/usr/lib/node'];
const commonPath = commondir(paths);
console.log(commonPath); // Outputs: '/usr/lib'
path-common is another npm package that provides functionality to find the common path among multiple paths. It is similar to commondir but might offer different methods or additional features for handling edge cases or specific path operations.
find-root is a package that helps in finding the root directory of a project by traversing up the current directory until a specific marker file (like 'package.json') is found. While it serves a different purpose, it is related in terms of navigating and determining directory structures, which can be somewhat similar to what commondir does.
compute the closest common parent directory among an array of directories
var commondir = require('commondir');
var dir = commondir(process.argv.slice(2))
console.log(dir);
output:
$ node dir.js /x/y/z /x/y /x/y/w/q
/x/y
$ node ../baz ../../foo/quux ./bizzy
/foo
var commondir = require('commondir');
Compute the closest common parent directory for an array absolutePaths
.
Compute the closest common parent directory for an array relativePaths
which
will be resolved for each dir
in relativePaths
according to:
path.resolve(basedir, dir)
.
With npm do:
npm install commondir
MIT
FAQs
compute the closest common parent for file paths
We found that commondir demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.