Introduction

Installation

Get @cometloop/safe installed in your project.


Install

pnpm add @cometloop/safe

Or with npm:

npm install @cometloop/safe

Or with yarn:

yarn add @cometloop/safe

Import

// Core utilities
import { safe, createSafe } from '@cometloop/safe'

// Result constructors (for building SafeResult values manually)
import { ok, err } from '@cometloop/safe'

// Error class
import { TimeoutError } from '@cometloop/safe'

// Types
import type { SafeResult, SafeOk, SafeErr, SafeHooks, SafeAsyncHooks,
  RetryConfig, CreateSafeConfig, SafeInstance, NonFalsy } from '@cometloop/safe'

Key exports:

  • safe — core utility with sync, async, wrap, wrapAsync, all, and allSettled methods
  • createSafe — factory function for creating pre-configured safe instances
  • ok / err — construct SafeResult values manually
  • TimeoutError — error class thrown when an operation exceeds its timeout
  • TypesSafeResult, SafeOk, SafeErr, SafeHooks, SafeAsyncHooks, RetryConfig, CreateSafeConfig, SafeInstance, NonFalsy

Next steps

  • safe.wrap — wrap sync functions to return SafeResult
  • safe.wrapAsync — wrap async functions to return SafeResult
  • createSafe — factory for pre-configured instances
  • Types — full type reference
Previous
Getting started