Socket
Book a DemoInstallSign in
Socket

@fsad-labs/toolly

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fsad-labs/toolly

Tools functions

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

toolly

A lightweight wrappers around funtions or promises that simplifies:

  • Retry funtions
  • Concat or joins functions

Install

npm i @fsad-labs/toolly

Usage

API Reference

# retryFn

Description

Retry executing your functions as many times as you want before displaying the error to the user.

  await retryFn({
    fn: function1, // your function
    retry: 3,
    delay: 1000, // milliseconds
    fnError: (err: any) => { // CUSTOM MANAGE }
  })
ParameterTypeDescription
fnfunctionRequired. Your function that will be wrapped to be executes
retrynumberoptional. number of attempts by default 3 times
delaynumberoptional. ms to wait before continue with the next execution by default 500 ms
fnErrorfunctionoptional. async function to catch the error and customize it. Must return a value

Result when retryFn is OK

Result (object)TypeDescription
successbooleanstatus of the execution True
resultanyresult of your fn

Result when retryFn throw an Error

Result (object)TypeDescription
successbooleanstatus of the execution False
messagestringmessage of the error Customizable
codestringcode error "RETRY_ERROR" Customizable
originalErroranyoriginal error caught

# joinFns

Description

Join your functions in a container, share args and control the execution.


    const fn1 = async (shared) => { //TODO }
    const fn2 = async (shared) => { //TODO }

    await joinFns({
        fns: [fn1, fn2, ...],
        args_shared: {
            arsg1: "A",
            arsg2: "B",
            arsg3: "C",
        },
    })
ParameterTypeDescription
fnsfunctionsRequired. Array of functions that will be wrapped to be executes
args_sharednumberoptional. args to be passed into all functions
Result (object)SubPropTypeDescription
executefunctionexecute function
statusisCompletedbooleanstatus of the container, true when all functions were executed
isErrorbooleanstatus error, true if joinFns throw error
messagestringoriginal message error caught
fnsStatusanystatus of the all functions

Usage/Examples

# retryFn

const { retryFn } = require('@fsad-labs/toolly');

const fn1 = async () => {
    //TODO
    throw { code: "NETWORK", message: "cancel" }
}

const fn2 = async () => {
    try {
        //TODO
        throw new Error("Something was wrong in test2");
    }
    catch (e) {
        throw e;
    }
}

const fn3 = () => async () => {
    //TODO
    throw new Error("Something was wrong in test3");
}

const result = await retryFn({
        fn: fn1,
        retry: 4, // four times
        delay: 1000, // 1 second
        fnError: async (e) => {
            // "Error callback executed";
            await new Promise(resolve => setTimeout(resolve, 1000));
            return { customProp: true };
        }
    });

# joinFns


const { joinFns } = require('@fsad-labs/toolly');

const fn1 = async (arg_shared) => { 
    //TODO
};

const fn2 = async (arg_shared) => {
    //TODO
    throw Error("Don't start middleware 3");
};

const fn3 = async (arg_shared) => {
    //TODO
    throw { code:"01" message: "Don't start middleware 3" } ;
};

const run = joinFns({
        fns: [fn1, fn2, fn3],
        args_shared: {
            arsg1: "A",
            arsg2: "B",
            arsg3: "C",
        }
    });

// EXECUTE
run.execute();

// CHECK
run.status;

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

📄 License

This project is licensed under the MIT License © fullstack-ad

Keywords

tool

FAQs

Package last updated on 08 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts