# flatry

> Flatry converting promise or function to flat array response. Inspired by golang style error handling without try/catch.

Latest version **1.0.15** (published 2024-01-13) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.15 |
| Published | 2024-01-13 |
| First published | 2017-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/flatry) |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 254.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 55 |
| Author | ymatuhin |
| Maintainers | ymatuhin |
| Keywords | flat, flatten, promise, async, await, golang, error handling, destructuring, try, catch |

## Links

- npm: https://www.npmjs.com/package/flatry
- Repository: https://github.com/ymatuhin/flatry
- Homepage: https://github.com/ymatuhin/flatry#readme
- Issues: https://github.com/ymatuhin/flatry/issues
- npm.io page: https://npm.io/package/flatry

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.15 (latest) — 2024-01-13
- 1.0.14 — 2023-02-03
- 1.0.13 — 2023-02-03
- 1.0.12 — 2018-04-20
- 1.0.11 — 2018-04-20
- 1.0.10 — 2018-04-20
- 1.0.9 — 2018-03-30
- 1.0.8 — 2017-11-23
- 1.0.7 — 2017-11-19
- 1.0.6 — 2017-11-17
- 1.0.5 — 2017-11-17
- 1.0.4 — 2017-11-17
- 1.0.3 — 2017-11-16
- 1.0.2 — 2017-11-16
- 1.0.1 — 2017-11-16
- … 1 more at https://npm.io/package/flatry/versions

## README

# Flatry

[![Build Status](https://travis-ci.org/ymatuhin/flatry.svg?branch=master)](https://travis-ci.org/ymatuhin/flatry)
[![GitHub license](https://img.shields.io/github/license/ymatuhin/flatry.svg)](https://github.com/ymatuhin/flatry/blob/master/LICENSE)

Flatry (flat try) converting promise or function to flat array response with `[err, result]`.

Inspired by golang style error handling without try/catch.

&nbsp;

## Install

```bash
npm install flatry
# or
yarn add flatry
```

&nbsp;

## Use

```js
import flatry from "flatry";
// or
const flatry = require("flatry");
```

&nbsp;

## Examples

![Flatry example](https://raw.githubusercontent.com/ymatuhin/flatry/master/example.png)

&nbsp;

### Asynchronous (async/await)

```js
// Before
async asyncData({ app, error }) {
  try {
    const categories = (await app.$axios.$get('forum')).sections;
    return { categories };
  } catch (err) {
    return error({ statusCode: err.statusCode });
  }
}


// After
async asyncData({ app, error }) {
  const [err, res] = await flatry(app.$axios.$get('forum'));
  if (err) return error({ statusCode: err.statusCode });
  return { categories: res.sections };
}
```

### Synchronous

```js
// Before
let result = false;
try {
  result = mayThrowErrorSomeday();
} catch (error) {
  console.log("Error catched", error);
}
console.log("result", result);

// After
const [err, result] = flatry(mayThrowErrorSomeday);
if (err) console.log("Error catched", err);
console.log("result", result);
```

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