Gathering detailed insights and metrics for @fuzzy-street/results
Gathering detailed insights and metrics for @fuzzy-street/results
Gathering detailed insights and metrics for @fuzzy-street/results
Gathering detailed insights and metrics for @fuzzy-street/results
🤓 A lightweight `Result<T,E>` Library which provides a set of robust and type-safe functions to represent operations that can either **succeed** or **fail** without relying on exception handling 🤓
npm install @fuzzy-street/results
Typescript
Module System
Node Version
NPM Version
TypeScript (97.86%)
HTML (1.58%)
Shell (0.43%)
JavaScript (0.12%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
10 Stars
35 Commits
5 Branches
1 Contributors
Updated on Jun 12, 2025
Latest Version
0.3.3
Package Id
@fuzzy-street/results@0.3.3
Unpacked Size
85.56 kB
Size
19.65 kB
File Count
6
NPM Version
10.9.2
Node Version
22.16.0
Published on
Jun 12, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A highly optimized, fully type-safe, dependency-free utility for representing operations that can either succeed or fail.
Complete with:
Its a fuzzy approach where by having better results we can craft more reliable code that doesn't rely on try/catch
and exceptions for control flow.
This library aims to provide an elegant solution for handling operations that can succeed or fail in TypeScript applications. It addresses the common problems with traditional exception-based error handling while maintaining full type safety and composability.
Unlike traditional error handling with exceptions, this library seeks to enable us with the following:
🧙♂️ Type-Safe Results - Experience bulletproof type safety with full TypeScript inference and precise error typing. No more "any" type nightmares or runtime surprises.
🔄 Powerful Functional Transformations - Transform your data with elegant, chainable operations like map
, chain
, and pipe
. Build complex processing flows with minimal code.
👪 Painless Composition - Compose operations that might fail without deeply nested try/catch blocks. Create clean, readable code that's easy to maintain and extend.
🧬 First-Class Async Support - Handle async operations with the same elegant API. Convert Promises to Results, chain async operations, and process multiple async results in parallel.
⚠️ Explicit Error Handling - Say goodbye to forgotten try/catch blocks and silent failures. Every potential error becomes a value you can inspect, transform, and handle with precision.
😇 Control Your Own Destiny - Decide exactly when and how to extract values from results with smart unwrapping operations that prevent runtime crashes.
🚂 Railway-Oriented Programming - Implement the powerful railway pattern with built-in short-circuiting. Keep your happy path clean while ensuring errors naturally flow to error handlers.
⚡ Blazing Fast Performance - Meticulously optimized for speed and minimal memory usage. We've benchmarked extensively to ensure near-zero overhead compared to traditional error handling.
🤑 Rich Combinators - Combine multiple results with sophisticated utilities like asyncAll
and sophisticated error aggregation. No more manual result merging.
💻 Developer Experience First - Designed for humans with clear naming, consistent behavior, and detailed documentation with practical examples for every function.
🆓 Zero Dependencies - Not a single external dependency. Just pure, optimized TypeScript that won't bloat your bundle or introduce security vulnerabilities.
💚 Universal Compatibility - Works anywhere JavaScript runs: browsers, Node.js, Deno, Bun, web workers, or serverless functions. One API to rule them all.
🪖 Battle-Tested - Comprehensive guides with real-world examples for every function. Learn through practical code, not just abstract theory.
1# Using npm 2npm install @fuzzy-street/results 3 4# Using yarn 5yarn add @fuzzy-street/results 6 7# Using pnpm 8pnpm add @fuzzy-street/results
Result Pattern is built around a simple concept: a function that can either succeed or fail returns a Result<T, E>
type, which is either:
{ status: "success", data: T }
for successful operations{ status: "error", error: E }
for failed operationsThis allows you to:
1import { success, error, isSuccess, isError, match } from '@fuzzy-street/results'; 2 3// Creating success results 4const successResult = success(42); 5// { status: "success", data: 42 } 6 7// Creating error results 8const errorResult = error(new Error('Something went wrong')); 9// { status: "error", error: Error("Something went wrong") } 10 11// Type checking 12if (isSuccess(successResult)) { 13 console.log(successResult.data); // 42 14} 15 16if (isError(errorResult)) { 17 console.log(errorResult.error.message); // "Something went wrong" 18} 19 20// Pattern matching 21const message = match(successResult, { 22 success: (value) => `Success: ${value}`, 23 error: (err) => `Error: ${err.message}` 24}); 25// "Success: 42"
The library is organized into three main categories:
These form the foundation of the Result pattern:
success
: Creates a successful resulterror
: Creates an error resultisSuccess
: Type guard for successful resultsisError
: Type guard for error resultsisResult
: Type guard for any resultmatch
: Pattern matching for resultsunwrap
: Extracts value or throws errorunwrapOr
: Extracts value with fallbackThese help transform and process results:
map
: Transforms success valuesmapError
: Transforms error valueschain
: Chains operations that might failtap
: Performs side effects on any resulttapSuccess
: Performs side effects on success resultstapError
: Performs side effects on error resultspipe
: Creates transformation pipelinescreateErrorBoundary
: Creates error-handling boundariesThese handle asynchronous operations:
fromPromise
: Converts a Promise to a ResultfromAsync
: Wraps an async function to return a ResultasyncMap
: Maps a Result value asynchronouslyasyncMapError
: Maps a Result error asynchronouslyasyncChain
: Chains async operations that return ResultsasyncPipe
: Creates async transformation pipelinesasyncAll
: Combines multiple async ResultswithFinally
: Executes cleanup after async operationscreateAsyncErrorBoundary
: Creates async error-handling boundariesEach function has detailed documentation and examples in the linked markdown files. We highly recommend exploring these docs to understand the full capabilities of each utility.
1import { pipe, success, error } from '@fuzzy-street/results'; 2 3function validateInput(input: string) { 4 return input ? success(input) : error(new Error('Input required')); 5} 6 7function processInput(input: string) { 8 return input.length >= 3 9 ? success(input.toUpperCase()) 10 : error(new Error('Input too short')); 11} 12 13function formatOutput(input: string) { 14 return success(`Processed: ${input}`); 15} 16 17// Create a processing pipeline 18const result = pipe( 19 'hello', // Input value 20 validateInput, // Validate (short-circuit if invalid) 21 processInput, // Process (short-circuit if fails) 22 formatOutput // Format output 23); 24 25// result: { status: "success", data: "Processed: HELLO" }
1import { asyncChain, fromPromise } from '@fuzzy-street/results'; 2 3async function fetchUser(id: string) { 4 return fromPromise( 5 fetch(`https://api.example.com/users/${id}`) 6 .then(response => { 7 if (!response.ok) throw new Error(`HTTP error ${response.status}`); 8 return response.json(); 9 }) 10 ); 11} 12 13async function fetchUserPosts(user) { 14 return fromPromise( 15 fetch(`https://api.example.com/users/${user.id}/posts`) 16 .then(response => { 17 if (!response.ok) throw new Error(`HTTP error ${response.status}`); 18 return response.json(); 19 }) 20 ); 21} 22 23// Chain async operations 24async function getUserWithPosts(userId: string) { 25 const userResult = await fetchUser(userId); 26 return await asyncChain(userResult, fetchUserPosts); 27}
1import { match, success, error } from '@fuzzy-street/results'; 2 3function divideNumbers(a: number, b: number) { 4 return b !== 0 5 ? success(a / b) 6 : error(new Error('Division by zero')); 7} 8 9const result = divideNumbers(10, 0); 10 11// Pattern matching for elegant error handling 12const message = match(result, { 13 success: (value) => `Result: ${value}`, 14 error: (err) => `Error: ${err.message}` 15}); 16 17// message: "Error: Division by zero"
The Result pattern has been carefully optimized to minimize overhead:
According to our benchmarks:
This library is built with TypeScript first in mind:
This repository comes with a comprehensive set of examples to demonstrate the usage of each function. To run them locally:
Clone the repository:
1git clone https://github.com/fuzzy-st/results.git 2cd results
Install dependencies:
1pnpm install
Run a specific example:
1pnpm tsx src/examples/core/success.ts 2pnpm tsx src/examples/transformers/pipe.ts 3pnpm tsx src/examples/async/asyncChain.ts
Each example file contains multiple usage patterns. To try a specific example, uncomment the corresponding run...()
function at the bottom of the file before running it.
For example, in src/examples/core/success.ts
:
1// Uncomment any of these to run the example 2// runBasicExample(); 3// runValidationExample(); 4runComplexExample(); // This one will execute
We encourage you to explore these examples to get a feel for how the library works in practice. Each example corresponds to the documentation for its respective function.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
No vulnerabilities found.
No security vulnerabilities found.