https://github.com/shinnn/slash-deduplication
Deduplicate multiple consecutive slashes in a current URL without reloading a page — useful for GitHub Pages
https://github.com/shinnn/slash-deduplication
cleanup client-side deduplication javascript normalization npm-package path redirection url
Last synced: 27 days ago
JSON representation
Deduplicate multiple consecutive slashes in a current URL without reloading a page — useful for GitHub Pages
- Host: GitHub
- URL: https://github.com/shinnn/slash-deduplication
- Owner: shinnn
- License: isc
- Created: 2018-04-13T08:15:56.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-01-12T10:03:37.000Z (over 7 years ago)
- Last Synced: 2025-03-18T13:56:00.379Z (about 1 year ago)
- Topics: cleanup, client-side, deduplication, javascript, normalization, npm-package, path, redirection, url
- Language: JavaScript
- Homepage:
- Size: 41 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slash-deduplication
[](https://www.npmjs.com/package/slash-deduplication)
[](https://travis-ci.org/shinnn/slash-deduplication)
[](https://ci.appveyor.com/project/ShinnosukeWatanabe/slash-deduplication/branch/master)

Deduplicate multiple consecutive slashes in a current URL without reloading a page
## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).
```
npm install slash-deduplication
```
## Usage
Once the HTML page loads [the script](./index.js) and if the current `location.pathname` includes multiple consecutive `/`, it [replaces](https://developer.mozilla.org/en-US/docs/Web/API/History_API#Adding_and_modifying_history_entries) the current URL with a duplicate-`/`-free one.
```javascript
(async () => {
location.href; //=> 'https://example.org/a//b/c//d////'
await import('slash-deduplication');
location.href; //=> 'https://example.org/a/b/c/d/'
})();
```
It only modifies the path of URL. Original fragment identifier and parameters are preserved.
```javascript
(async () => {
location.href; //=> 'https://example.org////////page#a//b&c=d//e'
await import('slash-deduplication');
location.href; //=> 'https://example.org/page#a//b&c=d//e'
})();
```
This library is suitable for static site hosting service where server-side redirection is not user-unconfigurable, for example [GitHub Pages](https://pages.github.com/).
## License
[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe