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

bettercolors

v1.1.1

Published

An alternative library to colors/chalk to use colors in projects

Downloads

59

Readme

BetterColors Package 🎨

The BetterColors package is a utility for formatting and displaying console messages with different colors and styles. It provides a set of methods to format messages for various types such as success, error, warning, info, debug, log, and rainbow.

Installation

You can install the BetterColors package using npm:

npm install bettercolors
pnpm i bettercolors
yarn add bettercolors

Usage

To use the BetterColors package, you need to import the BColors class from the bcolors module. Here's an example:

import { BColors } from 'bettercolors';
const bcolors = new BColors();

bcolors.success('Success message');
bcolors.error('Error message');
bcolors.warning('Warning message');
bcolors.info('Information message');
bcolors.debug('Debug message');
bcolors.log('Log message');
bcolors.rainbow('Rainbow message');

The above code demonstrates the basic usage of the BetterColors package. Each method corresponds to a different message type and formats the message accordingly.

Configuration

You can provide a configuration object to the BColors constructor to customize the package behavior. The configuration object can include the following properties:

  • messagePatterns: An object that allows you to customize the message patterns for different types. You can specify custom patterns for success, error, warn, info, debug, log, rainbow, and default types.

    • Params:
      • {message}: The message to be displayed.
      • {date}: The date of the message.
      • {dated}: The date of the message with the surrounding characters.
      • {type}: The type of the message.
      • {typeMaj}: The type of the message in uppercase.
      • {typeMin}: The type of the message in lowercase.
  • customParams: An object that allows you to define custom parameters for your messages. You can provide any key-value pairs as custom parameters.

  • date: A configuration object that enables you to display the date in your messages. You can specify the format, timezone, and surrounding characters for the date.

Available Colors and Styles

The BetterColors package provides several predefined colors and styles that you can use to format your messages. Here are some of the available colors:

  • Gray
  • Red
  • Green
  • Yellow
  • Blue
  • Magenta
  • Cyan
  • White

And here are a few available styles:

  • Reset
  • Bold
  • Thin
  • Underscore
  • Blink
  • Reverse
  • Hidden

You can utilize these colors and styles to add visual enhancements to your messages.

API Reference

BColors Class

The BColors class provides the following methods:

  • success(message: string): void - Formats and displays a success message.
  • error(message: string): void - Formats and displays an error message.
  • warning(message: string): void - Formats and displays a warning message.
  • info(message: string): void - Formats and displays an information message.
  • debug(message: string): void - Formats and displays a debug message.
  • log(message: string): void - Formats and displays a log message.
  • rainbow(message: string, colors?: string[]): void - Formats and displays a rainbow message.

Types

The BetterColors package defines the following types:

  • Configuration: A type that represents the configuration object used to customize the package behavior. It includes optional properties for message patterns, custom parameters, and date configuration.

Examples

Here are a few examples to demonstrate different usage scenarios:

import { BColors } from 'bettercolors';
const bcolors = new BColors();

bcolors.success('Operation completed successfully');
bcolors.error('An error occurred');
bcolors.warning('Warning: This action is irreversible');
bcolors.info('Please note the following information');
bcolors.debug('Debugging information');
colors.log('Log entry');
bcolors.rainbow('Enjoy the colorful message');
import { BColors, Gray, Red, Green } from 'bettercolors';

export const bcolors = new BColors({
  messagePatterns: {
    success: `${Gray}[SUCCESS ${Bold}{user}${Reset}]: ${Green}{message}`,
    error: `${Gray}[ERROR ${Bold}{environment}${Reset}]: ${Red}{message}`
  },
  customParams: {
    user: "John Doe",
    environment: "development"
  },
  date: {
    surrounded: "[]",
    format: "DD/MM/YYYY HH:mm:ss",
    timezone: "America/Denver"
  }
});

bcolors.success("Operation completed successfully");
bcolors.error("An error occurred");
bcolors.warning("Warning: This action is irreversible");
bcolors.info("Please note the following information");
bcolors.debug("Debugging information");
bcolors.log("Log entry");
bcolors.rainbow("Enjoy the colorful message");

Result:

image

Rainbow Message (with hexToConsoleColor)

import { BColors, Gray, Red, Yellow, Green, hexToConsoleColor } from 'bettercolors';
const bcolors = new BColors();

bcolors.rainbow('Enjoy the colorful message', [
  hexToConsoleColor('#ff0000'),
  hexToConsoleColor('#ff7f00'),
  hexToConsoleColor('#ffff00'),
  hexToConsoleColor('#00ff00'),
]);

bcolors.rainbow("Enjoy the default colorful message");

bcolors.rainbow("Enjoy the customized colorful message with pre-defined color", [
  Gray,
  Red,
  Yellow,
  Green
]);

Result:

image

License

This package is licensed under the MIT License.


This README.md file was automatically generated by a script based on the provided source code files.