ljharb/qs
View on GitHuboption to parse/unparse from array of pairs handling ordering and duplicate keys or key values like URLSearchParams
Open
#267 opened on Jun 26, 2018
feature requesthelp wantedparsestringify
Description
I want to be able to write a function that works on any browser/node like:
const nodeUrl = require('url');
const assert = require('assert');
function setQuery(url, key, value) {
const u = new nodeUrl.URL(url);
u.searchParams.set(key, value);
return u.toString();
}
const result = setQuery('https://example.com?ham=spam&eggs=chips&eggs=chips&ham=spam', 'eggs', 'zap');
assert.equal(result, 'ham=spam&eggs=zap&ham=spam');
is this something qs can help with?