Microscopically small query string parser/stringifier
npm install uqssh
npm install --save uqs
`
require
`js
var QS = require('uqs')
`
import
`js
import QS from 'uqs'
`
use
`js
var params = QS.parse(location.search)
// or the other way around
var qs = QS.stringify({my:'querystring', arguments:2})
`
why
Modern browsers make parsing URLs simple:
`js
var link = document.createElement('a')
link.href = 'https://example.com/some/path?they=did&forget=something'
console.info(link.protocol) // > 'https:'
console.info(link.hostname) // > 'example.com'
console.info(link.pathname) // > '/some/path'
`
You get the picture. So all is well...
or not? There is this one thing they seemed to have forgotten:
`js
console.info(link.search) // > '?they=did&forget=something' <== YUCK!
`
Darn it, now we still need to parse by hand!
$3
uqs is a microscopically small (< 1 kB minified and gzipped) querystring parser
and minifier that fills this exact gap the browser makers left us:
`js
var QS = require('uqs')
var params = QS.parse(link.search)
console.info(params) // > Object {they: "did", forget: "something"}
``