Skip to content

Create pipeline, execute them, modify them, copy them ...

License

Notifications You must be signed in to change notification settings

yoannchb-pro/pipipe

Repository files navigation

pipipe

Create pipeline, execute them, modify them, copy them ...

Update

Found a bug ?

  • Tell it in my github issues dont be afraid :)

Installation

npm i pipipe

Import

const createPipeline = require("pipipe");
// OR
import createPipeline from "pipipe";

Or in the browser

<script src="https://unpkg.com/pipipe@1.0.0/dist/index.js"></script>

How to use ?

Simple example

const reverseStrPipeline = createPipe()
  .pipe((str: string) => str.split(""))
  .pipe((arr: string[]) => arr.reverse())
  .pipe((arr: string[]) => arr.join(""));

const result = reverseStrPipeline.execute("hello world");

console.log(result); //dlrow olleh

Copy

Copy a pipeline to create a new one from it

const lowerCasePipeline = createPipe().pipe((str: string) => str.toLowerCase());
const splitPipepline = lowerCasePipeline
  .copy()
  .pipe((str: string) => str.split(""));

console.log(
  splitPipepline.execute("HI"), // "hi"
  lowerCasePipeline.execute("HI") // ["h", "i"]
);

Async

Execute asynchronously the pipeline

type UserList = { id: string; name: string; token: string }[];

const getUserTokenPipeline = createPipe()
  .pipe(async (id: string) => {
    const req = await fetch(`/userById/${id}`);
    return await req.json();
  })
  .pipe((result: UserList) => result[0]?.token)
  .catch(handleErr);

const token = await getUserTokenPipeline.executeAsync("123456789");

pipeInsert

Insert a new pipe to a specific position

const reverseStrPipeline = createPipe()
  .pipe((str: string) => str.split(""))
  .pipe((arr: string[]) => arr.join(""))
  .pipeInsert((arr: string[]) => arr.reverse(), 1);

const result = reverseStrPipeline.execute("hello world");

console.log(result); //dlrow olleh

pop, shift, splice

Same as the pop, shift, splice array method to remove pipe(s) from the pipeline

About

Create pipeline, execute them, modify them, copy them ...

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published