Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
nanocolors
Advanced tools
Nanocolors is a tiny and fast library for coloring terminal output. It provides a simple API to style text with various colors and effects, making it easier to create visually appealing command-line interfaces.
Basic Colors
Nanocolors allows you to easily apply basic colors to your text output in the terminal. The example demonstrates how to use red, green, and blue colors.
const { red, green, blue } = require('nanocolors');
console.log(red('This is red text'));
console.log(green('This is green text'));
console.log(blue('This is blue text'));
Text Effects
In addition to colors, Nanocolors supports various text effects such as bold, underline, and italic. The example shows how to apply these effects to your text.
const { bold, underline, italic } = require('nanocolors');
console.log(bold('This is bold text'));
console.log(underline('This is underlined text'));
console.log(italic('This is italic text'));
Combining Colors and Effects
Nanocolors allows you to combine colors and text effects to create more complex styles. The example demonstrates combining red with bold and green with underline.
const { red, bold, underline } = require('nanocolors');
console.log(red(bold('This is bold and red text')));
console.log(underline(green('This is underlined and green text')));
Chalk is a popular library for styling terminal output. It offers a rich API for applying colors and text effects. Compared to Nanocolors, Chalk has a larger footprint but provides more features and customization options.
Colors is another library for adding color and style to terminal output. It is similar to Nanocolors in terms of functionality but is slightly larger in size. Colors also provides a more extensive set of features.
CLI-Color is a library for styling terminal output with colors and effects. It is comparable to Nanocolors in terms of performance and size, but offers a different API and additional features like progress bars and tables.
A tiny and fast Node.js library for formatting terminal text with ANSI colors.
chalk
. Both loading and calls.node_modules
than chalk
.import { green, bold } from 'nanocolors'
console.log(
green(`Task ${bold('1')} was finished`)
)
API was heavily inspired
by @jorgebucaran’s
colorette
with few cool hacks
copied from @lukeed’s
kleur
.
Function calling time:
$ ./test/benchmark.js
chalk 11,608,010 ops/sec
cli-color 752,419 ops/sec
ansi-colors 3,601,857 ops/sec
kleur 15,185,239 ops/sec
kleur/colors 21,113,231 ops/sec
colorette 19,712,884 ops/sec
nanocolors 21,176,376 ops/sec
Library loading time:
$ ./test/loading.js
chalk 3.465 ms
cli-color 21.849 ms
ansi-colors 1.101 ms
kleur 1.628 ms
kleur/colors 0.508 ms
colorette 2.610 ms
nanocolors 0.486 ms
The space in node_modules
including sub-dependencies:
$ ./test/size.js
chalk 192 KB
cli-color 5120 KB
ansi-colors 40 KB
kleur 44 KB
colorette 32 KB
nanocolors 36 KB
Test configuration: ThinkPad X1 Carbon Gen 9, Fedora 34, Node.js 16.8.
chalk
Replace import and use named exports:
- import chalk from 'chalk'
+ import { red, bold } from 'nanocolors'
Unprefix calls:
- chalk.red(text)
+ red(text)
Replace chains to nested calls:
- chalk.red.bold(text)
+ red(bold(text))
Nano Colors exports functions:
Colors | Background Colors | Modifiers |
---|---|---|
black | bgBlack | dim |
red | bgRed | bold |
green | bgGreen | hidden |
yellow | bgYellow | italic |
blue | bgBlue | underline |
magenta | bgMagenta | |
cyan | bgCyan | reset |
white | bgWhite | |
gray |
Functions are not chainable. You need to wrap it inside each other:
import { black, bgYellow } from 'nanocolors'
console.log(bgYellow(black(' WARN ')))
Functions will use colors only if Nano Colors auto-detect that current environment supports colors.
You can get support level in isColorSupported
:
import { isColorSupported } from 'nanocolors'
if (isColorSupported) {
console.log('With colors')
}
You can manually switch colors on/off and override color support auto-detection:
import { createColors } from 'nanocolors'
const { red } = createColors(options.enableColors)
On undefined
argument, createColors
will use value
from color support auto-detection.
Nano Colors has build-in Deno support.
import { red } from 'https://deno.land/x/nanocolors/mod.ts'
FAQs
4x times faster than chalk and use 5x less space in node_modules
We found that nanocolors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.