Installations
npm install colorfy
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
14.17.3
NPM Version
6.14.13
Score
74.1
Supply Chain
99.4
Quality
79.9
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
Andifeind
Download Statistics
Total Downloads
97,242
Last Day
12
Last Week
58
Last Month
258
Last Year
29,326
GitHub Statistics
2 Stars
81 Commits
1 Watching
2 Branches
1 Contributors
Bundle Size
7.75 kB
Minified
2.19 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.4.0
Package Id
colorfy@2.4.0
Unpacked Size
93.61 kB
Size
13.27 kB
File Count
17
NPM Version
6.14.13
Node Version
14.17.3
Publised On
26 Apr 2023
Total Downloads
Cumulative downloads
Total Downloads
97,242
Last day
300%
12
Compared to previous day
Last week
7.4%
58
Compared to previous week
Last month
9.8%
258
Compared to previous month
Last year
341.1%
29,326
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Colorfy
Colorfy your console output with pretty ANSI colors.
Supports:
- Zero dependencies
- 256 ANSI color codes
- Pluralization
- Text indention
- Static color methods
Installation
1npm i colorfy --save
Usage
1import {colorfy} from 'colorfy' 2 3const cf = colorfy() 4console.log(cf.red('Hello').green('colorful').blue('World!').colorfy()) 5 6// or let colorfy print it out 7 8cf.red('Hello').green('colorful').blue('World!').print() 9 10// static methods 11import {colorize} from 'colorfy' 12const green = colorize.green('Green text') 13const red = colorize.red('Red text')
Methods
The initial colorfy()
call in the example above returns a colorfy instance. All colorize methods are chainable.
Pass colorfy()
as last method to a chain to get a pretty colorful string.
Since version v2.0.0
, colofy returns all color methods as static methods too.
red(text, [styles])
Draws red text
yellow(text, [styles])
Draws yellow text
green(text, [styles])
Draws green text
blue(text, [styles])
Draws blue text
fire(text, [styles])
Draws fire red text
orange(text, [styles])
Draws orange text
azure(text, [styles])
Draws azure blue text
lime(text, [styles])
Draws lime text
pink(text, [styles])
Draws pink text
plum(text, [styles])
Draws plum text
turq(text, [styles])
Draws turquoise text
ored(text, [styles])
Draws orangered text
dred(text, [styles])
Draws dark red text
dgreen(text, [styles])
Draws dark green text
dblue(text, [styles])
Draws dark blue text
grey(text, [styles])
Draws grey text
dgrey(text, [styles])
Draws dark grey text
ddgrey(text, [styles])
Draws dark dark grey text
lgrey(text, [styles])
Draws light grey text
llgrey(text, [styles])
Draws light light grey text
lbrown(text, [styles])
Draws light brown text
black(text, [styles])
Draws black text
white(text, [styles])
Draws white text
txt(text, [styles])
Draws text in default color. Without any styling
ansi(color, text, [styles])
Draws text in any ansi color. Must be a number between 0 and 255
auto(text, [styles])
Calculates a cross number between 0 and 99 of the input and uses a color based on this cross number. This feature could be useful for logging of hash values.
Run node examples/colorfy.js
to see colorfy in action. It gives you a list of all ansi color codes.
The styles
argument is optional and defines the text style.
bold
Draws bold text
italic
Draws italic text
underline
Draws underlined text
blink
Draws a flashing text
trim
Trims your text on both sides (See trim section below)
rtrim
Trims your text on its right side (See trim section below)
ltrim
Trims your text on its left (See trim section below)
bgred
Draws red background
bgyellow
Draws yellow background
bggreen
Draws green background
bgblue
Draws blue background
bgfire
Draws fire red background
bgorange
Draws orange background
bgazure
Draws azure blue background
bglime
Draws lime background
bgpink
Draws pink background
bgplum
Draws plum background
bgturq
Draws turquoise background
bgored
Draws orangered background
bgdred
Draws dark red background
bgdgreen
Draws dark green background
bgdblue
Draws dark blue background
bggrey
Draws grey background
bgdgrey
Draws dark grey background
bgddgrey
Draws dark dark grey background
bglgrey
Draws light grey background
bgllgrey
Draws light light grey background
bglbrown
Draws light brown background
Seperate stylings by a space cf.red('foo', 'bold underline')
Background colors
Background colors can be set as a style. See list above with all supported background styles
1cf.black('Black text on yellow background', 'bgyellow');
Joining
Since v2.0.0
, auto joining was disabled by default. To enable joining of text blocks by a space, set the autoJoin
flag to true.
All texts getting joined by a space character if joining is enabled. The trim parameter can be used to avoid joining for a certain text block.
1const cf = colorfy({ autoJoin: true }) 2cf.grey('(').green('20ms').grey(')').colorfy();
returns ( 20ms )
1const cf = colorfy({ autoJoin: true }) 2cf.grey('(').green('20ms', 'trim').grey(')').colorfy();
returns (20ms)
(No space around the number)
Output
The colorfy()
method returns a colorfied string of the colorfy chain. Colorization can be skiped by passing false
as first argument to colorfy()
1cf.red('All colors are beautiful').colorfy(); //Returns a colofied string 2cf.red('All colors are beautiful').colorfy(false); //Returns a plain string
print([bool colorize])
The print method prints a colorfy chain to stdout. The comands below are the same
1console.log(cf.red('All colors are beautiful').colorfy()); 2cf.red('All colors are beautiful').print();
write([bool colorize])
The write method writes a colorfy chain to stdout. It doesn't insert a trailing newline
1cf.red('All colors ').write(); 2cf.green('are beautiful').write();
indent(num size)
Colorfy supports text indention. Indentions itself are always uncolorized. The indent method sets the indention for the next lines. It expects the indention size as its onliest argument. The size argument increase the current indention size.
indent(number)
1const cf = colorfy() 2cf.txt(' '.repeat(10)).white('WARNING!', 'bgred').nl() 3cf.txt(' '.repeat(10)).white('The server is down!', 'bgred')
The code with usage of indent()
is quite smarter.
1const cf = colorfy() 2cf.indent(10) 3cf.white('WARNING!', 'bgred').nl() 4cf.white('The server is down!', 'bgred')
Please note, a call of indent()
inserts a line break.
reset()
Reset the indention and inserts a line break.
json(obj data, [num depth])
Colorizes a data construct. Dept is the maximum nesting depth, default value = 5.
1const cf = colorfy() 2cf.txt('JSON: ').json({ 3 one: 'One' 4 two: 2, 5 three [ 6 'Banana', 7 'Coconut' 8 ] 9}).print()
Pluralization
Texts can be pluralized. Add an [singular, plural, number]
array as a text block and colorfy returns the singular version if number === 1
otherwise the plural.
1const cf = colorfy() 2const passedTests = 35; 3const failedTests = 1; 4cf.green(passedTests).txt(['test passed', 'tests passed', passedTests]).print()); 5cf.red(failedTests).txt(['test failed', 'tests failed', failedTests]).print());
This example would render a red block
Config
Preset configurations can be changed by using the config()
method.
1const cf = colorfy() 2cf.config({ 3 trim: true 4}) 5 6cf.txt('(').green('13ms').txt(')') // Returns (13ms)
Preset configurations:
Property | Description |
---|---|
trim | Enable word trimming ( Disabled by default ) |
indention | Set the default indention for the indent() method. Default: 0 |
autoJoin | Joins text blocks by a space. Default: false |
Author
(c) 2016 by Andi Heinkelein
Licensed under MIT license.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- 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 'develop'
Reason
19 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- 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-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-w5p7-h5w8-2hfq
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
Score
1.7
/10
Last Scanned on 2025-01-27
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