(options)
| 35 | } |
| 36 | |
| 37 | function encoderForArrayFormat(options) { |
| 38 | const {arrayFormat} = options; |
| 39 | |
| 40 | if (['comma', 'separator', 'bracket-separator'].includes(arrayFormat)) { |
| 41 | const keyValueSeparator = arrayFormat === 'bracket-separator' ? '[]=' : '='; |
| 42 | |
| 43 | return key => (result, value) => { |
| 44 | if (isSkipped(value, options)) { |
| 45 | return result; |
| 46 | } |
| 47 | |
| 48 | // Translate null to an empty string so that it doesn't serialize as 'null' |
| 49 | const item = encodeArrayItem(value === null ? '' : value, options); |
| 50 | |
| 51 | if (result.length === 0) { |
| 52 | result.push([encode(key, options), keyValueSeparator, item].join('')); |
| 53 | return result; |
| 54 | } |
| 55 | |
| 56 | result.push(item); |
| 57 | return result; |
| 58 | }; |
| 59 | } |
| 60 | |
| 61 | // These formats write one parameter per item, with the marker in the name. |
| 62 | const marker = itemMarkerFor(arrayFormat); |
| 63 | |
| 64 | return key => (result, value) => { |
| 65 | if (isSkipped(value, options)) { |
| 66 | return result; |
| 67 | } |
| 68 | |
| 69 | const name = encode(key, options) + marker(result.length); |
| 70 | |
| 71 | if (value === null) { |
| 72 | result.push(name); |
| 73 | return result; |
| 74 | } |
| 75 | |
| 76 | result.push([name, '=', encode(value, options)].join('')); |
| 77 | return result; |
| 78 | }; |
| 79 | } |
| 80 | |
| 81 | function parserForArrayFormat(options) { |
| 82 | switch (options.arrayFormat) { |
no test coverage detected