Skip to content

Commit

Permalink
revert changes to template/utils.js file
Browse files Browse the repository at this point in the history
  • Loading branch information
technophile-04 committed Mar 28, 2024
1 parent 2ef2179 commit 9dfd650
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions templates/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@ export const withDefaults =
(template, expectedArgsDefaults, debug = false) =>
(receivedArgs) => {
const argsWithDefault = Object.fromEntries(
Object.entries(expectedArgsDefaults).map(([argName, argDefault]) => [
argName,
receivedArgs[argName] ?? [argDefault],
])
Object.entries(expectedArgsDefaults)
.map(([argName, argDefault]) => [argName, receivedArgs[argName] ?? [argDefault]])
);

if (debug) {
console.log(argsWithDefault, expectedArgsDefaults, receivedArgs);
}

const expectedArgsNames = Object.keys(expectedArgsDefaults);

const expectedArgsNames = Object.keys(expectedArgsDefaults)
Object.keys(receivedArgs).forEach((receivedArgName) => {
if (!expectedArgsNames.includes(receivedArgName)) {
throw new Error(
`Template received unexpected argument \`${receivedArgName}\`. Expecting only ${expectedArgsNames
.map((name) => `\`${name}\``)
.join(", ")}`
`Templated received unexpected argument \`${receivedArgName}\`. Expecting only ${
expectedArgsNames.map(name => `\`${name}\``).join(", ")
}`
);
}
});

return template(argsWithDefault);
};
};

0 comments on commit 9dfd650

Please sign in to comment.