MCPcopy
hub / github.com/didi/mpx / serialize

Function serialize

packages/utils/src/url.js:15–44  ·  view source on GitHub ↗
(params)

Source from the content-addressed store, hash-verified

13}
14
15function serialize (params) {
16 if (isURLSearchParams(params)) {
17 return params.toString()
18 }
19 const parts = []
20 forEach(params, (val, key) => {
21 if (typeof val === 'undefined' || val === null) {
22 return
23 }
24
25 if (isArray(val)) {
26 key = key + '[]'
27 }
28
29 if (!isArray(val)) {
30 val = [val]
31 }
32
33 forEach(val, function parseValue (v) {
34 if (type(v) === 'Date') {
35 v = v.toISOString()
36 } else if (type(v) === 'Object') {
37 v = JSON.stringify(v)
38 }
39 parts.push(encode(key) + '=' + encode(v))
40 })
41 })
42
43 return parts.join('&')
44}
45
46function buildUrl (url, params = {}, serializer) {
47 if (!serializer) {

Callers 1

requestFunction · 0.90

Calls 6

forEachFunction · 0.90
isArrayFunction · 0.90
typeFunction · 0.90
isURLSearchParamsFunction · 0.85
encodeFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected