JSPM

turbo-response

0.1.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 6
    • Score
      100M100P100Q49203F
    • License MIT

    Result type (Success/Fail) for operation outcomes in TypeScript/React

    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-response

    Features

    • 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