DEV Community

Valeria
Valeria

Posted on

4

Day 12: Pico-co-colors 🐥

We've already touched gradients in the terminal, but what if you'd like to simply color one line, word or phrase? Well, picocolors does exactly that nice and easy!

Install with your favourite package manager, e.g. deno add npm:picocolors and create a file, e.g. main.ts:

import pico from "picocolors";

console.log(
  pico.redBright("Happy ") +
    pico.greenBright("Holidays") +
    pico.yellowBright("!")
);
Enter fullscreen mode Exit fullscreen mode

Run with e.g. deno run -A ./main.ts and enjoy the festive greeting:

Of course, you could always use ASCII Color codes directly, e.g. like so:

console.log(
    "\u001b[91mHappy \u001b[92mHolidays\u001b[93m!"
); // 91 = Foreground bright red, 92 = Bright green and 93 is Bright yellow
Enter fullscreen mode Exit fullscreen mode

But that's way less descriptive, isn't it?

Not to mention that picocolors is NO_COLOR friendly and comes with couple of extra beauties like italic, bold, dim and inverse.

Do try them out and share your creations!

Liked the content and would love to have more of it all year long?

Buy Me A Coffee

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (3)

Collapse
 
fyodorio profile image
Fyodor

When they say “no dependencies”, I’m sold 🥳

Collapse
 
valeriavg profile image
Valeria

I know right?! I was gonna write about Chalk first, but this one is leaner 🤗

Collapse
 
webdiscus profile image
webdiscus

please pay attention to ansis.

There is the list of similar libraries:

chalk,
picocolors,
kleur,
ansi-colors,
kolorist,
colorette,
cli-color,
colors-cli,
colors.js,

You can compare features and benchmarks of all libraries from the list above.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay