qs-like
A tiny query string parsing and stringifying library
Usage
// ES6; // modularity;;;;;// or;;;;; // CommonJSconst escape parse prefix stringify unescape = ; // modularityconst escape = ;const parse = ;const prefix = ;const stringify = ;const unescape = ;
qs-like
via classical <script>
tag
Load
API
decode()
The decode()
method is an alias for parse()
.
encode()
The encode()
method is an alias for stringify()
.
escape(str)
The escape()
method performs URL percent-encoding on the given str in a manner that is optimized for the specific requirements of URL query strings.
The escape()
method is used by stringify()
and is generally not expected to be used directly. It is exported primarily to allow application code to provide a replacement percent-encoding implementation if necessary by assigning escape()
to an alternative function.
parse(str[, sep[, eq[, options]]])
str
<string>
The URL query string to parse.sep
<string>
The substring used to delimit key and value pairs in the query string. Default:'&'
.eq
<string>
The substring used to delimit keys and values in the query string. Default: '='.options
<Object>
decodeURIComponent
<Function>
The function to use when decoding percent-encoded characters in the query string. Default:unescape()
.
For example:
// => {} // => {} // => { a: '1', b: '2', c: '3', d: '', f: '' } // => { a: '1', b: '2', c: '3', d: '', f: '' } // => { a: '1', b: '2', c: '3', d: '', f: '' } // => { a: ['1', '2', '3'], d: '', f: '' } // => { q: 'qs' }
stringify(obj[, sep[, eq[, options]]])
obj
<Object>
The object to serialize into a URL query string.sep
<string>
The substring used to delimit key and value pairs in the query string. Default:'&'
.eq
<string>
. The substring used to delimit keys and values in the query string. Default:'='
.- options
encodeURIComponent
<Function>
The function to use when converting URL-unsafe characters to percent-encoding in the query string. Default:escape()
.
The stringify()
method produces a URL query string from a given obj by iterating through the object's "own properties".
For example:
// => {} // => 'a=1&b=&c=&d=&e=' // => 'a=&c=%271%27&c=2&c=3&c=&c=&f=' // => 'a=%7B%22key%22%3A%22value%22%2C%22key2%22%3A%22value2%22%7D&d=&f=' // => 'a=%28%29%20%3D%3E%20%7B%7D'
prefix(str[, prefix])
The prefix()
method is used for prefixing exclusive characters for a URL query string. Default: '?'
.
For example:
// => '?a=1&b=2' // => '&a=1&b=2' // => '?a=1&b=2'