Skip to content

πŸ“š 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() for async, 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