Skip to content

Toolbox library for running scripts in Node environment.

Notifications You must be signed in to change notification settings

hugomartinet/scriptools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📦 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 scriptools

With Bun

bun add scriptools

With Yarn

yarn add scriptools

With PNPM

pnpm add scriptools

Usage

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 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

Timer

The withTimer method wraps a function and logs the execution time.

const result = withTimer(myFunction)('arg1', 2); // will log `[myFunction] 12.34ms`

About

Toolbox library for running scripts in Node environment.

Resources

Stars

Watchers

Forks

Packages

No packages published