Skip to content

lidqqq/pipe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@lidqqq/pipe

A type safety function to create a pipeline

Installation

npm i @lidqqq/pipe

Usage

TypeScript

// Async
import { pipe } from '@lidqqq/pipe';
import type { AsyncReturnType } from '@lidqqq/pipe';

async function plus2(n: number): Promise<number> {
  return n + 2;
}
async function n2s(n: AsyncReturnType<typeof plus2>): Promise<string> {
  return n.toString();
}

const main = pipe<typeof plus2, typeof n2s>(plus2, n2s);

(async () => {
  console.log((await main(2)) === '4'); // true
})();
// Synchronously
import { pipeSync } from '@lidqqq/pipe';

function plus2(a: number) {
  return a + 2;
}
function n2s(a: number): string {
  return a.toString();
}

const main = pipeSync<typeof plus2, typeof n2s>(plus2, n2s);
console.log(main(42) === '44'); // true

JavaScript

// ESM
import { pipe } from '@lidqqq/pipe';
// CJS
const { pipe } = require('@lidqqq/pipe');

Type safety

About

A type safety function to create a pipeline

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published