1.0.1 • Published 6 months ago

console-pastel v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

ConsolePastel

ConsolePastel is a javascript tool which allows you to log text to the console in different colours and styles with the help of escape sequences.

Documentation

Table of Contents

Installation - Node JS

Navigate to your project folder in the cmd and run the following command.

npm i console-pastel

Implementation - Web

Navigate to the file in which you're gonna source the ConsolePastel script and paste the following code in the head tag or at the end of the body.

<script src="https://unpkg.com/console-pastel/cpastel.web.js"></script>

Functions

  • format

cpastel.format('Hello World', {color: 'red', style: 'bold'}, true);

In this example, we are calling the cpastel.format function to format a string into a certain colour and/or style. The arguments passed into the function must take the following form.

argument1 - string to be formatted using Terminal Pastel argument 2 - an object containing 2 properties; 'color' and 'style' to specify what colour and style the text should be formatted to. Check out the Colours and Styles for more info. argument 3 - specifies whether the styles should be reset at the end of the string. If set to false, the styles will be carried to the next content logged to the console.

  • log

cpastel.log('Hello World', {color: 'yellow', style: 'bold'});

In this example, we are calling the cpastel.log function to format a string into a certain colour and/or style and log it to the console. The arguments passed into the function must take the following form.

argument1 - string to be formatted and logged to the console argument2 - an object containing 2 properties; 'color' and 'style' to specify what colour and style the text should be formatted to. Check out the Colours and Styles for more info.

  • f

cpastel.f('<Lorem ipsum:12> dolor, sit amet <consectetur:34>');

In this example, we call the pastel.f function. Instead of formatting the entire string, it formats parts of the string we specify using stylable blocks.

Stylable blocks are written in the following way.

<Text to be formatted:[style code][colour code]>

To get the colour/style codes, check out the Colours and Styles sections. Some example stylable blocks are given below.

<Lorem ipsum:11> // same as, {color: 'black', style: 'bold'};
<Lorem ipsum:34> // same as, {color: 'yellow', style: 'underline'};
<Lorem ipsum:36> // same as, {color: 'magenta', style: 'underline'};
<Lorem ipsum:42> // same as, {color: 'red', style: 'strikethrough'};

Colours

ColourValueCode
Defaultdefault0
Blackblack1
Redred2
Greengreen3
Yellowyellow4
Blueblue5
Magentamagenta6
Cyancyan7
Whitewhite8

Styles

StyleValueCode
Defaultdefault0
Boldbold1
Italicitalic2
Underlineunderline3
Strikethroughstrikethrough4

----- End -----