find-parent-dir

Finds the first parent directory that contains a given file or directory.

MIT 5 个版本
安装
npm install find-parent-dir
yarn add find-parent-dir
pnpm add find-parent-dir
bun add find-parent-dir
README

find-parent-dir build status

Finds the first parent directory that contains a given file or directory.

npm install find-parent-dir
// assuming this is called from a file in a subdirectory of /myprojects/foo which contains .git directory
var findParentDir = require('find-parent-dir');

findParentDir(__dirname, '.git', function (err, dir) {
  // has err if some file access error occurred
  console.log(dir); // => /myprojects/foo/
  
  // if parent dir wasn't found, dir is null
})

// Same using `sync` method
var dir;
try { 
  dir = findParentDir.sync(__dirname, '.git');
  console.log(dir); // => /myprojects/foo/
  // if parent dir wasn't found, dir is null
} catch(err) {
  console.error('error', err); 
}
版本列表
0.3.1 2021-05-14
0.3.0 2014-03-29
0.2.1 2014-02-03
0.2.0 2014-01-27
0.1.0 2013-05-25