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

Function paramGenerator

benchmark/url/url-searchparams-creation.js:32–58  ·  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 acc[key] = Object.keys(values[key]).reduce((acc, k, i) => {
39 acc += `${k}=${values[key][k]}${i < valueKeys.length - 1 ? '&' : ''}`;
40 return acc;
41 }, '');
42 return acc;
43 }, {});
44 case 'iterable':
45 // Return the values object with all values as iterable
46 return valueKeys.reduce((acc, key) => {
47 acc[key] = Object.keys(values[key]).reduce((acc, k) => {
48 acc.push([k, values[key][k]]);
49 return acc;
50 }, []);
51 return acc;
52 }, {});
53 case 'object':
54 // Return the values object with all values as objects
55 return values;
56 default:
57 }
58}
59
60const bench = common.createBenchmark(main, {
61 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…