# sufa

> Result

Latest version **1.0.7** (published 2024-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install sufa
pnpm add sufa
yarn add sufa
bun add sufa
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2024-08-08 |
| First published | 2023-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ilushling |
| Maintainers | ilushling |
| Keywords | result, success, failure, match, error |

## Links

- npm: https://www.npmjs.com/package/sufa
- Repository: https://github.com/Ilushling/Result
- Homepage: https://github.com/Ilushling/Result#readme
- Issues: https://github.com/Ilushling/Result/issues
- npm.io page: https://npm.io/package/sufa

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.0.7 (latest) — 2024-08-08
- 1.0.6 — 2024-05-03
- 1.0.5 — 2024-04-23
- 1.0.4 — 2024-03-04
- 1.0.3 — 2024-03-03
- 1.0.2 — 2024-01-28
- 1.0.1 — 2023-12-23
- 1.0.0 — 2023-12-23

## README

# Result
Result model with model factory and match on success & on failure callbacks.

- [Features](#features);
- [Usage](#usage):
    - [Prepare](#prepare);
        - [Create model factory](#create-model-factory);
        - [Import types](#import-types).
    - [Commands](#commands):
        - [Result factory](#result-factory):
            - [Ok](#ok);
            - [Fail](#fail).
        - [Result](#result):
            - [isSuccess](#isSuccess);
            - [isFailure](#isFailure);
            - [getData](#getData);
            - [getError](#getError);
            - [match](#match).

## Features
1) Data in success;
2) Error in failure;
3) Match with onSuccess & onFailure callbacks;
4) Factory.

## Usage
- [Prepare](#prepare);
- [Commands](#commands).

### Prepare
#### Create model factory
```js
import { ResultModelFactory, ResultModel } from 'sufa';

const resultModelFactory = new ResultModelFactory({
  Model: ResultModel
});
```

#### Import types
```js
/**
 * @import { IResultModelFactory, IResultModel } from 'sufa'
 */
```

### Commands
#### Result factory
##### Ok
```js
const okResult = resultModelFactory.ok();
const okDataResult = resultModelFactory.ok('data');
```

##### Fail
```js
const error = new Error('Message');

result.fail(error);
```

#### Result
- [isSuccess](#isSuccess);
- [isFailure](#isFailure);
- [getData](#getData);
- [getError](#getError);
- [match](#match).

##### isSuccess
```js
const isSuccess = result.success;
```

##### isFailure
```js
const isFailure = result.failure;
```

##### getData
```js
const data = result.getData();
```

##### getError
```js
const error = result.getError();
```

##### match
```js
result.match({
  onSuccess: () => {},
  onFailure: () => {}
});
```

---
_Source: https://npm.io/package/sufa · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
