Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryanburnette/qurl
A JavaScript library for getting and setting query parameters.
https://github.com/ryanburnette/qurl
Last synced: 3 months ago
JSON representation
A JavaScript library for getting and setting query parameters.
- Host: GitHub
- URL: https://github.com/ryanburnette/qurl
- Owner: ryanburnette
- License: isc
- Created: 2014-02-07T22:55:13.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-11-17T22:16:49.000Z (about 4 years ago)
- Last Synced: 2024-04-25T06:01:04.215Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 28.3 KB
- Stars: 16
- Watchers: 6
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [Qurl](https://github.com/ryanburnette/qurl)
[![repo](https://img.shields.io/badge/repository-Github-black.svg?style=flat-square)](https://github.com/ryanburnette/Qurl)
[![npm](https://img.shields.io/badge/package-NPM-green.svg?style=flat-square)](https://www.npmjs.com/package/@ryanburnette/qurl)A browser JavaScript library for getting and setting query parameters. Makes use of [Window
Location][2] and [pushState][1].## Usage
Include directly in the browser, or with a module bundler.
```js
// bundler approach
var Qurl = require('@ryanburnette/qurl');
// or include the Js and Qurl will be an attribute of window
```Create a new instance, accepts an optional queryString as a parameter to the constructor.
```js
var url = new Qurl(/* queryString */);
// or
var url = Qurl(/* queryString */);
```Get the query parameters as an object.
```js
obj = url.query();
```Get query parameters as a string
```js
url.toString();
```Get the value of a single query parameter by passing its key as an argument.
```js
key = url.query('key');
```Set the value for a query parameter.
```js
url.query('key', 'value');
url.query('Robby', {
age: 20,
friends : ['Martin', 'Mole', 'Mindy'],
stuffs : [{ foo: 'bar' }, { gum: 'ball' }],
even : { deeper : down : [1,2,3] }
});
```Delete a query parameter.
```js
url.remove('key');
url.removeAll();
```Toggle auto updating of URL history
```js
url.updateHistory = true;
```[1]: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history
[2]: https://developer.mozilla.org/en-US/docs/Web/API/Window.location