ljharb/qs
Vedi su GitHuboption to parse/unparse from array of pairs handling ordering and duplicate keys or key values like URLSearchParams
Open
#267 aperta il 26 giu 2018
feature requesthelp wantedparsestringify
Metriche repository
- Star
- (8015 star)
- Metriche merge PR
- (Merge medio 6g 22h) (2 PR mergiate in 30 g)
Descrizione
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?