ttlog
v1.2.2
Published
Terminal and browser console colorizer
Readme
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
importimportandrequireare competing and I haven't found a way to allow both from the same .js file
Further reading and interesting links
- Chrome console colors: For browser console
- ANSI escape colors: For terminal/cmd
- Tagged templates: ES2015
- Chalk: What inspired this
- Generate SRI hash code: Yay security
