Comments (4)
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.
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.
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.
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)
- Add more colors HOT 2
- Chalk is not working in Jenkins multibranch pipeline HOT 1
- Does chalk.js support squiggly lines? HOT 1
- Cannot find module 'chalk'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? HOT 2
- Can't show color in vscode integrated terminal HOT 1
- chalk not suppported?? HOT 1
- Tried to use with TS (NestJS Project) HOT 6
- is there r any way to mix background colors like gradient-string? HOT 1
- Error [ERR_REQUIRE_ESM]: require() of ES Module HOT 6
- chalk 5.x fails with typescript HOT 3
- Is it possible to apply a style conditionally? HOT 5
- ReferenceError: navigator is not defined HOT 1
- Remove README.md from bundle HOT 2
- v4 property override error
- is support require('chalk')? HOT 3
- Chalk italic modifier is not applied in Windows Git Bash terminal. HOT 1
- $FORCE_COLOR works only as either level 0 or 3 HOT 1
- New Windows fluent emoji font - color is wrong HOT 1
- Unable to resolve module #ansi-styles HOT 2
- 【suggestion】support commonjs version HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chalk.