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-ts

v3.0.0

Published

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

Downloads

1

Readme

Euriklis - message package.

About the package:

The @euriklis/message-ts package is a typescript tool that provides an utility library for colored console printing of messages with some additional properties like warning symbol, information symbol, check symbol etc.

Installation

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

npm install @euriklis/message-ts --save

or

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

This command will add the package to your node_modules folder.

Usage:

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

import message from '@euriklis/message-ts';
new message()
    .bold
    .italic
    .underline
    .setColorYellow
    .append('Euriklis information message:\n')
    .reset
    .setColorGreen
    .appendCheckMark
    .appendWhiteSpace()
    .setColorCyan
    .append('The message library of the euriklis package was successfully installed.')
    .reset.log()
// print an error message:
new message().bold.italic.underline
    .setBgColorYellow
    .setColorCyan
    .blink
    .append('Euriklis error message:')
    .reset
    .append("\n")
    .setColorRed
    .appendWarningSign
    .appendWhiteSpace()
    .setColorYellow
    .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-ts library. Every message instance has a text property, that is the result of the applied methods.

  • 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:
 new message().underline 

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:
/**
 * @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 setColorRed, setColorCyan 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-ts';
new message().bold.italic.underline
    .setColorYellow // or setColor('yellow')
    .append('Information message:\n')
    .reset // to unset the bold, italic and underline
    .setColorCyan
    .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 setColor... 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.

import message from '@euriklis/message-ts'
new message().append('We appended a text').log()
appendCheckMark()

appends check mark symbol to the text. For example:

import message '@euriklis/message-ts'
import validator '@euriklis/validator-ts'
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).isArray.and.isEmpty
    .or.isSame(null).or.isUndefined
    .on(true, () => {
        new message().bold.italic.underline
            .setColorYellow
            .append('Information message:\n').reset
            .setColorGreen
            .appendCheckMark
            .appendWhiteSpace
            .setColorCyan
            .append('The buffer is empty and the program will ')
            .append('start to compute the required values...')
            .reset.log()
    })
new message().appendNotCheckMark

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

new message().appendWarningSign

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

new message().appendWhiteSpace 

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.setColorYellow.setBgColor('rgb(45, 140, 200)')
    .appendLogicalForAllSymbol
    .append(' a, b : ')
    .append('a ')
    .appendLogicalElementOfSymbol
    .appendWhiteSpace()
    .appendMathNaturalNumbersSymbol
    .appendWhiteSpace()
    .appendLogicalConjunctionSymbol
    .appendWhiteSpace()
    .append('b')
    .appendWhiteSpace()
    .appendLogicalElementOfSymbol
    .appendWhiteSpace()
    .appendMathNaturalNumbersSymbol
    .appendWhiteSpace()
    .appendLogicalFollowsSymbol
    .appendWhiteSpace()
    .appendLogicalExistsSymbol
    .appendWhiteSpace()
    .append('c :')
    .appendWhiteSpace()
    .append('c ')
    .appendLogicalElementOfSymbol
    .appendWhiteSpace()
    .appendMathNaturalNumbersSymbol
    .appendWhiteSpace()
    .appendLogicalConjunctionSymbol
    .append(' c')
    .appendWhiteSpace()
    .appendLogicalIdentical
    .appendWhiteSpace()
    .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().appendMath<some symbol> and
new message().appendLogical<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()
    .appendMathCubeRootSymbol
    .append('x + ').appendMathPartialDifferential
    .append('y / ').appendMathPartialDifferential
    .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:')
    .appendAmbulanceSymbol
    .append('\n')
    .append('This is the corona virus symbol:')
    .appendCoronaVirusSymbol
    .append('\n')
    .append('This is the copyright symbol:')
    .appendCopyrightSymbol
    .append('\n')
    .append('This is the registered symbol:')
    .appendRegisteredSymbol
    .append('\n')
    .append('This is the masked face symbol:')
    .appendFaceWithMedicalMaskSymbol
    .append('\n')
    .append('This is the hourglass symbol:')
    .appendHourglassSymbol
    .append('\n')
    .append('This is the heart symbol:')
    .appendHeartSymbol
    .append('\n')
    .append('This is the keyboard symbol:')
    .appendKeyboardSymbol
    .append('\n')
    .append('This is a joyful face:')
    .appendFaceWithTearsOfJoy
    .append('\n')
    .append('This is the water symbol:')
    .appendPotableWaterSymbol
    .append('\n')
    .append('This is the Bitcoin symbol:')
    .appendBitcoinSymbol
    .append('\n')
    .append('This is the rose symbol:')
    .appendRoseSymbol
    .append('\n')
    .append('This is the euro symbol:')
    .appendEuroSymbol
    .append('\n')
    .append('This is the question mark symbol:')
    .appendQuestionMarkOrnament
    .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-ts';
const error = new Error();
error.name = new message()
  .bold
  .italic
  .underline
  .setColorYellow
  .append("Internal error message:\n").reset.text;

error.message = new message().setColorRed
  .appendWarningSign
  .appendWhiteSpace()
  .setColorCyan
  .append("The file name that was created already exists ")
  .append("so please select other name for your application.")
  .reset.text;
console.log(error.name);
console.log(error.message);

Bugs and tips

If you want to inform me for some mistakes or errors which exist in the library, use the issues section of the repository.

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.