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

@sigurjs/core

v0.1.1

Published

Result / ResultAsync — errors as values for JavaScript and TypeScript

Readme

@sigurjs/core

Errors as values for JavaScript and TypeScript. Part of sigur

A Result is for extracting the value, extracting the error, or returning upstream — no throw / try / catch required at the call site.

Works anywhere JS runs (Node, Bun, Deno, browsers, React Native). Result-returning globals (JSON, fetch, URL, …) live in [@sigurjs/node](https://github.com/aifrim/sigur/tree/main/packages/node).

Install

pnpm add @sigurjs/core

Requirements: Node >=24 (or any modern JS runtime that can import ESM).

Quick start

Wrap a third-party SDK (or any throwing / rejecting API) with sure:

import { sure } from "@sigurjs/core";
import { getItem } from "some-api-sdk";

const safeGetItem = sure(getItem);
const result = await safeGetItem("1"); // Result — throws / rejects become Err

if (result.isOkay()) {
  console.log(result.value); // still trusts the SDK's type
} else {
  console.error(result.error);
}

sure is the bridge when you only have .d.ts + JS and cannot see how the package fails. Success typing is still the SDK's claim — validate the shape yourself if you need a domain type.

Construct your own Result

import { Err, Ok, type Result } from "@sigurjs/core";

function parseId(raw: string): Result<number, Error> {
  const n = Number(raw);

  if (Number.isFinite(n)) {
    return Ok(n);
  }

  return Err(`invalid id: ${raw}`);
}

const id = parseId("42");

if (id.isOkay()) {
  console.log(id.value);
} else {
  console.error(id.error);
}

Void / unit success

When success has no payload (e.g. ack / “done”), use Result<void, Error> and Ok() — no Ok(undefined) or cast needed. Runtime value is still undefined.

function publish(): Result<void, Error> {
  // …
  return Ok();
}

sure on a void-returning (or Promise<void>) function yields Result<void, Error> / ResultAsync<void, Error> the same way — success value is undefined.

Use Ok(value) when there is a real success payload.

Async

Sync functions return Result. Async / Promise-returning functions wrapped with sure return ResultAsync — await to get a Result. You can also wrap an existing Promise:

import { ResultAsync } from "@sigurjs/core";

const result = await ResultAsync.fromPromise(fetch("https://example.com"));

Call sites

At every call site, do one of:

  1. Extract the value — isOkay() then .value
  2. Extract the error — isErr() then .error
  3. Return upstream — return result

Prefer positive checks so TypeScript narrows to OkResult / ErrResult. Also available: instanceof OkResult / ErrResult / Result.

sure and finally

import { sure } from "@sigurjs/core";

const doWork = sure(
  () => risky(),
  {
    finally: () => cleanup(),
  },
);

finally runs after a failed attempt. If both the operation and cleanup throw, Sigur returns an AggregateError so cleanup cannot swallow the original failure.

API

| Export | Purpose | | ----------------------------------------- | --------------------------------------------------------------------- | | Result / OkResult / ErrResult | Sync success or failure as data | | Ok() / Ok(value) / Err(...) | Construct a Result; Ok() is void success; Err("msg", { cause }) | | sure(fn, options?) | Unsure (throwing / rejecting) function → Result-returning function | | toError(cause) | Normalize any thrown / rejected value to Error | | ResultAsync / ResultAsync.fromPromise | Async wrapper; await → Result |

Thrown / rejected causes map with toError → Result<T, Error>. Reshape errors by extracting and return Err("…", { cause }) (or Err(error)).