# @choojs/findup 中文文档

规范地址：https://npmcn.com/package/%40choojs/findup/

版本：0\.2\.1
npm 元数据更新时间：2023-11-02T16:31:56.383Z
中文译文更新时间：2026-11-09T14:23:27.042Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40choojs/findup
原文对照：https://npmcn.com/package/%40choojs/findup/?lang=original
项目主页：https://github.com/choojs/findup
源码仓库：https://github.com/choojs/findup

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：13.4 kB，10 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：1 个
- 首次发布：2018-04-11T11:57:31.532Z
- 最新版本发布：2018-06-01T08:32:14.533Z
- 近 30 天下载量：3574307（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

通过走上目录树查找文件

## 安装

```sh
npm install @choojs/findup
```

也可以使用：`pnpm add @choojs/findup`、`yarn add @choojs/findup`、`bun add @choojs/findup`

## README

# [![build status](https://secure.travis-ci.org/choojs/findup.png)](http://travis-ci.org/choojs/findup) @choojs/发现

> 这是叉子 [Filirom1/ 发现](https://github.com/Filirom1/findup)待定 [16号](https://github.com/Filirom1/findup/pull/16)。 。 。 .

### 安装

```sh
npm install -g @choojs/findup
```

### 使用量

在祖先的目录中查找文件

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

### 选项

-   `maxdepth`: (数目, 默认-1) 放弃前要穿越多远 如果最大深度为 `-1`,则没有限制.

#### 自动同步

查找( dir, 文件Name, 选项, 回调) 查找( dir, 转发器, 选项, 回调) `iterator(dir, cb)` 仅接受 cb `true` 或者说 `false`

```js
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'
});
```

或者说

```js
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'
});
```

#### 事件编辑器

查找( dir, 文件Name, 选项)

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

查找( dir, 转发器, 选项) `iterator(dir, cb)` 仅接受 cb `true` 或者说 `false`

```js
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);
});
```

找到返回事件Emiter。 发布3个事件: `found`, (中文(简体) ), `error`, (中文(简体) ), `end`

`found` 每次找到文件时都会发出事件.

你可以打个电话来阻止这段旅程 `stop` 手动.

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

`error` 出错时会释放事件

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

`end` 事件在翻转结束时或之后释放 `stop()` 实值 电话.

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

#### 同步

查找( dir, 文件Name 查找( dir, 转发器Sync) 与 `iteratorSync` 返回时 `true` 或者说 `false`

```js
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')
}
```

#### 国 际

```js
npm install -g @choojs/findup

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

使用量

```
$ 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
```

### 麻省理工学院

### 阅读测试:)

## 常见问题

### @choojs/findup 是什么？

通过走上目录树查找文件

### 如何安装 @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 和提交记录判断。

