Let's say I have
const highlight = (strings, ...values) => {
// console.logs in highlight
}
Let's say I want to create a "middleware" that modifies the template and then call highlight instead:
const doMore = (string, ...values) => {
// modify string/values and then call highlight here
}
So that I can now do something like
doMore`
the string ${template}
`;
I cannot figure out how to call highlight from doMore. How do I do this?
My first attempt was to use the ... operator. But this did not work. Specifically, I'm trying to create a wrapper for the npm chalk application, so I did something like:
const doMore = (string, ...values) => {
// extend string, values
return chalk(string, ...values)
}
but this throws an error: chalk_1.default.apply is not a function. Normally doing
chalk`the string ${template}`
but calling it using the spread operator is throwing this error.
You can use the
...spread syntax to convert an array into a list of arguments to callhighlight: