Skip to content

Latest commit

 

History

History

clor

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

NPM Version Downloads Build Status

Install | Usage | Compare | Custom Styles

About

Clor is a tiny alternative to colors.js or Chalk.

Install

npm install clor

Usage

var $ = require("clor")

$.red("hey")
//→ \u001b[31mhey\u001b[0m

$.underline.bold.bgBlue.yellow("howdy!")
//→ \u001b[4m\u001b[1m\u001b[44m\u001b[33mhowdy!\u001b[0m

// You can add new lines with `line` or \n
$("1st line").line("2nd line").red.line("3rd line")
//→ 1st line\u001b[0m\n2nd line\u001b[0m\u001b[31m\n3rd line\u001b[0m

Compare

In Chalk you concatenate strings to compose your output:

console.log(
  chalk.red.bold("fee") + "\n" + chalk.inverse("fi") + "\n" + chalk.underline("fo")
)

In Clor you can concatenate and use any style property as a function

console.log(`${clor.red.bold("fee").line.inverse("fi").line.underline("fo")}`)
console.log(String(
  clor.red.bold("fee").line.inverse("fi").line.underline("fo")
))

You can get the string and styles using string

console.log(
  clor.red.bold("fee").line.inverse("fi").line.underline("fo").string
)

or use the log() wrapper to console.log()

clor.red.bold("fee").line.inverse("fi").line.underline("fo").log(/* args */)

You can also provide your own logger function

clor.red.bold("hi").log(function (args) {
  process.stdout.write("[" + timestamp() + "] " + this)
}/*, ... */)

Inside the logger wrapper this is bound to the string.

In just a few lines of code Clor packs a lot of interesting functionality.

Custom Styles

Create custom styles easily:

const Style = {
  head: $.bold.underline.green,
  file: $.blue.bold("\"%s\""),
  date: $.yellow("{{").gray(datefmt(new Date(), "HH:MM:ss")).yellow("}}")
}

console.log(Style.head("Starting app..."))
console.log("Loading file " + Style.file + " on " + Style.date, file)