UNPKG

queri

Version:

Parse, stringify and manage your URI queries.

59 lines (40 loc) 1.74 kB
# queri.js Parse, stringify and manage your URI queries. Library does not operates with [window.location](https://developer.mozilla.org/en-US/docs/Web/API/Window/location) or [pushState](https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history), if you need to - you got to do it yourself. **queri.js** supports HTTP Queries of any nesting, according it's RFC ## Usage 1. **Include Queri.js** You can include module via `require('queri');` in NodeJS Or you can link Queri.js directly to your page via `<script src="queri.js"></script>` **IMPORTANT!** `Queri` class will be available as a **global** variable 2. **Enjoy** Use Queri.js whatever you like to ```javascript let q = new Queri('foo=bar&bar[]=1&bar[]=2&bar[]=3&baz=bat'); q.get('foo'); // ->> bar q.get('bar'); // ->> [1, 2, 3] q.set('bar', null) .stringify(); // ->> 'foo=bar&baz=bat' q.query = 'a=b&c=d'; q.get('foo', false); // ->> false q.get(); // ->> {a: "b", c: "d"} q.query; // ->> {a: "b", c: "d"} q.set('c', null) .stringify(); // ->> a=b q.remove() .stringify(); // ->> "" new Queri({a: "b", c: "d"}) === new Queri('a=b&c=d'); ``` ## Doc #### `.query` _property_, object representing current query #### `constructor ( input = {} )` _method_, returns new Queri object #### `get ( key = null, defaultValue = null )` _method_, returns `.query[key]` or default value if first one not presented, or whole `.query` if key is null #### `set ( key, val )` _method_, returns self #### `remove ( key = null )` _method_, returns self #### `stringify ( )` _method_, returns stringified version of `.query`