Installations
npm install colors
Score
98.8
Supply Chain
100
Quality
75.8
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
>=0.1.90
Typescript Support
No
Node Version
10.16.3
NPM Version
6.9.0
Statistics
5,176 Stars
259 Commits
448 Forks
53 Watching
2 Branches
43 Contributors
Updated on 25 Nov 2024
Bundle Size
9.43 kB
Minified
4.07 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
6,413,733,790
Last day
-11%
3,303,030
Compared to previous day
Last week
1.5%
20,184,763
Compared to previous week
Last month
16.6%
81,389,477
Compared to previous month
Last year
-18.5%
890,864,482
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
2
colors.js
Please check out the roadmap for upcoming features and releases. Please open Issues to provide feedback, and check the develop
branch for the latest bleeding-edge updates.
get color and style in your node.js console
Installation
npm install colors
colors and styles!
text colors
- black
- red
- green
- yellow
- blue
- magenta
- cyan
- white
- gray
- grey
bright text colors
- brightRed
- brightGreen
- brightYellow
- brightBlue
- brightMagenta
- brightCyan
- brightWhite
background colors
- bgBlack
- bgRed
- bgGreen
- bgYellow
- bgBlue
- bgMagenta
- bgCyan
- bgWhite
- bgGray
- bgGrey
bright background colors
- bgBrightRed
- bgBrightGreen
- bgBrightYellow
- bgBrightBlue
- bgBrightMagenta
- bgBrightCyan
- bgBrightWhite
styles
- reset
- bold
- dim
- italic
- underline
- inverse
- hidden
- strikethrough
extras
- rainbow
- zebra
- america
- trap
- random
Usage
By popular demand, colors
now ships with two types of usages!
The super nifty way
1var colors = require('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/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.
Enabling/Disabling Colors
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'); 2colors.enable(); 3colors.disable();
Console.log string substitution
1var name = 'Marak'; 2console.log(colors.green('Hello %s'), name); 3// outputs -> 'Hello Marak'
Custom themes
Using standard API
1 2var colors = require('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);
Using string safe API
1var colors = require('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
Combining Colors
1var colors = require('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.
Stable Version
The latest stable version of the package.
Stable Version
1.4.0
HIGH
3
7.5/10
Summary
Infinite Loop in colors.js
Affected Versions
>= 1.4.1
Patched Versions
0/10
Summary
Infinite loop causing Denial of Service in colors
Affected Versions
= 1.4.44-liberty-2
Patched Versions
0/10
Summary
Infinite loop causing Denial of Service in colors
Affected Versions
>= 1.4.1, <= 1.4.2
Patched Versions
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Warn: project license file does not contain an FSF or OSI license.
Reason
Found 5/24 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Reason
15 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-3gx7-xhv7-5mx3
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Score
2
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More