What is commondir?
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.
What are commondir's main functionalities?
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'
Other packages similar to commondir
path-common
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
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.
commondir
compute the closest common parent directory among an array of directories
example
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
methods
var commondir = require('commondir');
commondir(absolutePaths)
Compute the closest common parent directory for an array absolutePaths
.
commondir(basedir, relativePaths)
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)
.
install
With npm do:
npm install commondir
license
MIT