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.
const log = require('ttlog');
log`hello {white.bgBlack darkness} {underline my} {green old} {underline.blue.bgYellow friend}`;
const fs = require('fs');
const log = require('ttlog');
fs.appendFile('mylog.log', log`{blue ${Date.now()}}: {green Bad things happened!!}`);
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}`;
- red
- green
- blue
- cyan
- magenta
- yellow
- black
- white
- bgRed
- bgGreen
- bgBlue
- bgCyan
- bgMagenta
- bgYellow
- bgBlack
- bgWhite
- underline
- Support console.info/warn/etc?
- Problem is node doesn't support those, so it won't be consistent behavior
- Support
import
-
import
andrequire
are competing and I haven't found a way to allow both from the same .js file
-
- 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