MCPcopy Index your code
hub / github.com/sindresorhus/query-string / parserForArrayFormat

Function parserForArrayFormat

base.js:127–252  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

125}
126
127function parserForArrayFormat(options) {
128 let result;
129
130 switch (options.arrayFormat) {
131 case 'index': {
132 return (key, value, accumulator) => {
133 result = /\[(\d*)]$/.exec(key);
134
135 key = key.replace(/\[\d*]$/, '');
136
137 if (!result) {
138 accumulator[key] = value;
139 return;
140 }
141
142 if (accumulator[key] === undefined) {
143 accumulator[key] = {};
144 }
145
146 accumulator[key][result[1]] = value;
147 };
148 }
149
150 case 'bracket': {
151 return (key, value, accumulator) => {
152 result = /(\[])$/.exec(key);
153 key = key.replace(/\[]$/, '');
154
155 if (!result) {
156 accumulator[key] = value;
157 return;
158 }
159
160 if (accumulator[key] === undefined) {
161 accumulator[key] = [value];
162 return;
163 }
164
165 if (!Array.isArray(accumulator[key])) {
166 accumulator[key] = [accumulator[key], value];
167 return;
168 }
169
170 accumulator[key].push(value);
171 };
172 }
173
174 case 'colon-list-separator': {
175 return (key, value, accumulator) => {
176 result = /(:list)$/.exec(key);
177 key = key.replace(/:list$/, '');
178
179 if (!result) {
180 accumulator[key] = value;
181 return;
182 }
183
184 if (accumulator[key] === undefined) {

Callers 1

parseFunction · 0.85

Calls 1

decodeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…