ljharb/qs

option to parse/unparse from array of pairs handling ordering and duplicate keys or key values like URLSearchParams

Open

#267 aperta il 26 giu 2018

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)JavaScript (744 fork)batch import
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?

Guida contributor