π Introduction β
Just want to try it out? Skip to the π Get Started .
π Overview β
Cano TS is a lightweight and type-safe utility for function composition in TypeScript, inspired by Elixirβs pipe operator (|>)
. It allows you to build fluent, readable, and maintainable pipelines for both synchronous and asynchronous operations.
typescript
import { pipeSync } from "cano-ts";
const applyDiscount =
(price: number, discount: number) => price - discount;
const applyTax =
(price: number, taxRate: number) => price + price * taxRate;
const formatPrice =
(price: number, currency: string) => `${currency} ${price.toFixed(2)}`;
const finalPrice = pipeSync(100)
.next(applyDiscount, 10) // 100 - 10 = 90
.next(applyTax, 0.2) // 90 + 20% tax = 108
.next(formatPrice, "$") // Format as "$ 108.00"
.result();
console.log(finalPrice); // "$ 108.00"
β¨ Features β
- β
Fluent API β Chain functions using
.next()
- β
Supports async & sync pipelines β
pipe()
forasync
,pipeSync()
for sync - β Error Handling β Configurable PipeError for better debugging
- β
Function History Tracking β Debug easily with
.log()
- β Fully Type-Safe β Leverages TypeScript generics for strong typings