Typo is a scalable template engine designed for cli, which help to format your console output! Typo supports full 256-color ANSI background and foreground, underline, italic, etc.


Make typography beautiful in command-line.

Typo is a scalable node.js template engine designed for and focused on command-line (cli), which helps to format and beautify your console output.

Typo supports not only basic ANSI escope codes, such as basic background and foreground colors, underline, bold, etc, and ALSO full 8-bit colors (256 colors).

npm install typo --save
var typo = require('typo');
typo.log("There's once in a {{blue blue}} moon~");
  • typo-image: display pictures in CLI !
  • typo-ascii: ascii art text in CLI with all kinds of styles ! (on developing)

( '{{<helper[:<data>][|helper[:<data>]]> <text>}}', <object> );
typo.log('{{1}}{{b}}{{c.a}}{{c.b}}', {'1': 1, b:2, c: {a: 3}}); 
// print '123c.b'. 
// in which, `'c.b'` is not matched in `values` and not substituted. 
typo.log('{{bold abc}}');         // print a bold 'abc' 
typo.log('{{rgb:#00ffcc abc}}');  // with a specified RGB color! 
typo.log('{{bold|blue|underline abc}}'); // print a blue bold 'abc' with a underline 
typo.register('sum', function(value){{
    return value.split(',').reduce(function(prevcurrent){
        return (parseInt(current) || 0) + prev;
    }, 0);
typo.log('{{sum 1,2,3}}');         // print 6 

Which will not show up before typo@0.2.0.

if you like typo, there will be a billion thanks if you fork typo and make pull request.

The helpers below are built-in helpers of typo, and you could define your own helpers by typo.register method.

There will also be typo plugins soon or gradually.

Highlight your text text with any RGB colors filled in foreground.

Notice that if your RGB color is not a standard 8-bit RGB color, typo will automatically choose the closest one in the color palette, which will be really helpful.

typo.log('{{bg.rgb:#f26d7d|rgb:#000|bold peach bg and black bold font}}');

There's a background version of RGB: {{bg.rgb:<rgb> <text>}}.

Eight basic ANSI colors:

typo.log('{{magenta purple text}}');
  • italic # not widely supported. Sometimes treated as inverse.
  • bold
  • underline
  • inverse
  • strikethrough

Print a formated output to the command-line. Has no return value.


Template pattern

Object|Array, optional

If no values passed or not matched, the relevant pattern will not be substituted.

function(err, output), optional

Typo also support asynchronous help functions. See "register asynchronous helpers" section.

Returns the parsed or substituted ouput, if all helpers are synchronous.

Or output will be passed to callback.

Register helpers



Will be treated as a sync helper, if has only one [term parameter](http://en.wikipedia.org/wiki/Parameter_(computer_programming) (also called formal parameter);

Besides, the data (in "syntax" section) could be fetched using this.data inside helper.

function(str, callback)

If helper has more than one term parameters, it will be treated as an async helper.

And the second parameter will be the callback which should be implemented inside the helper function.