MCPcopy Create free account
hub / github.com/didi/mpx / stringifyQuery

Function stringifyQuery

packages/webpack-plugin/lib/utils/stringify-query.js:9–40  ·  view source on GitHub ↗
(obj, useJSON)

Source from the content-addressed store, hash-verified

7const JSON5 = require('json5')
8
9function stringifyQuery (obj, useJSON) {
10 if (useJSON) return `?${JSON5.stringify(obj)}`
11
12 const res = obj
13 ? Object.keys(obj).sort().map(key => {
14 const val = obj[key]
15
16 if (val === undefined) {
17 return val
18 }
19
20 if (val === true) {
21 return key
22 }
23
24 if (Array.isArray(val)) {
25 const key2 = `${key}[]`
26 const result = []
27 val.slice().forEach(val2 => {
28 if (val2 === undefined) {
29 return
30 }
31 result.push(`${key2}=${encodeURIComponent(val2)}`)
32 })
33 return result.join('&')
34 }
35
36 return `${key}=${encodeURIComponent(val)}`
37 }).filter(x => x).join('&')
38 : null
39 return res ? `?${res}` : ''
40}
41
42module.exports = stringifyQuery

Callers 3

add-query.jsFile · 0.85
applyMethod · 0.85
applyMethod · 0.85

Calls 3

keysMethod · 0.80
forEachMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected