@devlop/tap
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

Latest Stable Version License

tap

A JavaScript implementation of Laravel's tap helper.

Installing

using npm

npm install @devlop/tap

Usage

import tap from '@devlop/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 
let someObject = {
    team: 'Mora IK',
};

tap(someVariable, function () {
    // objects are passed by reference in JavaScript and can be modified
    someObject.name = 'Chicago Blackhawks';
});

console.log(someObject.name); // Chicago Blackhawks

Readme

Keywords

none

Package Sidebar

Install

npm i @devlop/tap

Weekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

3.9 kB

Total Files

5

Last publish

Collaborators

  • johanrosenson