1.0.1 • Published 4 years ago

@devlop-ab/tap v1.0.1

Weekly downloads
44
License
MIT
Repository
github
Last release
4 years ago

tap

A JavaScript implementation of Laravel's tap helper.

Installing

using npm

npm install @devlop-ab/tap

Usage

import tap from '@devlop-ab/tap';

// or
const tap = require('@devlop-ab/tap');

tap accepts two arguments, a value and a callback. The callback will get the value as the first argument, any return value of the callback will be ignored and the original value will be returned.

Examples

let someVariable = true;

let anotherValue = tap(someVariable, function () {
    console.log(someVariable); // true
});

console.log(anotherValue); // true
let someVariable = true;

let anotherValue = tap(someVariable, function () {
    console.log(someVariable); // true
    
    // re-assignments have no effect
    someVariable = false;
    
    // return values are ignored
    return false;
});

console.log(anotherValue); // still true