Skip to content

Commit 0a9621f

Browse files
committed
[minor] Merge pushOffer() and pushParam() into push()
1 parent 16f727d commit 0a9621f

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

lib/Extensions.js

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,18 @@ const tokenChars = [
2323
];
2424

2525
/**
26-
* Adds an offer to the map of extension offers.
26+
* Adds an offer to the map of extension offers or a parameter to the map of
27+
* parameters.
2728
*
28-
* @param {Object} offers The map of extension offers
29-
* @param {String} name The extension name
30-
* @param {Object} params The extension parameters
29+
* @param {Object} dest The map of extension offers or parameters
30+
* @param {String} name The extension or parameter name
31+
* @param {(Object|Boolean|String)} elem The extension parameters or the
32+
* parameter value
3133
* @private
3234
*/
33-
function pushOffer (offers, name, params) {
34-
if (Object.hasOwnProperty.call(offers, name)) offers[name].push(params);
35-
else offers[name] = [params];
36-
}
37-
38-
/**
39-
* Adds a parameter to the map of parameters.
40-
*
41-
* @param {Object} params The map of parameters
42-
* @param {String} name The parameter name
43-
* @param {Object} value The parameter value
44-
* @private
45-
*/
46-
function pushParam (params, name, value) {
47-
if (Object.hasOwnProperty.call(params, name)) params[name].push(value);
48-
else params[name] = [value];
35+
function push (dest, name, elem) {
36+
if (Object.prototype.hasOwnProperty.call(dest, name)) dest[name].push(elem);
37+
else dest[name] = [elem];
4938
}
5039

5140
/**
@@ -83,7 +72,7 @@ function parse (header) {
8372
if (end === -1) end = i;
8473
const name = header.slice(start, end);
8574
if (code === 0x2c) {
86-
pushOffer(offers, name, params);
75+
push(offers, name, params);
8776
params = {};
8877
} else {
8978
extensionName = name;
@@ -102,9 +91,9 @@ function parse (header) {
10291
if (start === -1) throw new Error(`unexpected character at index ${i}`);
10392

10493
if (end === -1) end = i;
105-
pushParam(params, header.slice(start, end), true);
94+
push(params, header.slice(start, end), true);
10695
if (code === 0x2c) {
107-
pushOffer(offers, extensionName, params);
96+
push(offers, extensionName, params);
10897
params = {};
10998
extensionName = undefined;
11099
}
@@ -155,9 +144,9 @@ function parse (header) {
155144
value = value.replace(/\\/g, '');
156145
mustUnescape = false;
157146
}
158-
pushParam(params, paramName, value);
147+
push(params, paramName, value);
159148
if (code === 0x2c) {
160-
pushOffer(offers, extensionName, params);
149+
push(offers, extensionName, params);
161150
params = {};
162151
extensionName = undefined;
163152
}
@@ -175,16 +164,16 @@ function parse (header) {
175164
if (end === -1) end = i;
176165
const token = header.slice(start, end);
177166
if (extensionName === undefined) {
178-
pushOffer(offers, token, {});
167+
push(offers, token, {});
179168
} else {
180169
if (paramName === undefined) {
181-
pushParam(params, token, true);
170+
push(params, token, true);
182171
} else if (mustUnescape) {
183-
pushParam(params, paramName, token.replace(/\\/g, ''));
172+
push(params, paramName, token.replace(/\\/g, ''));
184173
} else {
185-
pushParam(params, paramName, token);
174+
push(params, paramName, token);
186175
}
187-
pushOffer(offers, extensionName, params);
176+
push(offers, extensionName, params);
188177
}
189178

190179
return offers;

0 commit comments

Comments
 (0)