MCPcopy Index your code
hub / github.com/nodejs/node / paramGenerator

Function paramGenerator

benchmark/url/url-searchparams-toString.js:32–59  ·  view source on GitHub ↗
(paramType)

Source from the content-addressed store, hash-verified

30};
31
32function paramGenerator(paramType) {
33 const valueKeys = Object.keys(values);
34 switch (paramType) {
35 case 'string':
36 // Return the values object with all values as strings
37 return valueKeys.reduce((acc, key) => {
38 const objectKeys = Object.keys(values[key]);
39 acc[key] = objectKeys.reduce((acc, k, i) => {
40 acc += `${k}=${values[key][k]}${i < objectKeys.length - 1 ? '&' : ''}`;
41 return acc;
42 }, '');
43 return acc;
44 }, {});
45 case 'iterable':
46 // Return the values object with all values as iterable
47 return valueKeys.reduce((acc, key) => {
48 acc[key] = Object.keys(values[key]).reduce((acc, k) => {
49 acc.push([k, values[key][k]]);
50 return acc;
51 }, []);
52 return acc;
53 }, {});
54 case 'object':
55 // Return the values object with all values as objects
56 return values;
57 default:
58 }
59}
60
61const bench = common.createBenchmark(main, {
62 type: ['noencode', 'encodemany', 'encodelast', 'array', 'multiprimitives'],

Callers 1

mainFunction · 0.70

Calls 3

reduceMethod · 0.80
keysMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…