template literals with a style tag, fixes #341
This commit is contained in:
parent
797461ee32
commit
7d238e2ebb
2 changed files with 13 additions and 0 deletions
|
|
@ -134,6 +134,11 @@ const createStyler = (open, close, parent) => {
|
|||
|
||||
const createBuilder = (self, _styler, _isEmpty) => {
|
||||
const builder = (...arguments_) => {
|
||||
if (Array.isArray(arguments_[0])) {
|
||||
// Called as a template litteral, e.g. chalk.red`2 + 3 = {bold ${2+3}}`
|
||||
return applyStyle(builder, chalkTag(builder, ...arguments_));
|
||||
}
|
||||
|
||||
// Single argument is hot path, implicit coercion is faster than anything
|
||||
// eslint-disable-next-line no-implicit-coercion
|
||||
return applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue