Skip to content

Skhmt/ttlog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>

or via CDN:

 <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ttlog.min.js" integrity="sha384-PB71lhO4NaMS65f5FGJEpZnsS0S+Qk5EK4AoG9VzhS8ZNJQS6ndKlXHXRStzwuvq" crossorigin="anonymous"></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