ljharb/qs

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

Open

#267 创建于 2018年6月26日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)JavaScript (8,015 star) (744 fork)batch import
feature requesthelp wantedparsestringify

描述

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?

贡献者指南