npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bitclaw/result

v1.1.0

Published

Unified Result type for explicit error handling

Readme

@bitclaw/result

Rust-inspired Result<T> type for explicit, type-safe error handling across service boundaries.

Features

  • Discriminated union Ok<T> and Err with .ok boolean discriminator
  • Serializable All fields are plain data (works across TanStack Start server/client boundary)
  • Composable map, chain (flatMap), combine for result pipelines
  • Zero dependencies Pure TypeScript, no runtime overhead

Installation

bun add @bitclaw/result

Quick Start

import { ok, err, type Result } from '@bitclaw/result'

async function getUser(id: string): Promise<Result<User>> {
  const user = await db.findUser(id)
  if (!user) return err('USER_NOT_FOUND', `User ${id} not found`)
  return ok(user)
}

const result = await getUser('123')
if (result.ok) {
  console.log(result.data.name) // typed as User
} else {
  console.error(result.code, result.message) // typed as Err
}

API

Types

type Ok<T> = { readonly ok: true; readonly data: T }

type Err = {
  readonly ok: false
  readonly code: string
  readonly message: string
  readonly cause?: ErrorCause
  readonly context?: Record<string, string | number | boolean>
}

type Result<T> = Ok<T> | Err

Constructors

ok(data)                          // Ok<T>
err(code, message)                // Err
err(code, message, cause)         // Err with serialized Error cause
err(code, message, cause, ctx)    // Err with additional context

Type Guards

isOk(result)   // result is Ok<T>
isErr(result)  // result is Err

Utilities

// Unwrap or throw
const user = unwrap(result) // throws if Err

// Unwrap with fallback
const user = unwrapOr(result, defaultUser)

// Transform the success value
const name = map(result, user => user.name) // Result<string>

// Chain result-returning operations (flatMap)
const profile = chain(result, user => getProfile(user.id)) // Result<Profile>

// Combine multiple results into a single result
const [user, org] = unwrap(combine([getUser(id), getOrg(orgId)]))

safeCatch

Wraps an async function to catch unhandled rejections with an optional error callback:

import { safeCatch } from '@bitclaw/result'

const getUser = safeCatch(
  async (id: string) => {
    const user = await db.findUser(id)
    if (!user) throw new Error('Not found')
    return user
  },
  (error) => console.error('getUser failed:', error)
)

Patterns

Service functions return Result, never throw

// Service layer returns Result<T>
const createServer = async (name: string): Promise<Result<Server>> => {
  if (await exists(name)) return err('DUPLICATE_NAME', 'Server name taken')
  const server = await db.insert(name)
  return ok(server)
}

// Consumer check .ok
const result = await createServer('web-1')
if (!result.ok) {
  setError(result.message)
  return
}
// result.data is typed as Server

Error codes are machine-readable

err('SERVER_NOT_FOUND', 'Server web-1 does not exist')
err('SSH_FAILED', `Connection to ${ip} timed out`, error)
err('PLAN_LIMIT_REACHED', 'Upgrade to add more servers', undefined, {
  current: 3,
  limit: 3
})

Testing

bun test

40 tests across 2 files.