@choojs/findup

中文文档
0.2.1发布于 2018/06/01MITCommonJS近 30 天下载 357.4万

Find a file by walking up the directory tree

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. Options
  4. LICENSE MIT
  5. Read the tests :)

build status @choojs/findup

This is a fork of Filirom1/findup, pending #16.

Install

npm install -g @choojs/findup

Usage

Find up a file in ancestor's dir

.
├── config.json
└── f
    └── e
        └── d
            └── c
                ├── b
                │   └── a
                └── config.json

Options

  • maxdepth: (Number, default -1) How far to traverse before giving up. If maxdepth is -1, then there is no limit.

Async

findup(dir, fileName, options, callback) findup(dir, iterator, options, callback) with iterator(dir, cb) where cb only accept true or false

var findup = require('@choojs/findup');


findup(__dirname + '/f/e/d/c/b/a', 'config.json', function(err, dir){
  // if(e) e === new Error('not found')
  // dir === '/f/e/d/c'
});

or

findup(__dirname + '/f/e/d/c/b/a', function(dir, cb){
  require('path').exists(dir + '/config.json', cb);
}, function(err, dir){
  // if(e) e === new Error('not found')
  // dir === '/f/e/d/c'
});

EventEmitter

findup(dir, fileName, options)

var findup = require('@choojs/findup');
var fup = findup(__dirname + '/f/e/d/c/b/a', 'config.json');

findup(dir, iterator, options) with iterator(dir, cb) where cb only accept true or false

var findup = require('@choojs/findup');
var fup = findup(__dirname + '/f/e/d/c/b/a', function(dir, cb){
  require('path').exists(dir + '/config.json', cb);
});

findup return an EventEmitter. 3 events are emitted: found, error, end

found event is emitted each time a file is found.

You can stop the traversing by calling stop manually.

fup.on('found', function(dir){
  // dir === '/f/e/d/c'
  fup.stop();
});

error event is emitted when error happens

fup.on('error', function(e){
  // if(e) e === new Error('not found')
});

end event is emitted at the end of the traversing or after stop() is called.

fup.on('end', function(){
  // happy end
});

Sync

findup(dir, fileName) findup(dir, iteratorSync) with iteratorSync return true or false

var findup = require('@choojs/findup');

try{
  var dir = findup.sync(__dirname + '/f/e/d/c/b/a', 'config.json'); // dir === '/f/e/d/c'
}catch(e){
  // if(e) e === new Error('not found')
}

CLI

npm install -g @choojs/findup

$ cd test/fixture/f/e/d/c/b/a/
$ findup package.json
/root/findup/package.json

Usage

$ findup -h

Usage: findup [FILE]

    --name, -n       The name of the file to found
    --dir, -d        The directoy where we will start walking up    $PWD
    --help, -h       show usage                                     false
    --verbose, -v    print log                                      false

LICENSE MIT

Read the tests :)

版本与发布记录

@choojs/findup 共发布 2 个版本,首次发布于 2018/04/11;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.1latest2018/06/018 年前
0.2.02018/04/118 年前

关于 @choojs/findup 的常见问题

@choojs/findup 是什么?

Find a file by walking up the directory tree

如何安装 @choojs/findup?

在项目目录运行 npm install @choojs/findup,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 findup,可以用 npx findup 直接运行。

@choojs/findup 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/choojs__findup 是否存在。

@choojs/findup 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@choojs/findup 可以商用吗?

@choojs/findup 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@choojs/findup 的下载量有多少?

根据 npm 官方下载统计,@choojs/findup 在 2026/10/10 – 2026/11/08 这 30 天内被下载 3,574,307 次,日均约 119,144 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@choojs/findup 还在维护吗?

最新版本 0.2.1 发布于 2018/06/01(8 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/04/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。