Logging Aliases for Javascript

Created: 02 November 2021

Updated: 03 September 2023

I often find myself writing a function to JSON.stringify some data to log in either a pretty or flat structure

It’s just more of a convenience method, and it’s pretty much the same as doing console.log(JSON.stringify(data)) and looks like this:

const _ = (data: any, pretty: boolean = false) => {
  return console.log(JSON.stringify(data, null, pretty ? 2 : 0))
}

And then, when I need to log something:

_(myData)

Or, if I want to pretty print the JSON

_(myData, true)