multiple chalk functions share the same _styles array
See original GitHub issueI’d been doing this with chalk 0.4:
var COLORS = {
INFO: chalk.bold.green,
WARN: chalk.bold.yellow,
ERROR: chalk.bold.bgRed,
// etc
}
Upgrading to 0.5, I find that all of the functions I’ve stored are all set to apply the styles of the last on in the object.
Issue Analytics
- State:
- Created 9 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
How to combine multiple inline style objects? - reactjs
For two static styles, doing StyleSheet.compose() outside the render function might be more efficient. It will produce a new static stylesheet that will...
Read more >Styling console.log() Output With A Chalk-Inspired Formatter ...
To do this, I'm going to build off of yesterday's echo object. Only, instead of having just the two custom stylers - asWarning...
Read more >Colorize your console output with Chalk! - Node.js ... - YouTube
Chalk NPM package link:https://www.npmjs.com/package/chalkIn this video I'll be demonstrating how you can use the hugely popular NPM package ...
Read more >Chalk: Terminal String Styling Done Right - Morioh
Compose multiple styles using the chainable API log(chalk.blue. ... Data Driven Features | Calling JavaScript Functions | Calling Java Code | Commonly ...
Read more >Functional Programming in JavaScript: Introduction and ...
Functional programming (FP) is a style of coding that's been ... A combinator has the same requirements as a pure function, plus one...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As I fiddle on a patch for this, I can’t think of a way of providing the same API with the same performance. Each getter needs to return a new object (a function), and that function needs to have all the getters set.
Object.defineProperty
is brutal in a loop. Here’s the options I see:var style = chalk.blue.bgRed.bold
, since subsequent uses ofstyle
won’t be triggering newdefineProperty
s. I’ve added a benchmark that shows with the style cached into a variable.__proto__
on the function to an object with the properties already defined.__proto__
is deprecated, in ES6 it will becomeObject.setPrototypeOf
, but it can’t be remove any time soon if they don’t want to blow up the web. The docs for__proto__
state that it hurts performance, but comparing the benchmark with usingObject.create()
andchalk.red._('foo')
showed it was actually slightly slower than this__proto__
hack.chalk
(this is still much slower than caching a couple styles).Here’s the benches with option 2 (and an optimization of not doing
[].slice.call(arguments)
:Same here 😃 let me have one last look and I’ll merge it in