ttlog

1.2.2 • Public • Published

ttlog (tagged template log)

Terminal and browser console colorizer

Ttlog console.log()s using tagged template syntax similar to chalk.js, but works in both the browser and terminal (Windows 10, unix/linux, and macOS). Ttlog also returns the plain-text string without colorization information so you can output it to a file or whatever.

Usage in node.js or webpack

const log = require('ttlog');
log`hello {white.bgBlack darkness} {underline my} {green old} {underline.blue.bgYellow friend}`;

Both outputting and writing a log in node.js

const fs = require('fs');
const log = require('ttlog');
fs.appendFile('mylog.log', log`{blue ${Date.now()}}: {green Bad things happened!!}`);

Usage in the browser

Put this in your html (head or body) if you host the file yourself:

<script src="ttlog.min.js"></script>

Use it like this in a .js or <script> tag:

log`hello {white.bgBlack darkness} {underline my} {green old} {underline.blue.bgYellow friend}`;

API

  • red
  • green
  • blue
  • cyan
  • magenta
  • yellow
  • black
  • white
  • bgRed
  • bgGreen
  • bgBlue
  • bgCyan
  • bgMagenta
  • bgYellow
  • bgBlack
  • bgWhite
  • underline

Todo

  • Support console.info/warn/etc?
    • Problem is node doesn't support those, so it won't be consistent behavior
  • Support import
    • import and require are competing and I haven't found a way to allow both from the same .js file

Further reading and interesting links

Package Sidebar

Install

npm i ttlog

Weekly Downloads

0

Version

1.2.2

License

MIT

Unpacked Size

11.3 kB

Total Files

7

Last publish

Collaborators

  • skhmt