Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Jul 27, 2019
1 parent 22af9fa commit cc2cd57
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/utils/index.js
Expand Up @@ -27,21 +27,17 @@ exports.isPlainObject = function isPlainObject(obj) {
};

exports.normalizeQuery = function normalizeQuery(query) {
// foreach key, get the last element if it's an array
return Object.keys(query).reduce((q, param) => {
q[param] = [].concat(query[param]).pop();

return q;
}, {});
// foreach key, ensure that the value is an array
return fromEntries(
entries(query).map(([key, value]) => [key, [].concat(value).pop()]),
);
};

exports.normalizeMultiValueQuery = function normalizeMultiValueQuery(query) {
// foreach key, ensure that the value is an array
return Object.keys(query).reduce((q, param) => {
q[param] = [].concat(query[param]);

return q;
}, {});
return fromEntries(
entries(query).map(([key, value]) => [key, [].concat(value)]),
);
};

exports.capitalizeKeys = function capitalizeKeys(o) {
Expand Down

0 comments on commit cc2cd57

Please sign in to comment.