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

@simple_js/log-styler

v1.0.1

Published

A simple library for coloring text in the console.

Downloads

148

Readme

Log Styler Library

A simple and flexible library for coloring text and backgrounds in the console using ANSI escape codes. This library allows developers to easily add color and style to their console output, enhancing the user experience.

Table of Contents

Features

  • Supports multiple text colors and background colors.
  • Provides various text styles: bold, italic, underline, strikethrough, and more.
  • Simple and intuitive API.

Installation

You can install the library via npm. Run the following command:

npm install @simple_js/log-styler

Usage

To use the library, require it in your JavaScript file:

const { colorText, bgColorText, colorize } = require('@simple_js/log-styler');

API Reference

colorText(text, color, [style])

Colors the text with the specified color and optional style.

  • Parameters:
    • text (string): The text to color.
    • color (string): The color to apply (e.g., 'red', 'green').
    • style (string, optional): The style to apply (e.g., 'bold', 'italic').
  • Returns: A string with the colored text.

bgColorText(text, bgColor)

Colors the background of the text with the specified background color.

  • Parameters:
    • text (string): The text to color.
    • bgColor (string): The background color to apply (e.g., 'blue', 'yellow').
  • Returns: A string with the text and colored background.

colorize(text, options)

Colors the text with the specified options.

  • Parameters:
    • text (string): The text to color.
    • options (object): The options for coloring:
    • color (string): The color to apply.
    • bgColor (string): The background color to apply.
    • style (string): The style to apply.
  • Returns: A string with the colored text based on the options provided.

Examples

Here are some examples demonstrating how to use the library:

Basic Color Usage

const { colorText } = require('@simple_js/log-styler');

console.log(colorText('This is red text', 'red'));
console.log(colorText('This is bold green text', 'green', 'bold'));
console.log(colorText('This is italic blue text', 'blue', 'italic'));

Background Color Usage

const { bgColorText } = require('@simple_js/log-styler');

console.log(bgColorText('This text has a blue background', 'blue'));
console.log(bgColorText('This text has a yellow background', 'yellow'));

Using colorize

const { colorize } = require('@simple_js/log-styler');

console.log(colorize('This is bright yellow text on a black background', { color: 'brightYellow', bgColor: 'black', style: 'bold' }));
console.log(colorize('This is strikethrough text', { color: 'cyan', style: 'strikethrough' }));
console.log(colorize('This is inverted text', { color: 'green', bgColor: 'black', style: 'inverse' }));

Handling Invalid Colors

The library will issue warnings for unsupported colors or styles:

console.log(colorText('Invalid color: purple', 'purple'));

License

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

Contributing

Contributions are welcome! If you have suggestions for improvements or find bugs, please open an issue or submit a pull request.

  • Fork the repository.
  • Create your feature branch: git checkout -b feature/AmazingFeature
  • Commit your changes: git commit -m 'Add some amazing feature'
  • Push to the branch: git push origin feature/AmazingFeature
  • Open a pull request.

Thank you for considering contributing to this project!