Skip to content

Instantly share code, notes, and snippets.

@selimhex
Last active March 22, 2024 15:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selimhex/9dbc3caaae5121f577780371bae41af3 to your computer and use it in GitHub Desktop.
Save selimhex/9dbc3caaae5121f577780371bae41af3 to your computer and use it in GitHub Desktop.
debugging helper for weird js frameworks (#lwc😭)
prettyJson = (obj) => {
return JSON.stringify(obj, null, 2);
};
log(obj, name = "", color = null, table = false) {
if (table) {
console.log(`%c${name}`, `color: ${color || "unset"}`);
console.table(obj);
return;
}
console.log(`%c${name}`, `color: ${color || "unset"}`, this.prettyJson(obj));
}
/*
Example Usage:
this.log(result.setupTimeResult, 'setupTimeResult', "lime");
this.log(result.setupTimeResult.elements, "setupTimeResult.elements", "orange", true);
this.log(this.xAxis, "xAxis", "darkorange", false);
this.log(heightsArr, 'heightsArr', 'black; background: red');
this.log({ i: i, target: targetId, chosen: i === this.chosenBlob, t: e.type, dtl: e.detail }, "e", "lime");
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment