1faf70d939dfcae284e8579876b87845af654084ed1216ae0e49bf6abe1f3f86a071373cd48c06bddebbac97752ac399529527bb0b1dce975ca91232467e39 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # 🛣️ pathe
  2. > Universal filesystem path utils
  3. [![version][npm-v-src]][npm-v-href]
  4. [![downloads][npm-d-src]][npm-d-href]
  5. [![size][size-src]][size-href]
  6. > **❓ Why**
  7. >
  8. > For [historical reasons](https://docs.microsoft.com/en-us/archive/blogs/larryosterman/why-is-the-dos-path-character), windows followed MS-DOS 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. [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.**
  9. > 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** and has **no dependency on Node.js**!
  10. 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.
  11. ## 💿 Usage
  12. Install using npm or yarn:
  13. ```bash
  14. # npm
  15. npm i pathe
  16. # yarn
  17. yarn add pathe
  18. # pnpm
  19. pnpm i pathe
  20. ```
  21. Import:
  22. ```js
  23. // ESM / Typescript
  24. import { resolve } from 'pathe'
  25. // CommonJS
  26. const { resolve } = require('pathe')
  27. ```
  28. 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!
  29. ### Extra utilties
  30. Pathe exports some extra utilities that do not exist in standard Node.js [path module](https://nodejs.org/api/path.html).
  31. In order to use them, you can import from `pathe/utils` subpath:
  32. ```js
  33. import { filename, normalizeAliases, resolveAlias } from 'pathe/utils'
  34. ```
  35. ## License
  36. MIT. Made with 💖
  37. Some code used from Node.js project. See [LICENSE](./LICENSE).
  38. <!-- Refs -->
  39. [npm-v-src]: https://img.shields.io/npm/v/pathe?style=flat-square
  40. [npm-v-href]: https://npmjs.com/package/pathe
  41. [npm-d-src]: https://img.shields.io/npm/dm/pathe?style=flat-square
  42. [npm-d-href]: https://npmjs.com/package/pathe
  43. [github-actions-src]: https://img.shields.io/github/workflow/status/unjs/pathe/ci/main?style=flat-square
  44. [github-actions-href]: https://github.com/unjs/pathe/actions?query=workflow%3Aci
  45. [size-src]: https://packagephobia.now.sh/badge?p=pathe
  46. [size-href]: https://packagephobia.now.sh/result?p=pathe