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

pipem

v0.1.7

Published

Powerful TypeScript pipes with focus on size, performance and modularity.

Downloads

22

Readme

Powerful TypeScript pipes with focus on size, performance and modularity.


yarn add pipem

Pipeables

Pipeables are functions that you can put into a pipe (pipe itself is Pipeable).

We try to make the number of core pipeables as low as possible so it's easy to build your own abstractions on top them.

filter

Pipeable which runs either truePipeable or falsePipeable based on return value of predicate.

By default truePipeable returns Ok<$Input> and falsePipeable returns Err<Error<"FILTER", $Input>>.

filter((v: number) => !(v % 2));

filter(
  (v: number) => !(v % 2),
  () => ok("even"),
);

filter(
  (v: number) => !(v % 2),
  () => ok("even"),
  () => ok("odd"),
);

map

It maps value from $Input to $Output and returns it as Ok<$Output>.

// Pipeable<number, Result<string, Error>>
const doubleString = map((v: number) => `${v * 2}`);

wrap

Pipeable which wraps a sub-pipeable and overrides its Error.

It's recommended to use error function to create a custom Error.

// Pipeable<number, Result<number, Error<"CUSTOM", number>>>
wrap(
  map((v: number) => v * 2),
  error("CUSTOM"),
);

and

Pipeable which takes N number of pipeables and returns either Ok returned by the last pipeable or Err returned by any of the pipeables.

// Pipeable<number, Result<string, Error<"FILTER", number> | Error<"CUSTOM", number>>>
const customPipe = pipe(
  filter((v: number) => !(v % 2)),
  wrap(
    map((v) => `${v}`),
    error("CUSTOM"),
  ),
);

or

Pipeable which takes N number of pipeables and returns either Ok returned by any of the pipeables or Err if none of the pipeables returned Ok.

// Pipeable<number, Result<number, Error<"OR", number>>>
const customPipe = or(
  filter((v: number) => !(v % 2)),
  filter((v: number) => !(v % 3)),
);

pipe

Pipe is just and.


Utils

error

Creates error tuple based on value and potential sub-error.

It should mainly be used in wrap function as a second parameter.

All Pipeables should return error created with this function.

error("TEST", (value, error) => ({ valueType: typeof value, error }));

parse

Allows to run Pipeable with unknown input while infering everything else from the Pipeable as usual.

const isStringOrNumber = pipe(...);
// ResultErr<["OR", [], { }]>
const result1 = parse(isStringOrNumber, []);
// ResultOk<1>
const result2 = parse(isStringOrNumber, 1);

Limitations

  1. and/pipe and or can take only up to 32 Pipeables
  2. It's still not very clear how to do async Pipeables

Have a beautiful day 🍀.