Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.format support #8

Closed
bevacqua opened this issue Dec 16, 2013 · 4 comments
Closed

.format support #8

bevacqua opened this issue Dec 16, 2013 · 4 comments

Comments

@bevacqua
Copy link

It would be nice to have format as part of the API

console.log(chalk.underline.red.format("Detected %s Error(s)", errors.length));
@L1fescape
Copy link
Contributor

Not sure if @sindresorhus wants to include this functionality or not, but for the time being you can use the sprintf package to achieve this.

npm install chalk sprintf
var vsprintf = require('sprintf').vsprintf,
    chalk = require('chalk');

var errors = ["File not found."];

console.log(vsprintf(chalk.underline.red("Detected %s Error(s)"), [errors.length]));

@sindresorhus
Copy link
Member

No need. console.log already supports simple string substitution.

This should work:

console.log(chalk.underline.red('Detected %d Error(s)'), 1);

I've added an example to the readme ;)

@bevacqua
Copy link
Author

The point was using util.format and proving some sugar in the chalk api
On Dec 16, 2013 4:37 PM, "Andrew Kennedy" notifications@github.com wrote:

Not sure if @sindresorhus https://github.com/sindresorhus wants to
include this functionality or not, but for the time being you can use the
sprintf package in conjunction with chalk.

npm install chalk sprintf

var vsprintf = require('sprintf').vsprintf,
chalk = require('chalk');

var errors = ["File not found."];

console.log(vsprintf(chalk.underline.red("Detected %s Error(s)"), [errors.length]));


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-30692477
.

@sindresorhus
Copy link
Member

I prefer to keep Chalk focused and your example is actually more verbose than the above. Do feel free to create a tool for this using Chalk though, if this doesn't work for you. That's really what it's for; the most low-level way to colorize.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants