common-dir
Version:
Returns the parent directory common to each path
38 lines (29 loc) • 1.58 kB
Markdown
[](https://www.npmjs.org/package/common-dir)
[](https://www.npmjs.org/package/common-dir)
[](https://github.com/75lb/common-dir/network/dependents?dependent_type=REPOSITORY)
[](https://github.com/75lb/common-dir/network/dependents?dependent_type=PACKAGE)
[](https://travis-ci.org/75lb/common-dir)
[](https://github.com/feross/standard)
<a name="module_common-dir"></a>
## common-dir
<a name="exp_module_common-dir--commonDir"></a>
### commonDir(files) ⇒ <code>string</code> ⏏
Returns the parent directory common to each path.
**Kind**: Exported function
**Returns**: <code>string</code> - A single path ending with the path separator, e.g. '/user/some/folder/'
| Param | Type | Description |
| --- | --- | --- |
| files | <code>Array</code> | An array of file paths to inspect |
**Example**
```js
> const commonDir = require('common-dir')
> files = [
'/Users/75lb/one/package.json',
'/Users/75lb/one/test',
'/Users/75lb/two/test/main.js'
]
> commonDir(files)
'/Users/75lb/'
```
* * *
© 2014-21 Lloyd Brookes <75pound@gmail.com>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).