https://github.com/rvanbaalen/hashparser
Tiny javascript library to get and set (encoded) hash parameters
https://github.com/rvanbaalen/hashparser
hash javascript parser url util
Last synced: 3 months ago
JSON representation
Tiny javascript library to get and set (encoded) hash parameters
- Host: GitHub
- URL: https://github.com/rvanbaalen/hashparser
- Owner: rvanbaalen
- License: mit
- Created: 2019-06-05T17:01:30.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2026-03-29T02:43:29.000Z (3 months ago)
- Last Synced: 2026-03-29T05:26:29.944Z (3 months ago)
- Topics: hash, javascript, parser, url, util
- Language: JavaScript
- Homepage: https://robinvanbaalen.nl/hashparser/
- Size: 1.34 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[← See my other Open Source projects](https://robinvanbaalen.nl)
# @rvanbaalen/hashparser




## Description
Tiny javascript library to get and set (encoded) query parameters in the URL hash.
## Installation
```bash
npm install @rvanbaalen/hashparser
```
## Usage
### Basic usage
```js
import { HashParser } from '@rvanbaalen/hashparser';
const hp = new HashParser();
// Set a paramter in the hash
hp.set('foo', 'bar'); // example.com#foo=bar
// Get a parameter from the hash
hp.get('foo'); // bar
// Remove a parameter from the hash
hp.remove('foo'); // example.com#
```
### Encoded values
```js
import {HashParser} from '@rvanbaalen/hashparser';
// Two ways to use encoded parameters
// 1. Via the static getter
// Set a paramter in the hash
HashParser.encoded.set('foo', 'bar'); // example.com#foo=ImJhciI%3D
// Get a parameter from the hash
HashParser.encoded.get('foo'); // "bar"
// For reference, a default HashParser instance does not decode values
const hp = new HashParser();
hp.get('foo'); // ImJhciI%3D
// 2. Via the instance
const hp = new HashParser({encoded: true});
hp.set('foo', 'bar'); // example.com#foo=ImJhciI%3D
hp.get('foo'); // "bar"
```
### Options
The following options can be passed to a new HashParser instance:
```js
{
encoded: false, // default value is false, set to true to always encode values
sync: true // default value is true, this will listen for hashchange events on the window object and update the internal dataset.
}
```
## Building
Compile the source files to the `dist` folder:
```bash
npm run build
```
Upon each commit, `npm run build` is automatically
executed and `./dist/hashparser.min.js` is automatically added pre-commit.
## Contributing
Contributions are welcome! Please feel free to [open an issue](https://github.com/rvanbaalen/hashparser/issues) or [submit a pull request](https://github.com/rvanbaalen/hashparser/pulls).
## License
This project is licensed under the MIT License - see the [LICENSE](https://github.com/rvanbaalen/hashparser/blob/main/LICENSE) file for details.