1.0.1 • Published 10 years ago

rapidus-sparkle v1.0.1

Weekly downloads
16
License
MIT
Repository
github
Last release
10 years ago

rapidus-sparkle

NPM Version Build Status Coverage Status

A string formatter that creates shiny strings that sparkle with colour. Built using pegjs and chalk.

Installation

npm install --save rapidus-sparkle

Usage

// Create a formatter
var frmt = require('rapidus-sparkle')('%{red :foo %{:middle-#-} %{blue:bar}, yo!}')

// Format things
console.log(frmt({ foo: 'a foo thing'
                 , bar: 'a bar thing'
                 , middle: 'green'
                 }))

Format

  • :attr replace place holder with value from object.

    sparkle('hello :subj')({subj: 'world'}) will create the string "hello world"

  • %{color ...} applies a colour to the text up until the matching }

    The colour can either be specified as a literal colour name or it can be resolved from an attribute of the object.

    sparkle('%{blue hello!}')({}) uses a literal colur and will create the string "hello!" in blue. And sparkle('%{:foo hello!}')({foo: 'green'}) uses foo from the object to create the string "hello!" in green.

    For a full list of available colours see the chalk page

  • %% insert a literal "%"

Trying to find a memory in a dark room

1.0.1

10 years ago

1.0.0

10 years ago

0.3.0

10 years ago

0.2.5

11 years ago

0.2.4

11 years ago

0.2.3

11 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.0

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago