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

@billdaddy/safekit

v0.1.0

Published

Zero-dependency Try monad for TypeScript. Capture exceptions as values — Try.of(() => risky()).map().recover().getOrElse(). Port of Java Vavr Try / Scala util.Try.

Readme

safekit

All Contributors

Zero-dependency Try monad for TypeScript. Execute risky code and handle exceptions as values, not control flow.

npm License: MIT

Port of Java Vavr Try / Scala scala.util.Try. The existing try-monad npm package has been abandoned since 2017 (2 downloads/week).

Install

npm install @billdaddy/safekit

The problem Try solves

Result<T,E> (neverthrow, resultkit) wraps already-computed values where you know the error type ahead of time. Try<T> executes a computation and captures any thrown exception automatically — no need to know what might throw:

// Result: you write the error path manually
const result: Result<User, ApiError> = ok(user);

// Try: exception is captured automatically
const t = Try.of(() => JSON.parse(rawJson));  // SyntaxError captured if thrown

Quick start

import { Try } from "@billdaddy/safekit";

const result = Try.of(() => JSON.parse(rawInput))
  .map(obj => obj.name as string)   // skipped if parse failed
  .filter(name => name.length > 0)  // skipped if map failed
  .recover(e => "anonymous")        // handles any prior failure
  .get();                           // never throws — recover caught everything

API

Try.of(fn)

Execute a function and capture the result or exception:

const t1 = Try.of(() => parseInt("42", 10));   // Success(42)
const t2 = Try.of(() => JSON.parse("bad"));     // Failure(SyntaxError)
const t3 = Try.of(() => { throw "string err"; }); // Failure("string err")

Try.ofAsync(fn) — async computations

const t = await Try.ofAsync(async () => fetch("/api/users").then(r => r.json()));
// Never rejects — always resolves to Success or Failure

if (t.isSuccess()) {
  console.log(t.get()); // the parsed JSON
} else {
  console.error(t.getCause()); // the fetch/parse error
}

Transformations (fluent chaining)

Try.of(() => "  hello  ")
  .map(s => s.trim())             // Success("hello")
  .map(s => s.toUpperCase())      // Success("HELLO")
  .filter(s => s.length > 3)      // Success("HELLO") — passes
  .flatMap(s => Try.of(() => s))  // Success("HELLO")
  .get()                          // "HELLO"

All transformations on a Failure are no-ops — the original failure propagates:

Try.of(() => { throw new Error("fail"); })
  .map(x => x)         // no-op
  .filter(() => true)  // no-op
  .getOrElse("default") // "default"

Recovery

// recover — provide a fallback value
const t = Try.of(() => riskyParse())
  .recover(e => fallbackValue);

// recoverWith — provide a fallback Try computation
const t = Try.of(() => fetchPrimary())
  .recoverWith(e => Try.of(() => fetchBackup()));

Extracting values

const t = Try.of(() => compute());

t.get()                              // value or rethrows
t.getOrElse(defaultValue)            // value or default
t.getOrElseGet(cause => handleErr()) // value or call fn(cause)
t.getOrElseThrow(e => new MyErr(e))  // value or throw custom error
t.toNullable()                       // value or null
t.toArray()                          // [value] or []
t.getCause()                         // cause (throws if Success)

Fold

const message = Try.of(() => riskyOp()).fold(
  value => `Success: ${value}`,
  cause => `Error: ${(cause as Error).message}`,
);

Side effects with tap

Try.of(() => loadConfig())
  .tap(
    config => logger.info("Loaded config", config),
    err => logger.error("Config load failed", err),
  )
  .getOrElse(defaultConfig);

Try.all — collect multiple results

const t = Try.all([
  Try.of(() => parseA(rawA)),
  Try.of(() => parseB(rawB)),
  Try.of(() => parseC(rawC)),
]);

if (t.isSuccess()) {
  const [a, b, c] = t.get();
} else {
  console.error("First failure:", t.getCause());
}

instanceof narrowing

import { Try, Success, Failure } from "@billdaddy/safekit";

const t = Try.of(() => 42);
if (t instanceof Success) {
  t.get(); // TypeScript knows it's Success here
} else {
  t.getCause(); // TypeScript knows it's Failure here
}

Comparison with alternatives

| Package | Lazy (captures exceptions) | TypeScript | Active | Zero deps | |---|---|---|---|---| | safekit (Try) | ✅ | ✅ | ✅ | ✅ | | neverthrow | ❌ (wraps already-computed) | ✅ | ✅ | ✅ | | resultkit | ❌ (wraps already-computed) | ✅ | ✅ | ✅ | | try-monad | ✅ | ❌ | ❌ (abandoned 2017) | ✅ | | fp-ts | ✅ (TaskEither) | ✅ | ✅ | ❌ (heavy) | | Java Vavr Try | ✅ | n/a | ✅ | n/a | | Scala Try | ✅ | n/a | ✅ | n/a |

Contributors ✨

This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.

Thanks goes to these wonderful people:

License

MIT © trananhtung