# normalize-path 中文文档

规范地址：https://npmcn.com/package/normalize-path/

版本：3\.0\.0
npm 元数据更新时间：2023-03-04T04:01:45.310Z
中文译文更新时间：2026-11-05T14:34:35.451Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/normalize-path
原文对照：https://npmcn.com/package/normalize-path/?lang=original
项目主页：https://github.com/jonschlinkert/normalize-path
源码仓库：https://github.com/jonschlinkert/normalize-path

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

- 包体积（解压后）：9.2 kB，4 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=0\.10\.0
- 运行依赖：0 个
- 首次发布：2014-06-26T01:32:19.923Z
- 最新版本发布：2018-04-19T14:54:47.609Z
- 近 30 天下载量：560012088（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：11（近 12 个月 0 个）

## 中文简介

将文件路径中的斜杠规范化为posix/unix类型的正斜杠。还将重复斜杠压缩为单个斜杠并删除和尾随斜杠，除非禁用。

## 安装

```sh
npm install normalize-path
```

也可以使用：`pnpm add normalize-path`、`yarn add normalize-path`、`bun add normalize-path`

## README

# 正常路径 [![NPM version](https://img.shields.io/npm/v/normalize-path.svg?style=flat)](https://www.npmjs.com/package/normalize-path) [![NPM monthly downloads](https://img.shields.io/npm/dm/normalize-path.svg?style=flat)](https://npmjs.org/package/normalize-path) [![NPM total downloads](https://img.shields.io/npm/dt/normalize-path.svg?style=flat)](https://npmjs.org/package/normalize-path) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/normalize-path.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/normalize-path)

> 在文件路径中将鞭打规范化为 posix/ unix 类似前鞭. 另外缩放会重复被鞭打为一刀并去掉并跟随被鞭打,除非是被禁用.

请考虑跟随这个项目的作者, [乔恩·斯林克特](https://github.com/jonschlinkert),并考虑主演该项目以显示你的:心:和支持.

## 安装

安装方式 [无](https://www.npmjs.com/)数字 :

```sh
$ npm install --save normalize-path
```

## 使用量

```js
const normalize = require('normalize-path');

console.log(normalize('\\foo\\bar\\baz\\')); 
//=> '/foo/bar/baz'
```

**win32 命名空间**

```js
console.log(normalize('\\\\?\\UNC\\Server01\\user\\docs\\Letter.txt')); 
//=> '//?/UNC/Server01/user/docs/Letter.txt'

console.log(normalize('\\\\.\\CdRomX')); 
//=> '//./CdRomX'
```

**连续鞭打**

将多条相接的前向斜线(除了在win32命名空间中的前向斜线)收缩为一刀.

```js
console.log(normalize('.//foo//bar///////baz/')); 
//=> './foo/bar/baz'
```

### 轨迹斜拉

默认会去掉鞭子 过 `false` 作为禁用此行为的最后一个参数 _**保留** 沿着斜线走_数字 :

```js
console.log(normalize('foo\\bar\\baz\\', false)); //=> 'foo/bar/baz/'
console.log(normalize('./foo/bar/baz/', false)); //=> './foo/bar/baz/'
```

## 发布历史

### 3⁄4 ̄ ̧漯b

此发行中无中断更改 .

-   增加了检查以确保 [win32 命名空间](https://msdn.microsoft.com/library/windows/desktop/aa365247\(v=vs.85\).aspx#namespaces) 由 win32 妥善处理 `path.parse()` 在一个路径被此库规范后 .
-   进行了微小优化,以简化跟踪分隔符的处理方式

## 关于

**捐款**

拉出请求和星星总是受欢迎的. 对于错误和特性请求, [请创建一个问题](https://npmcn.com/issues/new)。 。 。 .

**运行测试**

运行和审查单元测试是熟悉图书馆及其API的好办法。 您可以使用以下命令安装依赖性并运行测试:

```sh
$ npm install && npm test
```
**大楼文件**

_(此工程的 readme.md 由 [动词](https://github.com/verbose/verb-generate-readme)请不要直接编辑读取器。 读取器的任何改动必须在 [动词 md](https://npmcn.com/package/normalize-path/.verb.md) 读取我的模板。 )_

要生成读取, 请运行以下命令 :

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### 相关项目

其他有用的路径相关图书馆:

-   [包含路径](https://www.npmjs.com/package/contains-path): 如果文件路径包含给定路径, 返回真实性 。\\\\\\ x [主页](https://github.com/jonschlinkert/contains-path "Return true if a file path contains the given path.")
-   [绝对是](https://www.npmjs.com/package/is-absolute): 如果文件路径是绝对的, 返回真实性 。 不依赖路径模块.. [更多](https://github.com/jonschlinkert/is-absolute) | [主页](https://github.com/jonschlinkert/is-absolute "Returns true if a file path is absolute. Does not rely on the path module and can be used as a polyfill for node.js native `path.isAbolute`.")
-   [相对](https://www.npmjs.com/package/is-relative): 回归 `true` 如果路径似乎是相对的 [主页](https://github.com/jonschlinkert/is-relative "Returns `true` if the path appears to be relative.")
-   [解析文件路径](https://www.npmjs.com/package/parse-filepath): pollyfill for node.js (中文(简体) ) `path.parse`,将文件路径解析为对象 [主页](https://github.com/jonschlinkert/parse-filepath "Pollyfill for node.js `path.parse`, parses a filepath into an object.")
-   [路径端](https://www.npmjs.com/package/path-ends-with)编号: 返回 `true` 如果一个文件路径以给定的字符串/后缀结尾。\\\\\\ x [主页](https://github.com/jonschlinkert/path-ends-with "Return `true` if a file path ends with the given string/suffix.")
-   [取消对齐](https://www.npmjs.com/package/unixify): 将 Windows 文件路径转换为 unix 路径 。 [主页](https://github.com/jonschlinkert/unixify "Convert Windows file paths to unix paths.")

### 贡献者

| **提交** | **贡献者** | | -- -- -- -- -- -- -- | 35 | [扬施林克特](https://github.com/jonschlinkert) | | 1 | [发烧](https://github.com/phated) |

### 作者

**乔恩·斯林克特**

-   [链接到配置文件](https://linkedin.com/in/jonschlinkert)
-   [GitHub 配置文件](https://github.com/jonschlinkert)
-   [推特简介](https://twitter.com/jonschlinkert)

### 许可证

版权: 2018, [乔恩·斯林克特](https://github.com/jonschlinkert)。 。 。 . 释放 [MIT 许可证](https://npmcn.com/package/normalize-path/LICENSE)。 。 。 .

* * *

_此文件由 [动词基因读取器](https://github.com/verbose/verb-generate-readme),v 6.0,于2018年4月19日查阅._

## 常见问题

### normalize-path 是什么？

将文件路径中的斜杠规范化为posix/unix类型的正斜杠。还将重复斜杠压缩为单个斜杠并删除和尾随斜杠，除非禁用。

### 如何安装 normalize-path？

在项目目录运行 npm install normalize-path，或使用 pnpm add / yarn add / bun add。

### normalize-path 支持 TypeScript 吗？

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

### normalize-path 支持 ESM 还是 CommonJS？

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

### normalize-path 需要什么版本的 Node\.js？

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

### normalize-path 可以商用吗？

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

### normalize-path 的下载量有多少？

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

### normalize-path 还在维护吗？

最新版本 3\.0\.0 发布于 2018/04/19（8 年前）；至今共发布 11 个版本，其中过去 12 个月发布了 0 个；首次发布于 2014/06/26。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

