Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

pathe

unjs35.5mMIT2.0.2TypeScript support: included

Universal filesystem path utils

readme

🛣️ pathe

Universal filesystem path utils

version downloads size

❓ Why

For historical reasons, windows followed MS-DOS and used backslash for separating paths rather than slash used for macOS, Linux, and other Posix operating systems. Nowadays, Windows supports both Slash and Backslash for paths. Node.js's built-in path module 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, 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 module and ensures paths are normalized with slash / and work in environments including Node.js.

💿 Usage

Install using npm or yarn:

# npm
npm i pathe

# yarn
yarn add pathe

# pnpm
pnpm i pathe

Import:

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

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

Read more about path utils from Node.js documentation 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. In order to use them, you can import from pathe/utils subpath:

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

License

Made with 💛 Published under the MIT license.

Some code was used from the Node.js project. Glob supported is powered by zeptomatch.

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

v2.0.2

compare changes

🩹 Fixes

  • format: Allow calls with partial arguments (#198)
  • Use node:path export types (#199)
  • extname: Handle inputs ending with dot (#203)

🏡 Chore

  • Enable strict typescript compilation (#200)
  • Update deps (c284a3d)

❤️ Contributors

v2.0.1

compare changes

🩹 Fixes

  • Mixed posix/win32 namespaces (#197)

❤️ Contributors

  • Pooya Parsa (@pi0)

v2.0.0

compare changes

🚀 Enhancements

  • Add posix and win32 exports to match node:path (#193)
  • ⚠️ Set delimiter to ; in windows (#176)
  • Add matchesGlob export (#195)
  • utils: Add reverseResolveAlias util (#173)

🩹 Fixes

  • basename: Ignore trailing seperator (#180)
  • utils/filename: Handle files beginning with a period or without ext (#185)
  • parse: ⚠️ Fix root handling to be consistent with node (#194)
  • join: ⚠️ Preserve normalized unc paths (#196)

📖 Documentation

  • Fix typo (#163)
  • Add jsdocs for pathe/utils (#170)

📦 Build

  • Add type: module to package.json (#190)
  • Update exports (#164)

🏡 Chore

✅ Tests

  • Add additional tests for extname (#186)

🤖 CI

⚠️ Breaking Changes

  • ⚠️ Set delimiter to ; in windows (#176)
  • parse: ⚠️ Fix root handling to be consistent with node (#194)
  • join: ⚠️ Preserve normalized unc paths (#196)

❤️ Contributors

v1.1.2

compare changes

🩹 Fixes

  • Trim root folder / when calculating relative paths (#142)
  • Check process.cwd before calling it (#147)
  • Uppercase windows drive letters (#151)
  • resolveAlias: Handle aliases ending with trailing slash (#155)
  • relative: Handle different windows drive letters (#158)

🏡 Chore

❤️ Contributors

1.1.1 (2023-06-01)

Bug Fixes

1.1.0 (2023-01-20)

Features

  • provide default export for node compatibility (resolves #115) (1ff01d1)

1.0.1 (2023-01-20)

Bug Fixes

  • process.cwd fallback on non-node env (#114) (14714c1)

1.0.0 (2022-11-14)

0.3.9 (2022-10-07)

Bug Fixes

  • respect path separators when resolving aliases (#67) (a718ebe)

0.3.8 (2022-09-19)

Bug Fixes

  • basename: handle empty extensions (#61) (b0661cb)

0.3.7 (2022-09-06)

Bug Fixes

  • resolveAlias: preserve relative paths as is (f3e5bcc)

0.3.6 (2022-09-06)

Features

0.3.5 (2022-08-18)

Bug Fixes

  • extname: avoid regex look-behinds for safari support (#42) (c0cec97)

0.3.4 (2022-08-10)

Features

  • add normalizeAliases and filename in /utils subpath (#34) (1ece780)

Bug Fixes

  • improve windows path handling and improve coverage (#36) (34a55cf)

0.3.3 (2022-08-01)

Bug Fixes

  • normalize process.cwd on windows (#31) (a7b0f7b)

0.3.2 (2022-06-29)

Bug Fixes

  • extname: handle edge cases wirth leading dot (dfe46d7), closes #21

0.3.1 (2022-06-27)

Bug Fixes

  • replace double-slashes in join calls (#17) (fd57079)
  • return . as dirname fallback for non-absolute paths (#19) (e15d5da)

0.3.0 (2022-05-05)

⚠ BREAKING CHANGES

  • import pathe from 'pathe should be changes to import * as pathe from 'pathe'
  • implement rest of path minimally (#10)

Features

  • implement rest of path minimally (#10) (6136b3c)

Bug Fixes

  • avoid mixed named and default exports (89e35ad)

0.2.0 (2021-09-27)

⚠ BREAKING CHANGES

  • improved implementation with tests (#3)

Features

  • improved implementation with tests (#3) (d8d0cb5)

0.1.0 (2021-09-24)

0.0.3 (2021-09-24)

Bug Fixes

0.0.2 (2021-09-22)

Bug Fixes

0.0.1 (2021-09-22)