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

@raini/pipes

v1.3.0

Published

Simple and reusable pipelines for function composition.

Downloads

13

Readme

@raini/pipes

Build Status codecov npm npm licence: MIT code style: prettier versioning: @priestine/semantics

@raini/pipes is a set of composable blocks called Pipelines. Pipelines are lazy and do not get invoked until they are forked with process method.

Pipelines are Monoids and can be concatenated with other Pipelines using p.concat which allows joining separate sets of composed functions.

Features

  • Composition of functions via pipe
  • Helper pipe methods, e.g. pipeTap or extendPipe
  • Implements Semigroup (holds associativity) with p.concat
  • Implements Monoid (holds right identity and left identity) with p.concat and P.empty
  • PromisePipeline allows abstracting from using Promises in composed functions - promisePipeline.process returns the only Promise to work with
  • Can be used both in Node and in browsers (transpiled to ES5)

Installation

npm i -S @raini/pipes

Usage

PromisePipeline

import { PromisePipeline } from "@raini/pipes"
import * as rl from "readline"

const addSpaceIfMissing = (q: string): string => (q.endsWith(" ") ? q : q.concat(" "))
const toObject = (q: string) => ({ q })
const createReadLine = () => ({ rl: rl.createInterface(process.stdin, process.stdout) })
const askQuestionAsync = ({ rl, q }) => new Promise((res) => rl.question(q, (a: string) => res(a)))
const applyGreenColor = (x: string) => `\x1b[32m${x}\x1b[0m`
const log = console.log
const exit = () => process.exit(0)

PromisePipeline.of(addSpaceIfMissing)
  .pipe(toObject)
  .pipeExtend(createReadLine) // Extend argument object with return value
  .pipe(askQuestionAsync)
  .pipe(applyGreenColor)
  .pipeTap(log) // Execute function on the argument and return the argument
  .process(() => "What is the answer to life, the universe and everything?")
  .then(exit)

PromisePipeline Helpers

  • pipeP is equivalent to PromisePipeline.empty().pipe
  • pipeExtendP is equivalent to PromisePipeline.empty().pipeExtend
  • pipeTapP is equivalent to PromisePipeline.empty().pipeTap

SyncPipeline

import { SyncPipeline } from "@raini/pipes"

const isOdd = (num: number) => num % 2 == 0
const negate = <T>(f: (x: T) => any) => (x: T) => !f(x)
const filterOutOddNumbers = (nums: number[]) => nums.filter(negate(isOdd))
const multiplyBy2 = (num: number) => num * 2
const multiplyItemsBy2 = (nums: number[]) => nums.map(multiplyBy2)
const log = console.log

const result = SyncPipeline.of(filterOutOddNumbers)
  .pipeTap(log) // [ 1, 3, 5 ]
  .pipe(multiplyItemsBy2)
  .process(() => [1, 2, 3, 4, 5])

log(result) // [ 2, 6, 10 ]

// A fun thing using pipeExtend (instead of pipe) for multiplying items by 2

const result2 = SyncPipeline.of(filterOutOddNumbers)
  .pipeTap(log) // [ 1, 3, 5 ]
  .pipeExtend(multiplyItemsBy2)
  .process(() => [1, 2, 3, 4, 5])

log(result2) // [ 1, 3, 5, 2, 6, 10 ]

SyncPipeline Helpers

  • pipe is equivalent to SyncPipeline.empty().pipe
  • pipeExtend is equivalent to SyncPipeline.empty().pipeExtend
  • pipeTap is equivalent to SyncPipeline.empty().pipeTap