1.0.1 β€’ Published 4 months ago

cano-ts v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

πŸ“š Full Documentation: Cano Ts Docs

πŸš€ Get Started

import { pipeSync } from "cano-ts";

const add = (x: number, y: number) => x + y;
const multiply = (x: number, factor: number) => x * factor;
const format = (x: number, prefix: string) => `${prefix} ${x}`;

const result = pipeSync(5)
  .next(add, 3) // 5 + 3 = 8
  .next(multiply, 2) // 8 * 2 = 16
  .next(format, "Result:")
  .result();

console.log(result); // "Result: 16"

πŸ“– About cano-ts

When working with transformations in JavaScript and TypeScript, we often end up with deeply nested function calls or complex .then() chains for asynchronous operations. Cano Ts solves this problem by introducing a fluent, pipeline-based API for function chaining.

/* BEFORE: Traditional Promise Chaining */
async function fetchUser(id: number, db: DbInstance): Promise<User> {
  return db.getUserById(id);
}

function updateRoleTo(user: User, newRole: string): User {
  return { ...user, role: newRole };
}

async function saveToDB(user: User, db: DbInstance): Promise<User> {
  await db.updateUser(user);
  return user;
}

// ❌ Callbacks required for passing extra arguments
fetchUser(1, DB)
  .then((user) => updateRoleTo(user, "admin"))
  .then((updatedUser) => saveToDB(updatedUser, DB))
  .then(console.log)
  .catch(console.error);

/* βœ… AFTER: Using cano-ts for a Clean Pipeline */
const result = await pipe(1)
  .next(fetchUser, DB)
  .next(updateRoleTo, "admin")
  .next(saveToDB, DB)
  .result();

console.log(result);

✨ 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

πŸ“¦ Installation

npm

npm install cano-ts

You can also use other package manager:

pnpm add cano-ts
# OR
yarn add cano-ts
1.0.1

4 months ago

1.0.0

4 months ago

0.3.0

4 months ago

0.2.2

5 months ago

0.2.1

5 months ago

0.2.0

5 months ago