753f54e027f5db02c7b3fe7c6d6d36ee4ee973944ebe14e4ecc9d36b3ce1de42f6d600c05d7956c432dd85aefa90a94a728333db89f72b5ec4617667f75e84 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # pathe
  2. > Normalized paths for Node.js
  3. [![version][npm-v-src]][npm-v-href]
  4. [![downloads][npm-d-src]][npm-d-href]
  5. [![size][size-src]][size-href]
  6. 🧪 This package is still experimental and might not handle all cases. Please track issues.
  7. ## ❓ Why
  8. For [historical reasons](https://docs.microsoft.com/en-us/archive/blogs/larryosterman/why-is-the-dos-path-character), windows followed MS-DOS
  9. and using 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.
  10. [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.**
  11. This package is a drop-in replacement of the Node.js's `path` module and ensures paths are normalized with slash `/`.
  12. Compared to popular [upath](https://github.com/anodynos/upath), pathe is providing **identical exports** of Node.js with normalization on **all operations** and written in modern **ESM/Typescript**.
  13. ## 💿 Install
  14. Install using npm or yarn:
  15. ```bash
  16. npm i pathe
  17. # or
  18. yarn add pathe
  19. ```
  20. Import:
  21. ```js
  22. // ESM / Typescript
  23. import { resolve } from 'pathe'
  24. // CommonJS
  25. const { resolve } = require('pathe')
  26. ```
  27. Read more about path utils from [Node.js documentation](https://nodejs.org/api/path.html) and rest assured behavior is ALWAYS like POSIX regardless of your input paths format and running platform!
  28. ## License
  29. MIT. Made with 💖
  30. Some code used form Node.js project. See [LICENSE](./LICENSE).
  31. <!-- Refs -->
  32. [npm-v-src]: https://img.shields.io/npm/v/pathe?style=flat-square
  33. [npm-v-href]: https://npmjs.com/package/pathe
  34. [npm-d-src]: https://img.shields.io/npm/dm/pathe?style=flat-square
  35. [npm-d-href]: https://npmjs.com/package/pathe
  36. [github-actions-src]: https://img.shields.io/github/workflow/status/unjs/pathe/ci/main?style=flat-square
  37. [github-actions-href]: https://github.com/unjs/pathe/actions?query=workflow%3Aci
  38. [size-src]: https://packagephobia.now.sh/badge?p=pathe
  39. [size-href]: https://packagephobia.now.sh/result?p=pathe