term-css

1.0.0 • Public • Published

term-css

Terminal CSS styling using node-css.

Installation

$ npm install term-css

Example

js:

 
var css = require('term-css')
  , fs = require('fs')
  , style = fs.readFileSync('pet.css', 'utf8');
 
var tobi = {
  name: 'tobi',
  species: 'ferret',
  age: 2
};
 
var loki = {
  name: 'loki',
  species: 'ferret',
  age: 1
};
 
var fn = css.compile('  {name} is a {species}, he is {age} years old', style);
 
console.log();
console.log(fn(tobi));
console.log(fn(loki));
console.log();
 

css:

name {
  color: cyan;
  font-weight: bold;
}
 
species {
  color: white;
  font-weight: bold;
  background: black;
}
 
age {
  color: red;
  text-decoration: underline;
}

output:

CSS properties

The following CSS properties / values are understood:

  • text-decoration: <underline|inverse>
  • font-weight: <bold>
  • font-style: <italic>
  • color: <grey|gray|black|blue|cyan|green|red|magenta|yellow>
  • background: <grey|gray|black|blue|cyan|green|red|magenta|yellow>

Substitution

term-css substitutes tokens with properties in the object passed, for example {name} will access { name: "tobi" }, whereas {labels.visits} will access { labels: { visits: 'Visits' } }.

For styling purposes you may also assign a classname, for example instead of styling "labels.visits", "labels.uptime" separately, you may use {label labels.visits} and {label labels.uptime}.

Omitting styling

To output a plain string but use the same format, simply omit the css string from the .compile(fmt, style) call.

License

(The MIT License)

Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

none

Package Sidebar

Install

npm i term-css

Weekly Downloads

605

Version

1.0.0

License

none

Last publish

Collaborators

  • tjholowaychuk