Goodies

Introduction

The @supercharge/goodies package provides a handful of useful helper functions for Node.js and JavaScript, like an async tap function.

Installation

The @supercharge/goodies package lives independently from the Supercharge framework. Using it in your application requires you to install it as a project dependency:

npm i @supercharge/goodies

You can use this package with every project even if it’s not build on Supercharge. Enjoy!

Using Goodie Methods

The @supercharge/goodies package exports a handful methods that you can reach for when using require():

const { tap } = require('@supercharge/goodies')

// or

const Goodies = require('@supercharge/goodies')

Goodies.tap(…)

Available Methods

Here’s a list of available methods in the collections package:

tap

Methods

tap

The tap method invokes a callback passing the given value as an argument to the callback and returns the value. It accepts two arguments, a value and a callback:

tap has the following signature:

async tap(value, async callback)

Using tap allows you to run a side-effect on the value and return the value:

const { tap } = require('@supercharge/goodies')

const user = await tap(await User.findBy({ email }), async (user) => {
    await user.subscribeToNewsletter()
})

// user = the found user for `email`