npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@spacingbat3/kolor

v4.0.0

Published

A simple module to colorize your Node.js console.

Downloads

3,960

Readme

@spacingbat3/kolor

A simple Node.js module to add kolors to you console!

Kolor is a Polish word that means colour / color.

Usage:

ESM / TypeScript:

  1. Importing selected group of functions (colors or modifiers[*]):
import {colors, modifiers} from "@spacingbat3/kolor"

// Because errors should be red :)
console.error(colors.red("ERROR: Something went wrong!"))

// Modifiers are grouped by `safe` and `other`:
console.log(modifiers.safe.bold("Definitely important text."))
  1. Importing default object as colors that contains all method packed in one object (except other modifiers, they're in unsafe object).
import colors from "@spacingbat3/kolor"

// Now, syntax is similar to the one in `colors/safe` module.
console.warn(colors.bold("==> "+colors.brightYellow("Warning:"))+" Something happened!")

CommonJS:

// Synchronously with `require` (CommonJS):
const { colors, modifiers } = require("@spacingbat3/kolor")

console.log(colors.purple("Colorized text goes here."));

// or, with "default" object

const colors_2 = require("@spacingbat3/kolor").default;

console.log(colors_2.purple("Colorized text goes here."));

// Async with `import` (ESM):
import("@spacingbat3/kolor")
   .then(kolor => {
      // Here, default, colors and modifiers objects are available.
      const { colors, modifiers } = kolor;
      console.debug(colors.gray(colors.bold("Debug")+": some information goes here!"));
   })
   .catch(e => console.error(e));

Why I started to develop it?

In general, I made this module as an answer to colors library sabotage. I decided to neither thrust colors not any alternatives to it, when I only need some of its features.

You can use this library as well in your project, this is why I publish it. You may ask: should I trust you? It depends on what you need – as ISC license says, this program has no guarantee it will work as expected, yet this software is developed in hope to be useful to anyone (like most OSS software should be developed). Also, I may not frequently improve it, I made it specifically for my personal needs, if you need something more complex just use another library.

Please note it's syntax is not fully compatible with colors, specifically it is not touching the String.prototype. You may find it easier to move from colors/safe, through. If you need a library that uses String.prototype to easily switch from colors, this module is not for you, neither chalk is.

Why not just use chalk or fork of colors?

This project has a different philosophy that both of these projects. It's neither an ESM module nor has any rich features – it's much more simple, doing only some simple tests to detect if text should be colorized or not and being limited (at least for now) only to 16-bit color palete. It might be however much more performant, as it uses ES2021 features to be much shorter, simpler and not being bloated with unnecessary colors.

Another difference (at least from colors) is that kolor separates some ANSI escape codes that are not working on all platforms, which you may find useful if your application is meant to be cross-platform.

Since v3.2.0 it also provides the type definitions for transforming the literal types, which makes TypeScript to accurately predict all combinations of types for the library and overall improves the type accuracy (not just for literals).

Legal

This project is licensed under the ISC license, which should be distributed with this project. Not distributing it with this library might be against the license – please read the license for further information.