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

@ib-code/result-object

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ib-code/result-object

Function or method result structure serializer

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

ResultObject

npm licence GitHub branch checks state Codecov

In JavaScript, errors and failures are typically implemented with exceptions. In some situations, however, exceptions may not be the best choice. The ResultObject contains a build in methods that transform the result to common structure. The ResultObject object are wrappers for a successful, or failed results of the functions or methods.

Object Sturecture

// SuccessОbject

{
  "ok": true,
  "data": {
    // ...some data
  },
  "error": undefined,
}

// FailedОbject
{
  "ok": false,
  "data": {
    // ...some data
  },
  "error": Error // Error object
}

Installation

$ npm install @ib-code/result-object
$ yarn add @ib-code/result-object

Usage

import { Result, ResultObject } from 'result-object'

const someFunctions = (): ResultObject<number> => {
  try {
    const numebr = getNumber() // example function

    return Result.success(numebr)
  } catch (error) {
    return Result.failed(error, "Additional data")
  }
}

Author

License

Copyright (c) 2022 Igor Bezsmertnyi, contributors. Released under the MIT license

Keywords

result

FAQs

Package last updated on 07 Dec 2023

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