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

flec-pipe

v1.0.2

Published

Brings support for piping to JavaScript, with full TypeScript integration. Use it to write clean, readable, and maintainable JavaScript.

Downloads

3

Readme

Flec Pipe

Brings support for piping to JavaScript, with full TypeScript integration. Use it to write clean, readable, and maintainable JavaScript.

Flec Pipe uses tartak under the hood, to help keep this library understandable and maintainable. Look at this library's source code to see how it works.

Installation

npm install flec-pipe
pnpm add flec-pipe
yarn add flec-pipe

Usage

Flec Pipe is easy to get started with, and works just like in other languages with built-in support for piping.

To use pipes in your code, import the pipe function from flec-pipe.

import { pipe } from "flec-pipe";

const result = pipe(-16, Math.abs, Math.sqrt);
// result = 4

The pipe function supports up to 40 functions (in addition to the initial value - thus 41 arguments in total).

Pipize

Flec Pipe also provides a function called pipize. This function allows you to mutate an exisiting function, with parameters, to make it suitable for piping. You can also specify the index of the parameter which the piped value should fill. Here's an example of how to use it.

import { pipe, pipize } from "flec-pipe";

const divide = (a: number, b: number) => a / b;

// prettier-ignore
const result = pipe(
  -16,
  Math.abs,
  pipize([divide, 0], 2)
);

// result = 16 / 2
// = 8

// prettier-ignore
const result2 = pipe(
  -16,
  Math.abs,
  pipize([divide, 1], 2)
);

// result2 = 2 / 16
// = 0.125

Notice the difference between the two results. The first argument of pipize is an array containing the function to be made pipable, and the index of the parameter which the piped value should fill.

In the first example, the piped value takes the place of the first parameter (see the 0 in the array). This causes the piped value, in this case 16, to be passed as the first parameter to the divide function.

In the second example, the piped value takes the place of the second parameter (see the 1 in the array). This causes the piped value to be passed as the second parameter to the divide function.

The following arguments of the pipize function represent the other parameters of the function to be made pipable, in order (excluding the parameter which the piped value should fill), and fully typed.

This can be useful for piping values to JavaScript functions which take multiple parameters. For example:

import { pipe, pipize } from "flec-pipe";

// prettier-ignore
const result = pipe(
  -16,
  Math.abs,
  Math.sqrt,
  pipize([Math.pow, 0], 3)
);

// trace:
// -16
// Math.abs -> 16
// Math.sqrt -> 4
// Math.pow(4, 3) -> 64

If we wanted to raise a given value, such as 3, to the power equal to the piped value, we can simply modify the pipize function call to say that the piped value should fill the second parameter of Math.pow.

import { pipe, pipize } from "flec-pipe";

// prettier-ignore
const result = pipe(
  -16,
  Math.abs,
  Math.sqrt,
  pipize([Math.pow, 1], 3)
);

// result = 3 ** 4
// = 81