npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

composition-logger

v4.0.0

Published

The most optimal way to visualize/debug functional compositions

Downloads

13

Readme

Composition Logger

composition-logger

Installation

To install ( recommended to save as a dev dependency )

npm install composition-logger --save -dev

What is this?

From all the resources that I have seen, the recommended way to debug functional compositions in JavaScript is to provide a function that produces a side effect such as logging to the console and continue to pass the data through the composition, such as ramdas tap function.

This is all well and good but it poses a few limitations such as:

  • Not beginner friendly. Beginners need to understand how functional composition works in order to debug or gain insight in how the data flows through a composition.

  • Debugging methods such as tap can be tedious to work with. Let's say your composition contains a bug, in order to view the data between each step of the compositon, you would be required to manually add the tap function between each step of the composition.

So how can we do better? By utilising console.group and this is exactly what composition-logger does.

composition-logger logs each step of your composition in an organised manner without interuptting the data flow of your composition, making it effortless to debug and giving you continuous insight into your functional compositions.

Usage

composition-logger exposes two functions:

  • pipeWithLogs: Compose from left to right see pipe

  • composeWithLogs: Compose from right to left see compose

Pipe

import { pipeWithLogs } from "composition-logger";

const divideByTwo = data => data / 2;

const sum = data => data.reduce((a, b) => a + b);

const addOne = data => data.map(item => item + 1);

const performCalculation = pipeWithLogs(addOne, sum, divideByTwo);

performCalculation([1, 4, 5, 6, 7]);

The above example will log the following to the browser:

Compose

import { composeWithLogs } from "composition-logger";

const divideByTwo = data => data / 2;

const sum = data => data.reduce((a, b) => a + b);

const addOne = data => data.map(item => item + 1);

const performCalculation = composeWithLogs(divideByTwo, sum, addOne);

performCalculation([1, 4, 5, 6, 7]);

The above example will log the following to the browser: