New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@libn/result

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libn/result

Simple result handling.

latest
Source
npmnpm
Version
0.5.0
Version published
Maintainers
1
Created
Source

@libn/result

Simple result handling.

default

Handle errors like Rust's std::result and Go's (in)famous if err != nil.

import { as, open, seal, wrap } from "@libn/result";

// Define possible errors and their corresponding values
type Errors = {
  NonStringInput: unknown;
  InvalidJson: Error;
};
const parse = (raw: unknown) =>
  // Parameterize symbol with errors
  wrap(as<Errors>(), (no) => {
    // Throw as expression
    const json = typeof raw === "string" ? raw : no("NonStringInput", raw);
    // Wrap unsafe functions
    const result = seal(JSON.parse, "InvalidJson")(json);
    // Re-throw when types are compatible
    return open(result, { InvalidJson: no });
  });

FAQs

Package last updated on 29 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts