Skip to content

Commit

Permalink
fix: Assign object entries to array
Browse files Browse the repository at this point in the history
Assigning the entries to an array first permits comparing the lengths and setting undefined entries as null
  • Loading branch information
thelindat committed Oct 15, 2021
1 parent 30a3910 commit 4646c6f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ const parseParameters = (query, parameters) => {
if (parameters === undefined)
throw new FormatError(`Placeholders were defined, but query received no parameters!`, query);

if (!Array.isArray(parameters)) {
let arr = [];
Object.entries(parameters).forEach((entry) => {
const [key, value] = entry;
arr[key - 1] = value;
});
parameters = arr
}
if (Array.isArray(parameters)) {
if (parameters.length === 0) return [query, [null]];
const diff = queryParams.length - parameters.length
Expand All @@ -44,14 +52,7 @@ const parseParameters = (query, parameters) => {
parameters[queryParams.length+i] = null
}
}
} else {
let arr = [];
Object.entries(parameters).forEach((entry) => {
const [key, value] = entry;
arr[key - 1] = value;
});
return [query, arr];
}
}

return [query, parameters];
};
Expand Down

0 comments on commit 4646c6f

Please sign in to comment.