Posted at

js, node で手軽な pretty print メモ

More than 1 year has passed since last update.

深いネストもダンプする関数

> const pp = v => console.dir(v, { depth: null, colors: true})

> pp(obj)
[ { type: 'text', start: 0, end: 6, depth: 0, content: 'before' },
{ type: 'bracket',
start: 6,
end: 10,
depth: 0,
open: '(',
close: ')',
nodes:
[ { type: 'text', start: 7, end: 10, depth: 1, content: 'hit' } ] },
{ type: 'text', start: 11, end: 16, depth: 0, content: 'after' } ]