ylg
v1.1.1
Published
Simple and complete list of colors and styles for console.log()
Downloads
94
Maintainers
Readme
About
Simple and complete list of colors and styles for console.log()
log
let log = require('ylg')
log() // similar to console.log
log.test() // will output all available colors and styles in terminal for you to choose
log.black()
log.bgblack()
log.red('a') // ouput red color "a" in terminal
log.bgred()
log.green('a', 'b', ...) // supports multiple arguments
log.bggreen()
log.yellow('a', array, object) // supports array and object
log.bgyellow()
log.blue()
log.bgblue() // background blue color
log.magenta()
log.bgmagenta()
log.cyan()
log.bgcyan()
log.white()
log.bgwhite()
log.dark()
log.bgdark()
// shorthand
log.r() // shorthand for log.red()
log.bgr()
log.g()
log.bgg()
log.y()
log.bgy()
log.b()
log.bgb()
log.m()
log.bgm()
log.c()
log.bgc()
log.w()
log.bgw()
// styles
log.reset()
log.bold() // apply bold style
log.dim()
log.italize()
log.underline()
log.blink()
log.none()
log.reverse()
log.hidden()
// shorthands
log.R()
log.B() // shorthand for bold style
log.D()
log.i()
log.u()
log.rv()
log.h()
log.inline() // doesn't break into next line
log.lg() // shorthand for inline
// extra
log.error()
log.err()
log.er()
log.E()
log.e()
log.W()
log.warn()
log.warning()
// special
log.out() // same as process.stdout.write()
log.depth() // similar to console.log(util.inspect(1, null)), default depth is null (fully expand), default console.log only has depth 1 ( { k: { k2: [Object] } } )
log.depth0() // depth: 0
log.depth[0-9]() // depth from 0-9
log.d() // shorthand for log.depth()
log.d0()
log.d[0-9]()
lg (inline of log)
let {lg} = require('ylg')
lg.test() // output all available inline colors and styles in terminal
lg.red('a') // ouput red color "a" inline (no line break) in terminal
lg.bgred()
lg.green()
... // all methods same as log above
custom combo
log('a', ['red','bold']) // combine bold and red together
log.red('a', ['bold']) // alternative way
lg.bold('a', ['red']) // inline + bold + red
All elements in the last array must fully match the color and styles, else will show the array instead.
additional
let {err, warn} = require('ylg')
err('a') // log error, shorthand for log.bgred (background red)
warn('a') // warning, shorthand for log.yellow
debug('a) // same as log.cyan
/// shorthands
// e = E = er = err = error = log.e = log.E = log.er = log.err = log.error = log.bgr;
// W = warn = warning = log.W = log.warn = log.warning = log.y;
/// inline
// lg.e = lg.E = lg.er = lg.err = lg.error = lg.bgr;
// lg.W = lg.warn = lg.warning = lg.y;
/// special
let {out, inspect} = require('ylg')
out // same as process.stdout.write()
inspect(v, depth=null) // same as util.inspect() // can use log.inspect() as well
// shorthand
let {insp, isp, ip} = require('ylg')
insp() // same as inspect; can use log.insp() as well
isp() // same
ip() // same
// to color code
let { toc } = require('ylg') // alt: log.toc
toc.red('AA') // \x1b[31mAA\x1b0m // to insert inside log()
toc.red() // \x1b[31m // to insert inside log() (open)
toc.R() // \x1b[0m // reset all colors and styles (close)
... // has all color and style methods as log() above
global
require('ylg').gb()
log(1)
log.r(1)
Available globally: log, lg, out, inspect, W, warn, warning, E, err, error, toc.
require('ylg').gb.main()
log()
lg()
require('ylg').gb.abbr() // abreviation, shorthand
out() // shorthand for process.stdout.write()
inspect(ob[, depth=null]) // shorthand for console.log(util.inspect(ob, 1, depth, 1))
insp() // abbr for inspect
require('ylg').gb.warn()
W()
warn()
warning()
require('ylg').gb.err()
E()
er()
err()
error()
// you can also require separately as normal
const {warn, err} = require('ylg')
flaw
Careful when log last variable as array, if elements in array all match the colors and sytles AND there are more than 1 arguments provided, the array will be used to style and will NOT be output.
let arr=['red','bold']
log(v, arr) // arr will be used to style and will NOT be output
log(v, arr, '') // workaround: just pass in any or empty string as the last value
etc
ylg is just shorthand for Y log (Y is nickname, and lg (log) is console.log).