MCPcopy
hub / github.com/sindresorhus/query-string / encoderForArrayFormat

Function encoderForArrayFormat

base.js:12–125  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

10const encodeFragmentIdentifier = Symbol('encodeFragmentIdentifier');
11
12function encoderForArrayFormat(options) {
13 switch (options.arrayFormat) {
14 case 'index': {
15 return key => (result, value) => {
16 const index = result.length;
17
18 if (
19 value === undefined
20 || (options.skipNull && value === null)
21 || (options.skipEmptyString && value === '')
22 ) {
23 return result;
24 }
25
26 if (value === null) {
27 result.push([encode(key, options), '[', index, ']'].join(''));
28 return result;
29 }
30
31 result.push([encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join(''));
32 return result;
33 };
34 }
35
36 case 'bracket': {
37 return key => (result, value) => {
38 if (
39 value === undefined
40 || (options.skipNull && value === null)
41 || (options.skipEmptyString && value === '')
42 ) {
43 return result;
44 }
45
46 if (value === null) {
47 result.push([encode(key, options), '[]'].join(''));
48 return result;
49 }
50
51 result.push([encode(key, options), '[]=', encode(value, options)].join(''));
52 return result;
53 };
54 }
55
56 case 'colon-list-separator': {
57 return key => (result, value) => {
58 if (
59 value === undefined
60 || (options.skipNull && value === null)
61 || (options.skipEmptyString && value === '')
62 ) {
63 return result;
64 }
65
66 if (value === null) {
67 result.push([encode(key, options), ':list='].join(''));
68 return result;
69 }

Callers 1

stringifyFunction · 0.85

Calls 1

encodeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…