How to use the URLSearchParams function from url

Find comprehensive JavaScript url.URLSearchParams code examples handpicked from public code repositorys.

74
75
76
77
78
79
80
81
82
83
) {
  if (callback == null) {
    callback = function () {}
  }
  const u = new URL(`${Settings.apis.clsi.url}/project/${projectId}/status`)
  u.search = new URLSearchParams({
    compileGroup,
    compileBackendClass,
  }).toString()
  request.post(u.href, (err, res, body) => {
fork icon0
star icon0
watch icon202

87
88
89
90
91
92
93
94
95
96
const postData = this.postData();
if (!postData) return null;
const contentType = this.headers()['content-type'];
if (contentType === 'application/x-www-form-urlencoded') {
  const entries = {};
  const parsed = new _url.URLSearchParams(postData);
  for (const [k, v] of parsed.entries()) entries[k] = v;
  return entries;
}
try {
fork icon0
star icon0
watch icon1

1
2
3
4
5
6
7
8
9
10
11
12
const url = require("url");


const swapiApi = async (entity, queryParams = {}) => {
  try {
    if (!entity) throw new Error("Entity not found in params");
    const params = new url.URLSearchParams(queryParams);


    const config = {
      method: "get",
      maxBodyLength: Infinity,
fork icon0
star icon0
watch icon0

186
187
188
189
190
191
192
193
194

let combined = components.join(' ');

// Create the HREF
let search_url = new URL('https://devpost.com/software/search');
let search_params = new URLSearchParams();

search_params.set('query', combined);
search_params.set('per_page', '4');
fork icon0
star icon0
watch icon0

48
49
50
51
52
53
54
55
56
57
  Object.entries(values.multiValueQueryStringParameters).forEach(([qKey, qValues]) => {
    qValues.forEach((qValue) => {
      multiValueQueryStringParametersToArray.push([qKey, qValue])
    })
  })
  const rawQueryString = new URLSearchParams(multiValueQueryStringParametersToArray)
  mergedEvent.req.url += '?' + rawQueryString.toString()
}

if (values.body && Buffer.from(values.body, 'base64').toString('base64') === values.body) {
fork icon0
star icon0
watch icon0

238
239
240
241
242
243
244
245
246
247

Example:

```js
const { URLSearchParams } = require('url');
const urlSearchParams = new URLSearchParams('foo=bar&baz=new');

const buf = Buffer.alloc(1);
urlSearchParams.has.call(buf, 'foo');
// Throws a TypeError with code 'ERR_INVALID_THIS'
fork icon0
star icon0
watch icon3

+ 15 other calls in file