Skip to content

A JavaScript library for getting and setting query parameters.

License

Notifications You must be signed in to change notification settings

ryanburnette/qurl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

repo npm

A browser JavaScript library for getting and setting query parameters. Makes use of Window Location and pushState.

Usage

Include directly in the browser, or with a module bundler.

// 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.

var url = new Qurl(/* queryString */);
// or
var url = Qurl(/* queryString */);

Get the query parameters as an object.

obj = url.query();

Get query parameters as a string

url.toString();

Get the value of a single query parameter by passing its key as an argument.

key = url.query('key');

Set the value for a query parameter.

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.

url.remove('key');
url.removeAll();

Toggle auto updating of URL history

url.updateHistory = true;

About

A JavaScript library for getting and setting query parameters.

Resources

License

Stars

Watchers

Forks

Packages

No packages published