@flex-development/pathe

中文文档
4.0.2发布于 2025/05/30BSD-3-ClauseTypeScriptES Module构建来源已验证近 30 天下载 6072

Universal drop-in replacement for node:path

原始使用文档
文档目录8 节
  1. Contents
  2. What is this?
  3. When should I use this?
  4. Install
  5. Use
  6. API
  7. Types
  8. Contribute

pathe

github release npm codecov license conventional commits typescript vitest yarn

Universal drop-in replacement for node:path

Contents

What is this?

This package is a universal drop-in replacement for Node.js' path module.

It enforces consistency between POSIX and Windows operating systems and also provides additional utilities for working with file URLs, paths, and extensions.

When should I use this?

For historical reasons, Windows followed MS-DOS and used backslashes (\) to separate path components, as opposed to the forwardslashes (/) used by POSIX operating systems. Even though Windows operating systems now support both separators, there are still discrepancies between operating systems when using Node.js' path module:

The default operation of the node:path module varies based on the operating system on which a Node.js application is running. Specifically, when running on a Windows operating system, the node:path module will assume that Windows-style paths are being used. – Windows vs. POSIX

This package enforces consistency between operating systems by ensuring paths are POSIX-compliant. With support for both drive and UNC paths as well, platform-specific modules like node:path/posix and node:path/win32 are no longer needed.

To achieve consistent results when working with Windows file paths on any operating system, use path.win32. To achieve consistent results when working with POSIX file paths on any operating system, use path.posix.

To achieve consistent results when working with Windows file paths on any operating system, use pathe. To achieve consistent results when working with POSIX file paths on any operating system, use pathe. :blush:

Install

This package is ESM only.

In Node.js (version 18+) with yarn:

yarn add @flex-development/pathe
See Git - Protocols | Yarn  for details regarding installing from Git.

In Deno with esm.sh:

import { parse } from 'https://esm.sh/@flex-development/pathe'

In browsers with esm.sh:

<script type="module">
  import { parse } from 'https://esm.sh/@flex-development/pathe'
</script>

Use

import {
  addExt,
  basename,
  changeExt,
  cwd,
  delimiter,
  dirname,
  dot,
  extToValue,
  extname,
  fileURLToPath,
  format,
  formatExt,
  isAbsolute,
  isDeviceRoot,
  isSep,
  isURL,
  join,
  matchesGlob,
  normalize,
  parse,
  pathToFileURL,
  relative,
  removeExt,
  resolve,
  resolveWith,
  root,
  sep,
  toNamespacedPath,
  toPath,
  toPosix
} from '@flex-development/pathe'

API

This package exports the following identifiers:

The default export is pathe.

Documentation website coming soon.

Types

This package is fully typed with TypeScript.

Contribute

See CONTRIBUTING.md.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

版本与发布记录

@flex-development/pathe 共发布 9 个版本,首次发布于 2022/12/16;过去 12 个月发布了 0 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.0.2latest2025/05/301.5 年前
4.0.12024/12/241.9 年前
4.0.02024/12/181.9 年前
3.0.02024/10/022 年前
2.0.02023/07/303 年前
1.0.32023/01/023 年前

关于 @flex-development/pathe 的常见问题

@flex-development/pathe 是什么?

Universal drop-in replacement for node:path

如何安装 @flex-development/pathe?

在项目目录运行 npm install @flex-development/pathe,或使用 pnpm add / yarn add / bun add。

@flex-development/pathe 支持 TypeScript 吗?

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

@flex-development/pathe 支持 ESM 还是 CommonJS?

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

@flex-development/pathe 需要什么版本的 Node.js?

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

@flex-development/pathe 可以商用吗?

@flex-development/pathe 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

@flex-development/pathe 的下载量有多少?

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

@flex-development/pathe 还在维护吗?

最新版本 4.0.2 发布于 2025/05/30(1.5 年前);至今共发布 9 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/12/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。