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

coloredcli

v1.0.30

Published

A npm package written on node to make your command line colorful

Downloads

18

Readme

coloredcli.js

A npm package written on node to make your command line colorful

coloredcli is a Node.js package designed to enhance the appearance of text on the command line by adding colors and styles. This package provides easy-to-use functions for applying various colors, background colors, and styles to your text output.

Installation

You can install coloredcli using npm:

npm i coloredcli

or

npm install coloredcli

Usage

Basic Usage (Examples)

import * as colorPackage from 'coloredcli/src/index.mjs';

const colorText = 'Hello, this is a colored text!';
const bgColorText = 'This text has a colored background!';
const successText = 'Success message';
const errorText = 'Error message';
const warningText = 'Warning message';

// Apply colors
console.log(colorPackage.applyColor(colorText, 'green'));
console.log(colorPackage.applyBackground(bgColorText, 'bgBlue'));

// Apply styles
console.log(colorPackage.applyStyle(successText, 'bold'));
console.log(colorPackage.applyStyle(errorText, 'italic'));
console.log(colorPackage.applyStyle(warningText, 'underline'));

// Apply color and style in the same console.log
console.log(colorPackage.applyStyle(colorPackage.applyColor(successText, 'green'), 'bold'));

Output

OutputImage

Test: Playing with loops, exploring all the colors available in the list

OutputImage1

Output:

OutputImage12

Test: A story expressing messages to your loved ones

OutputImageStory

Running Tests

In your test script (test.mjs), you can use the runTest function to test different color and style combinations:

import { runTest } from 'coloredcli/test-runner';

runTest();

Constants

You can create a separate file (constants.mjs) to store your text constants and use them in your tests:

// constants.mjs
export const colorText = 'Hello, this is a colored text!';
export const bgColorText = 'This text has a colored background!';
export const successText = 'Success message';
export const errorText = 'Error message';
export const warningText = 'Warning message';
export const boldText = 'Ankit Guria says Hi';

Then, in your test script (test.mjs), you can import and use these constants:

import * as varPackage from './constants.mjs';
import { runTest } from 'coloredcli/test-runner';

runTest(varPackage);

Steps for a layman(Playground)

  1. Create a new project:

npm init -y

This command will create a package.json dependencies for your test file.

Note:

Add the 'module' type in your package.json. It should look something like this.

// package.json
{
    "name": "exampleCLI",
    "version": "1.0.0",
    "description": "An example CLI using coloredcli",
    "main": "example.js",
    "type": "module",
    "scripts": {
        "start": "node example.js"
    },
    "keywords": [],
    "author": "Ankit Guria",
    "license": "ISC",
    "dependencies": {
        "coloredcli": "^1.0.4",
        "coloredcli.js": "^1.0.14"
    }
}
  1. A new file like - "example.js" to be created. Here is the sample code:
// example.js
import * as colorPackage from 'coloredcli/src/index.mjs';
const text = 'This is a colorful story on CLI!';
// a normal console log statement
console.log(text)
// a console log statement equipped with coloredcli.js
console.log(colorPackage.applyBackground(colorPackage.applyColor(text, 'cyan'), 'bgBrightYellow'));
  1. Now run this file, and here you go. node example.js

  2. Play and enjoy more with custom console log statements or something else. The output should be something like this:

output4

Contributing

Feel free to contribute by opening issues or submitting pull requests on GitHub.

License

This project is licensed under the MIT License - see the LICENSE file for details.