Create pipeline, execute them, modify them, copy them ...
npm install pipipe
npm i pipipe
`
Import
`js
const createPipeline = require("pipipe");
// OR
import createPipeline from "pipipe";
`
Or in the browser
`html
`
How to use ?
$3
`ts
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
`
$3
Copy a pipeline to create a new one from it
`ts
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"]
);
`
$3
Execute asynchronously the pipeline
`ts
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");
`
$3
Insert a new pipe to a specific position
`ts
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
``