# pathe

> Universal filesystem path utils

Latest version **2.0.3** (published 2025-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install pathe
pnpm add pathe
yarn add pathe
bun add pathe
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2025-02-11 |
| First published | 2021-09-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 50.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 589 |
| Maintainers | pi0, danielroe |

## Links

- npm: https://www.npmjs.com/package/pathe
- Repository: https://github.com/unjs/pathe
- Homepage: https://github.com/unjs/pathe#readme
- Issues: https://github.com/unjs/pathe/issues
- npm.io page: https://npm.io/package/pathe

## Recent versions

- 2.0.3 (latest) — 2025-02-11
- 2.0.2 — 2025-01-17
- 2.0.1 — 2025-01-09
- 2.0.0 — 2025-01-03
- 1.1.2 — 2024-01-10
- 1.1.1 — 2023-06-01
- 1.1.0 — 2023-01-20
- 1.0.1 — 2023-01-20
- 1.0.0 — 2022-11-14
- 0.3.9 — 2022-10-07
- 0.3.8 — 2022-09-19
- 0.3.7 — 2022-09-06
- 0.3.6 — 2022-09-06
- 0.3.5 — 2022-08-18
- 0.3.4 — 2022-08-10
- … 10 more at https://npm.io/package/pathe/versions

## README

# 🛣️ pathe

> Universal filesystem path utils

[![version][npm-v-src]][npm-v-href]
[![downloads][npm-d-src]][npm-d-href]
[![size][size-src]][size-href]

## ❓ Why

For [historical reasons](https://docs.microsoft.com/en-us/archive/blogs/larryosterman/why-is-the-dos-path-character), windows followed MS-DOS and used backslash for separating paths rather than slash used for macOS, Linux, and other Posix operating systems. Nowadays, [Windows](https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN) supports both Slash and Backslash for paths. [Node.js's built-in `path` module](https://nodejs.org/api/path.html) in the default operation of the 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 path module will assume that Windows-style paths are being used. **This makes inconsistent code behavior between Windows and POSIX.**

Compared to popular [upath](https://github.com/anodynos/upath), pathe provides **identical exports** of Node.js with normalization on **all operations** and is written in modern **ESM/TypeScript** and has **no dependency on Node.js**!

This package is a drop-in replacement of the Node.js's [path module](https://nodejs.org/api/path.html) module and ensures paths are normalized with slash `/` and work in environments including Node.js.

## 💿 Usage

Install using npm or yarn:

```bash
# npm
npm i pathe

# yarn
yarn add pathe

# pnpm
pnpm i pathe
```

Import:

```js
// ESM / Typescript
import { resolve, matchesGlob } from "pathe";

// CommonJS
const { resolve, matchesGlob } = require("pathe");
```

Read more about path utils from [Node.js documentation](https://nodejs.org/api/path.html) and rest assured behavior is consistently like POSIX regardless of your input paths format and running platform (the only exception is `delimiter` constant export, it will be set to `;` on windows platform).

### Extra utilities

Pathe exports some extra utilities that do not exist in standard Node.js [path module](https://nodejs.org/api/path.html).
In order to use them, you can import from `pathe/utils` subpath:

```js
import {
  filename,
  normalizeAliases,
  resolveAlias,
  reverseResolveAlias,
} from "pathe/utils";
```

## License

Made with 💛 Published under the [MIT](./LICENSE) license.

Some code was used from the Node.js project. Glob supported is powered by [zeptomatch](https://github.com/fabiospampinato/zeptomatch).

<!-- Refs -->

[npm-v-src]: https://img.shields.io/npm/v/pathe?style=flat-square
[npm-v-href]: https://npmjs.com/package/pathe
[npm-d-src]: https://img.shields.io/npm/dm/pathe?style=flat-square
[npm-d-href]: https://npmjs.com/package/pathe
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/pathe/ci/main?style=flat-square
[github-actions-href]: https://github.com/unjs/pathe/actions?query=workflow%3Aci
[size-src]: https://packagephobia.now.sh/badge?p=pathe
[size-href]: https://packagephobia.now.sh/result?p=pathe

---
_Source: https://npm.io/package/pathe · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
