# @humanfs/core 中文文档

规范地址：https://npmcn.com/package/%40humanfs/core/

版本：0\.20\.0
npm 元数据更新时间：2026-09-10T12:48:23.184Z
中文译文更新时间：2026-11-05T14:51:32.908Z
软件包许可：Apache-2\.0

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

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

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

- 包体积（解压后）：66.7 kB，11 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=24\.0\.0
- 运行依赖：1 个
- 首次发布：2024-01-30T00:34:31.713Z
- 最新版本发布：2026-09-10T12:48:22.791Z
- 近 30 天下载量：506263887（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：20（近 12 个月 2 个）

## 中文简介

人文图书馆的核心.

## 安装

```sh
npm install @humanfs/core
```

也可以使用：`pnpm add @humanfs/core`、`yarn add @humanfs/core`、`bun add @humanfs/core`

## README

# `@humanfs/core`

以 [尼古拉斯·扎卡斯](https://humanwhocodes.com/)

如果你觉得有用,请考虑支持我的工作 [捐赠](https://humanwhocodes.com/donate) 或者说 [提名我](https://stars.github.com/nominate/) 为吉他之星.

## 说明

在所有运行时间的所有执行中共享的人机核心功能. 本套件的内容有意是运行时间不可知的,并非打算单独使用.

目前,这个软件包只是输出 `Hfs` 类,这是一个抽象的基础类,意在从运行时特定的hfs包中继承(如 `@humanfs/node`) (中文(简体) ).

> \[尖叫声\] 这个项目是 **实验** 在v1.0.0之前可能会发生重大变化。 用你自己的谨慎,绝对不要生产!

## 安装

### 节点.js

使用您最喜欢的节点软件包管理器安装 :

```shell
npm install @humanfs/core

# or

pnpm install @humanfs/core

# or

yarn add @humanfs/core

# or

bun install @humanfs/core
```

然后你可以导入 `Hfs` 财务报告和审定财务报表 `Path` 像这样的课程 :

```js
import { Hfs, Path } from "@humanfs/core";
```

### 德诺

使用 [日 尔](https://jsr.io/)数字 :

```shell
deno add @humanfs/core

# or

jsr add @humanfs/core
```

然后你可以导入 `Hfs` 像这样的课:

```js
import { Hfs, Path } from "@humanfs/core";
```

### 浏览器

建议导入精密版本以节省带宽:

```js
import { Hfs, Path } from "https://cdn.skypack.dev/@humanfs/core?min";
```

然而,您也可以导入未修改的版本用于调试:

```js
import { Hfs, Path } from "https://cdn.skypack.dev/@humanfs/core";
```

## 使用量

### `Hfs` 类

这个 `Hfs` 类包含一个 `Hfs` 实例 _无_ 预定义的 impl。 此类主要用于创建运行时间特定简表, 例如 `NodeHfs` 财务报告和审定财务报表 `DenoHfs`。 。 。 .

您可以通过提供 `impl` 直接 :

```js
const hfs = new Hfs({ impl: { async text() {} }});
```

指定的 `impl` 成为实例的基础 , 意思是, 你总是可以重置回它 `resetImpl()`。 。 。 .

您也可以继承 `Hfs` 用预设的简便来创建自己的课程,例如:

```js
class MyHfs extends Hfs {
    constructor() {
        super({
            impl: myImpl
        });
    }
}
```

### `Path` 类

这个 `Path` 类代表文件系统内目录或文件的路径。 它是一种抽象的表示方式,即使在传统文件系统之外也可以使用,在传统文件系统中,字符串路径可能不合理.

```js
const myPath = new Path(["dir", "subdir"]);
console.log(myPath.toString());		// "dir/subdir"

// add another step
myPath.push("file.txt");
console.log(myPath.toString());		// "dir/subdir/file.txt"

// get just the last step
console.log(myPath.name);			// "file.txt"

// change just the last step
myPath.name = "file.json";
console.log(myPath.name);			// "file.json"
console.log(myPath.toString());		// "dir/subdir/file.json"

// get the size of the path
console.log(myPath.size);			// 3

// remove the last step
myPath.pop();
console.log(myPath.toString());		// "dir/subdir"

// iterate over the steps
for (const step of myPath) {
    // do something
}

// create a new path from a string
const newPath = Path.fromString("/foo/bar");
```

## 许可证

Apache 2.0 (英语)

## 常见问题

### @humanfs/core 是什么？

人文图书馆的核心\.

### 如何安装 @humanfs/core？

在项目目录运行 npm install @humanfs/core，或使用 pnpm add / yarn add / bun add。

### @humanfs/core 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @humanfs/core 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @humanfs/core 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=24\.0\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @humanfs/core 可以商用吗？

@humanfs/core 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @humanfs/core 的下载量有多少？

根据 npm 官方下载统计，@humanfs/core 在 2026/10/07 – 2026/11/05 这 30 天内被下载 506,263,887 次，日均约 16,875,463 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @humanfs/core 还在维护吗？

最新版本 0\.20\.0 发布于 2026/09/10（1 个月前）；至今共发布 20 个版本，其中过去 12 个月发布了 2 个；首次发布于 2024/01/30。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

