1.0.1 • Published 1 year ago
scriptools v1.0.1
📦 scriptools
A series of tools to use in JS/TS scripts. Feel free to suggest new features, improvements or report issues!
Installation
With NPM
npm install scriptoolsWith Bun
bun add scriptoolsWith Yarn
yarn add scriptoolsWith PNPM
pnpm add scriptoolsUsage
Runner
Run script
The runScript method handles exiting process while running a script. It works with both synchronous and asynchronous methods.
runScript(() => {
...
})Logger
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 immediatelylevelcan be"info","success","warn"or"error"logDetailsis 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 levelClear journal
Logger.clear(); // will empty log journalSet options on Logger
Logger.setOptions({ printOnLog: true }); // will print logs immediately
Logger.setOptions({ grouped: false }); // will print all logs grouped by levelTimer
The withTimer method wraps a function and logs the execution time.
const result = withTimer(myFunction)('arg1', 2); // will log `[myFunction] 12.34ms`