MCPcopy
hub / github.com/Kong/insomnia / parserForArrayFormat

Function parserForArrayFormat

packages/insomnia/bin/yarn-standalone.js:119724–119772  ·  view source on GitHub ↗
(opts)

Source from the content-addressed store, hash-verified

119722 encode(value, opts)
119723 ].join('');
119724 };
119725
119726 case 'bracket':
119727 return function (key, value) {
119728 return value === null ? encode(key, opts) : [
119729 encode(key, opts),
119730 '[]=',
119731 encode(value, opts)
119732 ].join('');
119733 };
119734
119735 default:
119736 return function (key, value) {
119737 return value === null ? encode(key, opts) : [
119738 encode(key, opts),
119739 '=',
119740 encode(value, opts)
119741 ].join('');
119742 };
119743 }
119744}
119745
119746function parserForArrayFormat(opts) {
119747 var result;
119748
119749 switch (opts.arrayFormat) {
119750 case 'index':
119751 return function (key, value, accumulator) {
119752 result = /\[(\d*)\]$/.exec(key);
119753
119754 key = key.replace(/\[\d*\]$/, '');
119755
119756 if (!result) {
119757 accumulator[key] = value;
119758 return;
119759 }
119760
119761 if (accumulator[key] === undefined) {
119762 accumulator[key] = {};
119763 }
119764
119765 accumulator[key][result[1]] = value;
119766 };
119767
119768 case 'bracket':
119769 return function (key, value, accumulator) {
119770 result = /(\[\])$/.exec(key);
119771 key = key.replace(/\[\]$/, '');
119772
119773 if (!result) {
119774 accumulator[key] = value;
119775 return;

Callers 1

parseFunction · 0.85

Calls 1

concatMethod · 0.80

Tested by

no test coverage detected