Socket
Socket
Sign inDemoInstall

typo

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    typo

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.


Version published
Weekly downloads
701
increased by0.72%
Maintainers
1
Install size
34.6 kB
Created
Weekly downloads
 

Readme

Source

Typo

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).

screenshot

Installation

npm install typo --save

Getting started

Typo is a Readable stream, which means you can .pipe() and .on('data', c) with it.

// create a typo instance
var typo = require('typo')();

// remember to pipe
typo.pipe(process.stdout);

typo.log("There's once in a {{blue blue}} moon~");

Typo Plugins

  • typo-rgb: support full 8-bit RGB colors !
  • typo-image: display pictures in CLI !
  • typo-ascii: ascii art text in CLI with all kinds of styles ! (on developing)

Usage

Syntax

( '{{<helper[:<data>][|helper[:<data>]]> <text>}}', <object> );
Simple substitution
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.
With helper functions
typo.log('{{bold abc}}');         // print a bold 'abc'
typo.log('{{red abc}}');  		   // print a red 'abc'
With piped helpers
typo.log('{{bold|blue|underline abc}}'); // print a blue bold 'abc' with a underline
Custom helpers
typo.register('sum', function(value){{
    return value.split(',').reduce(function(prev, current){
        return (parseInt(current) || 0) + prev;
    }, 0);
}});

typo.log('{{sum 1,2,3}}');         // print 6
Work with plugins

You need to install plugins first.

npm install typo-image
var image = require('typo-image');
typo.plugin(image);

typo.log('{{~image ./logo.png}}');  // will print the png image to the CLI !
Nested helpers
typo.log('{#list}3{/list}');

Which will not show up before typo@1.0.0.

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

Available helpers

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.

Basic colors

Eight basic ANSI colors:

01234567
blackredgreenyellowbluemagentacyanwhite
typo.log('{{magenta purple text}}');

Other text styles

  • italic # not widely supported. Sometimes treated as inverse.
  • bold
  • underline
  • inverse
  • strikethrough

Plugin: {{rgb:<rgb> <text>}}

You need to install plugin 'typo-rgb' to use this helper.

npm install typo-rgb --save

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.plugin(require('typo-rgb'));
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>}}.

Typo factory and typo constructor

How to create a typo instance.

var Typo = require('typo');
var typo = Typo(options);

Or

// this is the typo constructor from which your module  could be inherited.
var Typo = require('typo').Typo; 
var typo = new Typo(options);
options.clean Boolean

Optional, default to false

If true, typo will clean all styles and output pure text, which is really helpfull if you use typo in CI.

options.output Stream.Writeable

Optional, no default value

The writeable stream to write into. If set, typo will .pipe() output to that stream.

However, you could also use .pipe() method to do this.

Instance Methods

These methods below is the methods of the typo instance.

typo.log(pattern [,values [,callback]])

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

pattern string

Template pattern

values Object|Array

Optional

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

callback function(err, output)

Optional

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

typo.template(pattern [,values [,callback]])

Returns

The parsed or substituted ouput, if all helpers are synchronous.

Or output will be passed to callback.

typo.register(name, helper)

typo.register(helpers_map)

Register helpers for the current instance

name

string

helper (sync)

function(str)

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.

helper (async)

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.

helpers_map

Object

typo.plugin(plugin)

Register a plugin

plugin Object

The typo plugin.

Register global helpers and plugins

var Typo = require('typo');

Typo.register(helpers); // the same parameters as `typo.register`
Typo.plugin(plugin);	 // the same parameters as `typo.plugin`

Keywords

FAQs

Last updated on 03 Aug 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc