Microscopically small querystring parser/stringifier
.
uqs is a microscopically small universal querystring parser/stringifier.
npm install --save uqs
var QS = require('uqs')
import QS from 'uqs'
var params = QS.parse(location.search)
// or the other way around
var qs = QS.stringify({my:'querystring', arguments:2})
Modern browsers make parsing URLs simple:
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:
console.info(link.search) // > '?they=did&forget=something' <== YUCK!
Darn it, now we still need to parse by hand!
uqs is a microscopically small (< 1 kB minified and gzipped) querystring parser and minifier that fills this exact gap the browser makers left us:
var QS = require('uqs')
var params = QS.parse(link.search)
console.info(params) // > Object {they: "did", forget: "something"}
Add an issue in this project's issue tracker to let me know of any problems you find, or questions you may have.
Copyright 2016 by Stijn de Witt. Some rights reserved.
Licensed under the Creative Commons Attribution 4.0 International (CC-BY-4.0) Open Source license.