Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zacanger/path-normalize
Zero-dependency browser-oriented path.normalize
https://github.com/zacanger/path-normalize
normalize path path-normalize
Last synced: 16 days ago
JSON representation
Zero-dependency browser-oriented path.normalize
- Host: GitHub
- URL: https://github.com/zacanger/path-normalize
- Owner: zacanger
- License: mit
- Created: 2018-02-25T07:32:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-19T17:19:40.000Z (5 months ago)
- Last Synced: 2024-10-16T18:50:44.747Z (about 1 month ago)
- Topics: normalize, path, path-normalize
- Language: JavaScript
- Homepage: http://npm.im/path-normalize
- Size: 1.68 MB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# path-normalize
Zero-dependency browser-oriented `path.normalize`.
[Donate](https://ko-fi.com/zacanger)
[![npm version](https://img.shields.io/npm/v/path-normalize.svg)](https://npm.im/path-normalize) [![CircleCI](https://circleci.com/gh/zacanger/path-normalize/tree/master.svg?style=svg)](https://circleci.com/gh/zacanger/path-normalize/tree/master) [![codecov](https://codecov.io/gh/zacanger/path-normalize/branch/master/graph/badge.svg)](https://codecov.io/gh/zacanger/path-normalize)
`path-normalize` is different from
[normalize-path](http://npm.im/normalize-path); `normalize-path` only handles
slashes, while this lib is a browser-focused version of the POSIX
`path.normalize` in Node.`path-normalize` also differs from Node's `path.normalize`. `path-normalize`
handles uri-encoded strings.Most of this library is directly from
[Node's source](https://github.com/nodejs/node/blob/b404aa56c0e776c9722017ca020f9d04c7aa6de2/lib/path.js#L1182).
--------## Installation
`npm i path-normalize`
## Usage
```javascript
const normalize = require('path-normalize')
const normal = (somePath) => normalize(somePath)
```Slightly more real-world example:
```javascript
import normalize from 'path-normalize'// imaginary client-side router api
router.route('/foo/*', (pathname) => {
const normalized = normalize(pathname)
if (normalized !== pathname) {
router.redirect(normalized)
} else {
renderFoo()
}
})
```[LICENSE](./LICENSE.md)