# @dazl/fs-utils 中文文档

规范地址：https://npmcn.com/package/%40dazl/fs-utils/

版本：18\.10\.0
npm 元数据更新时间：2026-08-07T07:10:28.740Z
中文译文更新时间：2026-11-11T16:48:54.869Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40dazl/fs-utils
原文对照：https://npmcn.com/package/%40dazl/fs-utils/?lang=original
项目主页：https://github.com/dazl-dev/core3-utils#readme
源码仓库：https://github.com/dazl-dev/core3-utils

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

- 包体积（解压后）：53 kB，27 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- 运行依赖：4 个
- 首次发布：2025-08-27T19:21:27.517Z
- 最新版本发布：2026-03-29T22:49:11.737Z
- 近 30 天下载量：10075（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：9（近 12 个月 6 个）

## 中文简介

可在所有环境中使用的文件系统 utils

## 安装

```sh
npm install @dazl/fs-utils
```

也可以使用：`pnpm add @dazl/fs-utils`、`yarn add @dazl/fs-utils`、`bun add @dazl/fs-utils`

## README

[![npm version](https://badge.fury.io/js/@dazl%2Ffs-utils.svg)](https://badge.fury.io/js/@dazl%2Ffs-utils) [@dazl/fs-utils 在吉苏布](https://github.com/dazl-dev/core3-utils/tree/main/packages/fs-utils)

[内容](https://dazl-dev.github.io/core3-utils/index) > 翻译: [@dazl/fs-utils (英语)](https://dazl-dev.github.io/core3-utils/fs-utils)

## fs- 实用软件包

## 职能

| 函数 | 说明 |
| --- | --- |
| [添加前缀( 路径)](https://dazl-dev.github.io/core3-utils/fs-utils.addrelativeprefix) |  |
| [创建 ImpportPath ({导入FilePath, 目标FilePath, 目标PackageJsonPath, fs, })](https://dazl-dev.github.io/core3-utils/fs-utils.createimportpath) | 如果导入文件和目标文件在同一包中,则返回相对导入路径,否则则返回一个光导导入描述符. |
| [格式 TOSpaths( st)](https://dazl-dev.github.io/core3-utils/fs-utils.formattoospaths) |  |
| [获得BareImportSpecifier(绝对导入 Path, 软件包 JsonPath, 软件包JsonName](https://dazl-dev.github.io/core3-utils/fs-utils.getbareimportspecifier) | 创建绝对导入路径的光导导入描述符, 从 JS/ TS 文件中删除扩展名 . |
| [获取 DTSPath( 文件 Path)](https://dazl-dev.github.io/core3-utils/fs-utils.getdtspath) |  |
| [获取FullExtname( 文件路径)](https://dazl-dev.github.io/core3-utils/fs-utils.getfullextname) | 返回“.”的第一次出现时的文件扩展名,与上次出现时返回的路径.extname()不同. |
| [获取导入Path( 文件Path)](https://dazl-dev.github.io/core3-utils/fs-utils.getimportpath) |  |
| [获取 Package JsonPath( 文件 Path, fs)](https://dazl-dev.github.io/core3-utils/fs-utils.getpackagejsonpath) | 获取最接近给定文件路径的 package.json 文件的路径 . |
| [获取包Name( dirPath, fs)](https://dazl-dev.github.io/core3-utils/fs-utils.getpackagename) | 获取软件包名称 . |
| [获取PackagePath( 文件Path, fs)](https://dazl-dev.github.io/core3-utils/fs-utils.getpackagepath) | 获取到包目录的路径,最接近给定的文件路径. |
| [获得Relative ImportPath( 源文件文件文件文件文件文件文件导入)](https://dazl-dev.github.io/core3-utils/fs-utils.getrelativeimportpath) | 创建文件的相对导入路径, 从 JS/ TS 文件取出扩展名 . |
| [获得RelativeModulePath( 源代码AbsFilePath, 目标代码AbsFilePath)](https://dazl-dev.github.io/core3-utils/fs-utils.getrelativemodulepath) |  |
| [是 DirPath( 文件Path) 语句](https://dazl-dev.github.io/core3-utils/fs-utils.isdirpath) |  |
| [是JavaScriptFile( 文件Path) 语句](https://dazl-dev.github.io/core3-utils/fs-utils.isjavascriptfile) |  |
| [是 JsonFile( 文件盘)](https://dazl-dev.github.io/core3-utils/fs-utils.isjsonfile) |  |
| [是Path IncludesDir( 文件Path, 目录Name](https://dazl-dev.github.io/core3-utils/fs-utils.ispathincludesdir) | 安全检查路径是否包含目录名称 . |
| [是Relative ModulePath(路径)](https://dazl-dev.github.io/core3-utils/fs-utils.isrelativemodulepath) |  |
| [isRelative Module 请求( 请求)](https://dazl-dev.github.io/core3-utils/fs-utils.isrelativemodulerequest) |  |
| [是SubPath( 路径, 碱性Path, fs)](https://dazl-dev.github.io/core3-utils/fs-utils.issubpath) | 检查路径是否等于或子路径 . |
| [是 TsOrJS( 文件盘)](https://dazl-dev.github.io/core3-utils/fs-utils.istsorjs) |  |
| [是TypeAffecting FileOrDir( 文件Path) 图像](https://dazl-dev.github.io/core3-utils/fs-utils.istypeaffectingfileordir) |  |
| [是 TypeScriptFile( 文件Path) 语句](https://dazl-dev.github.io/core3-utils/fs-utils.istypescriptfile) |  |
| [绝对是 Windows StyleAboutePath( fsPath)](https://dazl-dev.github.io/core3-utils/fs-utils.iswindowsstyleabsolutepath) |  |
| [路径 ChanToRoot( 当前路径)](https://dazl-dev.github.io/core3-utils/fs-utils.pathchaintoroot) |  |
| [路径TrueCase( fs, 路径)](https://dazl-dev.github.io/core3-utils/fs-utils.pathtotruecase) | 返回路径的大小写绝对形式,类似于 fs. realpathSync.native() 路径中不存在的轨迹片段保持不变. |
| [已读 packageJson( dirPath, fs)](https://dazl-dev.github.io/core3-utils/fs-utils.readpackagejson) | 读取并解析目录的软件包. json |
| [重基调ModulePath( 文件Path, 模块Path)](https://dazl-dev.github.io/core3-utils/fs-utils.rebaserelativemodulepath) |  |
| [替换 WinSwash( 字符串)](https://dazl-dev.github.io/core3-utils/fs-utils.replacewinslashes) |  |

## 接口

| 接口 | 说明 |
| --- | --- |
| [调整](https://dazl-dev.github.io/core3-utils/fs-utils.adjustrelativeimportpathargs) |  |
| [创建导入路径](https://dazl-dev.github.io/core3-utils/fs-utils.createimportpathargs) |  |

## 变量

| 变量 | 说明 |
| --- | --- |
| [文件请求前缀](https://dazl-dev.github.io/core3-utils/fs-utils.filerequestprefix) | 语言服务器协议中文件请求的前缀 |

## 常见问题

### @dazl/fs-utils 是什么？

可在所有环境中使用的文件系统 utils

### 如何安装 @dazl/fs-utils？

在项目目录运行 npm install @dazl/fs-utils，或使用 pnpm add / yarn add / bun add。

### @dazl/fs-utils 支持 TypeScript 吗？

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

### @dazl/fs-utils 支持 ESM 还是 CommonJS？

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

### @dazl/fs-utils 可以商用吗？

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

### @dazl/fs-utils 的下载量有多少？

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

### @dazl/fs-utils 还在维护吗？

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

