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

@euriklis/message

v2.1.2

Published

A javascript library which allows you to write style-designed messages, mathematical/logical expressions and special symbols in the terminal.

Downloads

28

Readme

Euriklis - message package.

About the package:

The @euriklis/message package is a javascript tool that provide an utility library for colored console printing of messages with some additional properties like warning symbol, information symbol, check symbol or not check symbol.

Installation

To install the @euriklis/message package just run the following command in the terminal.

npm install @euriklis/message --save --save-exact

This command will add the package to your node_modules folder.

The current version of the package is 2.0.0 and is written in esm mode (import/export).

Usage:

To use the message library you have to import it to your file:

import message from '@euriklis/message';
// print an information message:
new message().bold().italic().underline().set_color_yellow()
    .append('Euriklis information message:\n')
    .reset().set_color_green().append_check_mark()
    .set_color_cyan().append_white_space()
    .append('The message library of the euriklis package was successfully installed.')
    .reset().log()
// print an error message:
new message().bold().italic().underline().set_color_yellow()
    .blink().append('Euriklis error message:\n')
    .reset().set_color_red().append_warning_sign().set_color_yellow().append('The message library of the euriklis package prints error message for you.')
    .reset().log()

Methods:

message methods

All the methods of the message class return message object, but make changes to the text parameter of the instance. So the architecture of the library allows you to chain the methods of the @euriklis/message library. Every message instance has a text property, that is the result of the applied methods. In 03.03.2021 the current version was upgraded and a set of new methods, especially mathematical and logical symbols were added.

  • method bold:
new message().bold()

makes the text which will be shown in the terminal after this method to appear in bold style. For example:

new message().bold().append('This text will be bold...')
    .reset().log()
  • method italic:
new message().italic()

makes the text which will be shown in the terminal in italic style. In the example which was shown above we can apply the italic method as well as the bold method.

new message().bold().italic()
    .append('This text will be bold and italic...')
    .reset().log()
  • method underline or underscore (?!?):
 new message().underline() 
 // or 
 new message().underscore()

this method makes the style of the text that will be shown in the terminal to be underlined.

new message().underline()
    .append('Underlined text')
    .reset().log()
  • method blink:
new message().blink()

the text that will be shown in the terminal will blink.

  • method family setColor (set_color_black, set_color_green, set_color_red, set_color_yellow, set_color_violet, set_color_cyan and etc...):
/**
 * @param {string}color
 **/
new message().setColor(color)

sets the color of the text which will be shown in the terminal. The possible values of the color are 'black', 'red', 'green', 'blue', 'grey', 'violet', 'cyan', 'yellow' and any arbitrary rgb color (typed as string). We recommend you to use the more user-friendly methods set_color_red, set_color_cyan and etc... For example, let us say that we want to write an info message to the terminal with underlined yellow bold style and the content of the information message to be in cyan color, then we have to write:

import message from '@euriklis/message';
new message().bold().italic().underline()
    .set_color_yellow() // or setColor('yellow')
    .append('Information message:\n')
    .reset() // to unset the bold, italic and underline
    .set_color_cyan()
    .append('The file was successfully updated...')
    .reset().log()
  • method family setBgColor:
new message().setBgColor(color)

sets the background color of the text message that will be shown in the terminal. The possible color values of the method are the same with the setColor() method.

  • method reset:
new message().reset()

reset, restart the color/background color and style properties of the text to the default.This method has to be used to unset previous properties like bold, italic, underline. When we want to change the color, it is not necessary to use this method because the set_color_... will change the color automatically. For more details, see the example for the underline and bold method above.

  • method family append/prepend:
/**
 * @param {string} text_message
 **/
new message().append(text_message)

appends a text to the current text property of the message instance. To see the message you have to use the log() method.

const message = require('@euriklis/message')
new message().append('We appended a text').log()
append_check_mark()

appends check mark symbol to the text. For example:

const message = require('@euriklis/message')
const validator =  require('@euriklis/validator')
let buffer = null
// Here we combine the message library with the
// @euriklis/validator package to show a more complicated
// way for the using of the message methods.
new validator(buffer).is_array().and().is_empty()
    .or().is_same(null).or().is_undefined()
    .on(true, () => {
        new message().bold().italic().underline()
            .set_color_yellow()
            .append('Information message:\n').reset()
            .set_color_green()
            .append_check_mark().append_white_space()
            .set_color_cyan()
            .append('The buffer is empty and the program will ')
            .append('start to compute the required values...')
            .reset().log()
    })
new message().append_not_check_mark()

appends the not check mark symbol (⍻) to the text property of the message instance. (prepend_not_check_mark() also exists).

new message().append_warning_sign() 

appends a warning sign (⚠) to the text property of current the message instance.

new message().append_white_space() 

appends an empty interval to the text property.

  • method log:
new message().log() 

