Catalog npm
Back to packageRELEASE DETAILS

1.0.0

npm

@00f2ff/result

Safe promise handling with Results, implemented with ES2020 features

result
Published27 Feb 2023
Direct dependencies14
Transitive dependenciesNot calculated

README

Current package documentation

Result

Safely handle asynchronous errors with Result. Inspired by neverthrow's core ResultAsync types, but is intended for use in sequential imperative statements using async/await, rather than functional pipelining.

Akin to Rust's std::result and Scala's scala.util.Either. Uses ES2020's Promise.allSettled under the hood and mostly follows its naming convention.

Installation

npm i @00f2ff/result

API

E defaults to Error.

settle<T, E>

Settles a promise into Result<T, E> that can be narrowed to Fulfilled<T, E> or Rejected<T, E>.

const result: Result<boolean, Error> = await settle(Promise.resolve(true));
if (result.isFulfilled()) { 
  console.log(result.value); // true
}
const result: Result<boolean, Error> = await settle(Promise.reject(new Error("oh no"));
if (result.isRejected()) { 
  console.log(result.error); // Error("oh no")
}

settleAll<T, E>

Settles an array of promises into a tuple of [Fulfilled<T, E>[], Rejected<T, E>[]].

const resolvingPromises = [Promise.resolve(true), Promise.resolve("hello")];
const rejectingPromises = [Promise.reject(new Error("oh no"), Promise.reject(new DbError("ruh roh"))];

const [fulfilled, rejected] = await settleAll<boolean | string, Error | DbError>([...resolvingPromises, ...rejectingPromises]);

Test

npm run test

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 14

Native requirements
14 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@types/jest
Environment
{
  "local_name": "@types/jest",
  "alias": false,
  "peer_metadata": null
}
29.4.0development
@typescript-eslint/eslint-plugin
Environment
{
  "local_name": "@typescript-eslint/eslint-plugin",
  "alias": false,
  "peer_metadata": null
}
5.51.0development
@typescript-eslint/parser
Environment
{
  "local_name": "@typescript-eslint/parser",
  "alias": false,
  "peer_metadata": null
}
5.51.0development
eslint
Environment
{
  "local_name": "eslint",
  "alias": false,
  "peer_metadata": null
}
8.33.0development
eslint-config-prettier
Environment
{
  "local_name": "eslint-config-prettier",
  "alias": false,
  "peer_metadata": null
}
8.6.0development
eslint-plugin-import
Environment
{
  "local_name": "eslint-plugin-import",
  "alias": false,
  "peer_metadata": null
}
2.27.5development
eslint-plugin-n
Environment
{
  "local_name": "eslint-plugin-n",
  "alias": false,
  "peer_metadata": null
}
15.6.1development
eslint-plugin-prettier
Environment
{
  "local_name": "eslint-plugin-prettier",
  "alias": false,
  "peer_metadata": null
}
4.2.1development
eslint-plugin-promise
Environment
{
  "local_name": "eslint-plugin-promise",
  "alias": false,
  "peer_metadata": null
}
6.1.1development
husky
Environment
{
  "local_name": "husky",
  "alias": false,
  "peer_metadata": null
}
8.0.3development
jest
Environment
{
  "local_name": "jest",
  "alias": false,
  "peer_metadata": null
}
29.4.3development
prettier
Environment
{
  "local_name": "prettier",
  "alias": false,
  "peer_metadata": null
}
2.8.3development
ts-jest
Environment
{
  "local_name": "ts-jest",
  "alias": false,
  "peer_metadata": null
}
29.0.5development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
4.9.5development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-MSaDtI80VF0ZFoSyaKumJryoFRJZ/O9r5ZM36u7GFt3J/EDwlClasViWWodnLJOFhzxP7y7iWkErqlj5oLEzkQ==",
  "shasum": "78c3e788bf301bea453f1d9bb9d734c07917014d",
  "tarball": "https://registry.npmjs.org/@00f2ff/result/-/result-1.0.0.tgz",
  "fileCount": 8,
  "unpackedSize": 9670,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEQCIEfjs2pguvEBR5Ag0TvcQ7+Cxh7ZkzG3YR6fWVtYG4gRAiA6/1W8ud8HgEZfJ6EOqJzwGJSww3lWbw6X6ismA0vlKQ=="
    }
  ],
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj/CSqACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoFuw//bcRNwKZKVEyZ4ZwhwMtOIJdZWzfNh204na+ASCcAfAMvmuSB\r\ns60mJkMdYcfZ+t8rFSGSOs3ld5Dz5T2J3CIORjGd1ZTKp4zpjdOHhvdnryUh\r\nJJpdAzV2+9uANf+SaaRgumvivI16fCdtxXq99u2bfMCka5nG39iwVmwucgga\r\nN8A1vxJO0hjC6a7T2r9CONNcgEbKg++97VG4AbZff6kvuYSrw7JwGmyQsVU5\r\nWc27Rw0MqU3AhXGe637DhB+0EaezGlL6oSph1QsJWlBE366z6NSUQwkfEteR\r\nMUVOFQWY/nmjLgAx3lJuVMGADf11JO0xJw1YPiwWrKOK3pMAroB1p0S7j6Jy\r\nCCXkFOZLEj6jBqLs5YyAKYTnoQGF9xJkYZRWcDjzMaLIMlHfrCUO3NtTkBDV\r\n1R8KI9seQ0hNN7z0ybmPZJWGltFVb4djToSjdcFQsdFiYH8Ez/aWPaAQQPQU\r\ncPjhsg8XNc3XNZDw2NxrO3Ll1cX0b3rUh/1lXFvqdz050di0m/+tq421Efvs\r\nmIJ8PFPKACEGw7SlLjqR/VmBQTDeZ3p4x2lfBTF7SJvgZDZKQWDMlMm7NwCN\r\njAqEZbnVL/S9NlBtukxU4AzDPawgJJV5r6b2D1XhaPge0jc87htHg7NrlGYH\r\nGosqwc7ceOlEVY3WxmMmSm1Yc3hpRIZ6mTY=\r\n=JfiR\r\n-----END PGP SIGNATURE-----\r\n"
}

Repository

PENDING
00f2ff/result

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 21:54 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:5d5a8cb87c9552cc33028e0f93b07f5e99de873ccd5c508e062c87fc11f58fa1

Other collected versions

0.1.027 FebView all collected versions →