MCPcopy Create free account
hub / github.com/parse-community/parse-dashboard / encodeFormData

Function encodeFormData

src/lib/encodeFormData.js:8–33  ·  view source on GitHub ↗
(key, value, prevKey)

Source from the content-addressed store, hash-verified

6 * the root directory of this source tree.
7 */
8export default function encodeFormData(key, value, prevKey) {
9 let field = key;
10 if (prevKey) {
11 field = prevKey + '[' + key + ']';
12 }
13 if (typeof value === 'string') {
14 return encodeURI(field) + '=' + encodeURIComponent(value);
15 }
16 if (typeof value !== 'object') {
17 return encodeURI(field) + '=' + String(value);
18 }
19 if (value && typeof value.toJSON === 'function') {
20 return encodeURI(field) + '=' + encodeURI(value.toJSON());
21 }
22 const pieces = [];
23 if (Array.isArray(value)) {
24 for (let i = 0; i < value.length; i++) {
25 pieces.push(encodeFormData('', value[i], field));
26 }
27 return pieces.join('&');
28 }
29 for (const k in value) {
30 pieces.push(encodeFormData(k, value[k], field));
31 }
32 return pieces.join('&');
33}

Callers 4

requestFunction · 0.85

Calls 1

toJSONMethod · 0.80

Tested by

no test coverage detected