normalize-path

中文文档
3.0.0发布于 2018/04/19MITCommonJS零依赖近 30 天下载 5.6亿

Normalize slashes in a file path to be posix/unix-like forward slashes. Also condenses repeat slashes to a single slash and removes and trailing slashes, unless disabled.

原始使用文档
文档目录10 节
  1. Install
  2. Usage
  3. Trailing slashes
  4. Release history
  5. v3.0
  6. About
  7. Related projects
  8. Contributors
  9. Author
  10. License

normalize-path NPM version NPM monthly downloads NPM total downloads Linux Build Status

Normalize slashes in a file path to be posix/unix-like forward slashes. Also condenses repeat slashes to a single slash and removes and trailing slashes, unless disabled.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.

Install

Install with npm:

$ npm install --save normalize-path

Usage

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

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

win32 namespaces

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

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

Consecutive slashes

Condenses multiple consecutive forward slashes (except for leading slashes in win32 namespaces) to a single slash.

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

Trailing slashes

By default trailing slashes are removed. Pass false as the last argument to disable this behavior and keep trailing slashes:

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

Release history

v3.0

No breaking changes in this release.

  • a check was added to ensure that win32 namespaces are handled properly by win32 path.parse() after a path has been normalized by this library.
  • a minor optimization was made to simplify how the trailing separator was handled

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

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

Other useful path-related libraries:

Contributors

| Commits | Contributor | | --- | --- | | 35 | jonschlinkert | | 1 | phated |

Author

Jon Schlinkert

License

Copyright © 2018, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on April 19, 2018.

版本与发布记录

normalize-path 共发布 11 个版本,首次发布于 2014/06/26;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.0latest2018/04/198 年前
2.1.12017/03/309 年前
2.1.02017/03/309 年前
2.0.12015/11/1710 年前
2.0.02015/10/0411 年前
1.0.02015/01/2411 年前

关于 normalize-path 的常见问题

normalize-path 是什么?

Normalize slashes in a file path to be posix/unix-like forward slashes. Also condenses repeat slashes to a single slash and removes and trailing slashes, unless disabled.

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