GithubHelp home page GithubHelp logo

.format support about chalk HOT 4 CLOSED

chalk avatar chalk commented on May 22, 2024
.format support

from chalk.

Comments (4)

L1fescape avatar L1fescape commented on May 22, 2024

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]));

from chalk.

sindresorhus avatar sindresorhus commented on May 22, 2024

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 ;)

from chalk.

bevacqua avatar bevacqua commented on May 22, 2024

The point was using util.format and proving some sugar in the chalk api
On Dec 16, 2013 4:37 PM, "Andrew Kennedy" [email protected] 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
.

from chalk.

sindresorhus avatar sindresorhus commented on May 22, 2024

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.

from chalk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.