prints the message on the terminal.

  • method warn:
new message().warn()

execute console.warn method to the text.

  • method error:
new message().error()

execute console.error() method to the text property.

  • method info:
new message().info()

execute console.info() method to the text property.

Note that the color, background color and style method are valid only in the node terminal environment.

More useful examples:

Let say that we want to print a mathematical expression in formal logic. We can use the append_math_... and append_logic_... methods of the library.

new message().bold().set_color_yellow().setBgColor('red')
    .append_logical_forAll_symbol().append(' a, b : ')
    .append('a ').append_logical_element_of_symbol()
    .append_white_space().append_math_natural_numbers_symbol()
    .append_white_space().append_logical_conjunction_symbol()
    .append_white_space().append('b')
    .append_white_space().append_logical_element_of_symbol()
    .append_white_space().append_math_natural_numbers_symbol()
    .append_white_space().append_logical_follows_symbol()
    .append_white_space().append_logical_exists_symbol()
    .append_white_space().append('c :')
    .append_white_space().append('c ')
    .append_logical_element_of_symbol()
    .append_white_space().append_math_natural_numbers_symbol()
    .append_white_space().append_logical_conjunction_symbol()
    .append(' c').append_white_space()
    .append_logical_identical().append_white_space()
    .append('a + b ').reset().log()

and we have to take the following result in the terminal:

The message library is constructed especially for the needs of writing and printing of mathematical expressions into the terminal, so the methods family

new message().append_math_<some symbol> and
new message().append_logical_<some symbol> 

provides a rich assortment of functionalities and methods that ensure the supporting of expressions relevant to the logical programming, mathematical formulas, integrals, differential equations and partial differentials and set theory.

For example we can write a differential equation:

new message()
    .append_math_cube_root_symbol()
    .append('x + ').append_math_partial_differential()
    .append('y / ').append_math_partial_differential()
    .append('x + ').append('w * y = 0').reset().log()

and will obtain as result in the terminal:

∛x + ∂y / ∂x + w * y = 0

Some other new symbols and functionalities that are not mathematical and logic are presenting in the following code:

new message()
    .append('This is the ambulance symbol:')
    .append_ambulance_symbol().append('\n')
    .append('This is the corona virus symbol:')
    .append_corona_virus_symbol().append('\n')
    .append('This is the copyright symbol:')
    .append_copyright_symbol().append('\n')
    .append('This is the registered symbol:')
    .append_registered_symbol().append('\n')
    .append('This is the masked face symbol:')
    .append_face_with_medical_mask_symbol().append('\n')
    .append('This is the hourglass symbol:')
    .append_hourglass_symbol().append('\n')
    .append('This is the heart symbol:')
    .append_heart_symbol().append('\n')
    .append('This is the keyboard symbol:')
    .append_keyboard_symbol().append('\n')
    .append('This is a joyful face:')
    .append_face_with_tears_of_joy().append('\n')
    .append('This is the water symbol:')
    .append_potable_water_symbol().append('\n')
    .append('This is the Bitcoin symbol:')
    .append_bitcoin_symbol().append('\n')
    .append('This is the rose symbol:')
    .append_rose_symbol().append('\n')
    .append('This is the euro symbol:')
    .append_euro_symbol().append('\n')
    .append('This is the question mark symbol:')
    .append_question_mark_ornament().append('\n')
    .reset().log()

The expected output in the terminal has to be:

This is the ambulance symbol:🚑
This is the corona virus symbol:🦠
This is the copyright symbol:©
This is the registered symbol:®
This is the masked face symbol:😷
This is the hourglass symbol:⌛
This is the heart symbol:❤
This is the keyboard symbol:⌨
This is a joyful face:😂
This is the water symbol:🚰
This is the Bitcoin symbol:₿
This is the rose symbol:🌹
This is the euro symbol:€
This is the question mark symbol:❓

Note for the non console messages. The symbols that are supported of the message library can be used also in the html files or in the site text content. The only exception in this case is that the method family setColor(...) , setBgColor(...), error(), warn(), reset(), italic(), bold(), underline/underscore() and log() can not be used. If you want to put the obtained text content just get the text property of the message instance. The same issue is valid for the Error throwing , where for the throwing of error we simply have to get the text property. For example:

import message from '@euriklis/message';
const error = new Error(); 
error.name = new message().bold().italic()
    .underline().set_color_yellow()
    .append('Internal error message:\n').reset().text;

error.message = new message().set_color_red()
    .append_warning_symbol()
    .append_white_space().set_color_cyan()
    .append('The file name that was created already exists ')
    .append('so please select other name for your application.')
    .reset().text;
throw error;

Bugs and tips

If you want to inform me for something useful for this project or for some possible mistake, you can send me an email to [email protected] or to [email protected]

License

This project has MIT license. Everyone who uses it must know that the author may not be held liable for any third party software and hardware caused damages.