Skip to content

kuznetsovlv/print

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Printing method

Extracts method print to formated print into stdout.

Progect on GitHub.

Content.

Installation.

npm install print-str --save

How to use.

Common.

The library print-str extracts the only method print. The print waits one required argument and any number of optional arguments. First required argument is string argument str - a tagged string you want to display. Other arguments may be added in any order after str and able to be one of type:

  • Object of the variables to be substituted into str,
  • String of the options that modify method's work.

String.

The string to display should be added as first argument str. It may have tags to format it.

Tags.

There are two type of available tags: format tags and varaibles. Both type of tags may be shielded by prior symbol \ (realy to shield \ you need insert into string this symbol dubled: \\).

Format tags.

Format tags start with symbol @ and ends with ;. Between these two symbols must be one or more format options separeted by commas. For example @fBlue,bgGreen;. These options define format of the following text. Unsupported options are ignored. All available options are in the list below:

  • Common optios:
    • Reset
    • Bright
    • Dim
    • Underscore
    • Blink
    • Reverse
    • Hidden
  • Font color options:
    • fBlack
    • fRed
    • fGreen
    • fYellow
    • fBlue
    • fMagenta
    • fCyan
    • fWhite
  • Background color options:
    • bgBlack
    • bgRed
    • bgGreen
    • bgYellow
    • bgBlue
    • bgMagenta
    • bgCyan
    • bgWhite
Variable tags.

Variable tags starts with symbol $ and ends with ;. Between these two symbols must be a name of the variable to substitute. The variable must be defined as a key of one of the following object arguments. If variable is not defined in these arguments it would not substituted.

Optional arguments.

Optional arguments follow first str argument. They may be addedin any order. There are two types of optional arguments.

Variables.

If optional argument is type of object it will interpreted as a set of variables.

Options

If optional argument is type of string it will interpreted as a list of options. Alloptions in string separated by commas. Option may consist of it's name and value. Value separated from name by =. If option has only name but not value nor symbol =, it's value interpeted as true. If option contains = but no value after it, option's value is empty string. All available options are below:

  • [noStyles = false] - if true - all format tags will be interpreted as a text.
  • [noVars = false] - if true - all variable tags will be interpreted as a text.
  • [final = false] - true means that output finished and after output method will reset all styles and print symbol \n.
  • [encoding = 'utf8'] - encoding.

Example.

import print	from 'print-str';

const str = '@fBlue,bgGreen;Blue text, green background. @fRed;red text@bgBlue;, blue background.\\@bgRed; This must be not changed. Printing variable: $value;$end;';

print(str, {value: 12, end: '\n'});

print(str, 'noStyles,final');

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published