Package Exports
- turbo-response
Readme
turbo-response
A TypeScript library providing a type-safe Result type (Success/Fail) for handling operation outcomes.
Installation
npm install turbo-responseFeatures
- Type-safe result handling with discriminated unions
- Comprehensive API for working with success and failure states
- Zero dependencies (except dev dependencies)
- Full TypeScript support with complete type inference
- Functional programming utilities for chaining and transforming results
Quick Start
import { success, fail, fold, TurboResponse } from 'turbo-response';
// Creating responses
const successResult = success({ id: '123', name: 'John' });
const failResult = fail(new Error('Not found'));
// Pattern matching
const message = fold(
response,
(data) => `Found user: ${data.name}`,
(error) => `Error: ${error.message}`
);
// Chaining operations
const result = await andThenAsync(
fetchUser('123'),
async (user) => fetchOrders(user.id)
);API
See the TypeScript definitions for complete API documentation.
License
MIT