https://github.com/jonbri/starparam
URL Parameter Utility
https://github.com/jonbri/starparam
javascript parse url
Last synced: 7 days ago
JSON representation
URL Parameter Utility
- Host: GitHub
- URL: https://github.com/jonbri/starparam
- Owner: jonbri
- Created: 2016-11-23T00:48:33.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-28T13:58:42.000Z (almost 9 years ago)
- Last Synced: 2025-10-11T22:49:46.419Z (8 months ago)
- Topics: javascript, parse, url
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/starparam
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# starparam
[](https://travis-ci.org/jonbri/starparam)
URL Parameter Utility
This module provides utility functions for managing url parameters.
* add/replace url parameter
* remove url parameter
* parse/stringify object representing url
Only string operations are supported, changes to `window.history` are left to the consumer.
## Installation
`npm install --save-dev starparam`
```
import starparam from 'starparam';
```
## API
### get
Get the value of a url parameter.
```
starparam.get('http://localhost?foo=bar', 'foo') // returns 'bar'
```
### set
Generate a url string with a parameter added/updated.
```
starparam.set('http://localhost?foo=bar', 'baz', 'zoo'); // returns http://localhost?foo=bar&baz=zoo
```
### remove
Generate a url string with a parameter removed.
```
starparam.remove('http://localhost?foo=bar', 'foo'); // returns http://localhost
```
### parse
Parse the url, breaking it up into a simple representative object.
```
var oUrl = starparam.parse('http://localhost?foo=bar#one');
oUrl.prefix // 'http://localhost'
oUrl.params // array of simple param objects
oUrl.params[0].name // 'foo'
oUrl.params[0].value // 'bar'
oUrl.hash // 'one'
```
### stringify
Convert from a starparam url object into a url string (the inverse of `parse`).
```
starparam.stringify(starparam.parse('http://localhost?foo=bar')) // returns string: 'http://localhost?foo=bar'
```
## License
[BSD-2-Clause](http://spdx.org/licenses/BSD-2-Clause)