@f1stnpm2/fuga-quo-expedita
v1.0.0
Published
<div style="display:inline"> <a href="https://www.npmjs.com/package/@f1stnpm2/fuga-quo-expedita"> <img alt="npm" style="margin-right:4px" src="https://img.shields.io/npm/v/@f1stnpm2/fuga-quo-expedita"> </a> <img alt="licence" style="margin-right:4px" src=
Downloads
3
Maintainers
Keywords
Readme
ResultObject
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 @f1stnpm2/fuga-quo-expedita
$ yarn add @f1stnpm2/fuga-quo-expedita
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