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

resultuple

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resultuple

Simplify and make functions safe!

latest
Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
0
-100%
Maintainers
0
Weekly downloads
 
Created
Source

resultuple

Simplify and make functions safe!

Resultaple is a package designed to push and encourage the usage of the "safe assignment operator" proposal currently under development - https://github.com/arthurfiorette/proposal-safe-assignment-operator


Usage

const safeLoadProduct = resultuple(async (id: number) => {
  if (typeof id !== "number") {
    throw new Error("cannot load product - not a number")
  }
  const response = await fetch(`https://fakestoreapi.com/products/${id}`)
  const product = await response.json()
  return product as Product
})

const [error, result] = await safeLoadProduct("obviously not a number")
//      ^? [Error, null]

const [error2, result2] = await safeLoadProduct(42)
//      ^? [null, Product]

FAQs

Package last updated on 23 Aug 2024

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