Skip to content

Commit

Permalink
feat: inspectObject and writeStdout repl helpers
Browse files Browse the repository at this point in the history
* process.stdout.write will stop working after the buffer limit is hit because the event loop is closed
* inspectObject is like console.dir, but tuned to terminal debugging and can be paired with writeStdout to print large objects
  • Loading branch information
iloveitaly committed Jul 30, 2023
1 parent 8f89e6c commit 02db4fb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/repl_globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ function toFile(obj, path) {
});
}

function writeStdout(str) {
require("fs").writeSync(1, str);
return void 0;
}
global.writeStdout = writeStdout

function inspectObject(obj) {
const util = require("node:util")
const inspectOutput = util.inspect(obj, {depth: null, colors: true, maxArrayLength: null, maxStringLength: null})
return inspectOutput
}
global.inspectObject = inspectObject

// copyToClipboard = (text) => {
function copyToClipboard(text) {
require("child_process").spawnSync("/usr/bin/pbcopy", [], {
Expand Down

0 comments on commit 02db4fb

Please sign in to comment.