A series of tools to use in JS/TS scripts. Feel free to suggest new features, improvements or report issues!
With NPM
npm install scriptools
With Bun
bun add scriptools
With Yarn
yarn add scriptools
With PNPM
pnpm add scriptools
Run script
The runScript
method handles exiting process while running a script. It works with both synchronous and asynchronous methods.
runScript(() => {
...
})
The Logger
singleton class handles logging with different levels and printing a log recap.
Add logs to journal
Logger.log(level, log, logDetails); // will push log to journal
Logger.log(level, log, logDetails, { print: true }); // will push log to journal as well as print it immediately
level
can be"info"
,"success"
,"warn"
or"error"
logDetails
is optional
Print logs
Logger.printAll(); // will print all logs in the order they were pushed
Logger.printAll({ grouped: true }); // will print all logs grouped by level
Clear journal
Logger.clear(); // will empty log journal
Set options on Logger
Logger.setOptions({ printOnLog: true }); // will print logs immediately
Logger.setOptions({ grouped: false }); // will print all logs grouped by level
The withTimer
method wraps a function and logs the execution time.
const result = withTimer(myFunction)('arg1', 2); // will log `[myFunction] 12.34ms`