Gathering detailed insights and metrics for @colors/colors
Gathering detailed insights and metrics for @colors/colors
Gathering detailed insights and metrics for @colors/colors
Gathering detailed insights and metrics for @colors/colors
npm install @colors/colors
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
104 Stars
295 Commits
14 Forks
2 Watching
2 Branches
44 Contributors
Updated on 25 Aug 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-5.7%
4,390,818
Compared to previous day
Last week
2%
25,046,848
Compared to previous week
Last month
5.6%
105,397,276
Compared to previous month
Last year
47.6%
1,112,546,180
Compared to previous year
2
Please check out the roadmap for upcoming features and releases. Please open Issues to provide feedback.
npm install @colors/colors
By popular demand, @colors/colors
now ships with two types of usages!
The super nifty way
1var colors = require('@colors/colors'); 2 3console.log('hello'.green); // outputs green text 4console.log('i like cake and pies'.underline.red); // outputs red underlined text 5console.log('inverse the color'.inverse); // inverses the color 6console.log('OMG Rainbows!'.rainbow); // rainbow 7console.log('Run the trap'.trap); // Drops the bass 8
or a slightly less nifty way which doesn't extend String.prototype
1var colors = require('@colors/colors/safe'); 2 3console.log(colors.green('hello')); // outputs green text 4console.log(colors.red.underline('i like cake and pies')); // outputs red underlined text 5console.log(colors.inverse('inverse the color')); // inverses the color 6console.log(colors.rainbow('OMG Rainbows!')); // rainbow 7console.log(colors.trap('Run the trap')); // Drops the bass 8
I prefer the first way. Some people seem to be afraid of extending String.prototype
and prefer the second way.
If you are writing good code you will never have an issue with the first approach. If you really don't want to touch String.prototype
, the second usage will not touch String
native object.
The package will auto-detect whether your terminal can use colors and enable/disable accordingly. When colors are disabled, the color functions do nothing. You can override this with a command-line flag:
1node myapp.js --no-color 2node myapp.js --color=false 3 4node myapp.js --color 5node myapp.js --color=true 6node myapp.js --color=always 7 8FORCE_COLOR=1 node myapp.js
Or in code:
1var colors = require('@colors/colors'); 2colors.enable(); 3colors.disable();
1var name = 'Beowulf'; 2console.log(colors.green('Hello %s'), name); 3// outputs -> 'Hello Beowulf'
1 2var colors = require('@colors/colors'); 3 4colors.setTheme({ 5 silly: 'rainbow', 6 input: 'grey', 7 verbose: 'cyan', 8 prompt: 'grey', 9 info: 'green', 10 data: 'grey', 11 help: 'cyan', 12 warn: 'yellow', 13 debug: 'blue', 14 error: 'red' 15}); 16 17// outputs red text 18console.log("this is an error".error); 19 20// outputs yellow text 21console.log("this is a warning".warn);
1var colors = require('@colors/colors/safe'); 2 3// set single property 4var error = colors.red; 5error('this is red'); 6 7// set theme 8colors.setTheme({ 9 silly: 'rainbow', 10 input: 'grey', 11 verbose: 'cyan', 12 prompt: 'grey', 13 info: 'green', 14 data: 'grey', 15 help: 'cyan', 16 warn: 'yellow', 17 debug: 'blue', 18 error: 'red' 19}); 20 21// outputs red text 22console.log(colors.error("this is an error")); 23 24// outputs yellow text 25console.log(colors.warn("this is a warning")); 26
1var colors = require('@colors/colors'); 2 3colors.setTheme({ 4 custom: ['red', 'underline'] 5}); 6 7console.log('test'.custom);
Protip: There is a secret undocumented style in colors
. If you find the style you can summon him.
No vulnerabilities found.
No security vulnerabilities found.