# my-only-either

> Only support either interface

Latest version **1.3.0** (published 2022-08-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install my-only-either
pnpm add my-only-either
yarn add my-only-either
bun add my-only-either
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2022-08-30 |
| First published | 2022-05-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | ByungJoon Lee |
| Maintainers | jooni |
| Keywords | either, typescript |

## Links

- npm: https://www.npmjs.com/package/my-only-either
- Repository: https://github.com/imjuni/my-only-either
- Homepage: https://github.com/imjuni/my-only-either#readme
- Issues: https://github.com/imjuni/my-only-either/issues
- npm.io page: https://npm.io/package/my-only-either

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.3.0 (latest) — 2022-08-30
- 1.2.0 — 2022-07-27
- 1.1.2 — 2022-05-04
- 1.1.1 — 2022-05-04
- 1.1.0 — 2022-05-04
- 1.0.0 — 2022-05-04

## README

# my-only-either

[![Download Status](https://img.shields.io/npm/dw/my-only-either.svg)](https://npmcharts.com/compare/my-only-either?minimal=true) [![Github Star](https://img.shields.io/github/stars/imjuni/my-only-either.svg?style=popout)](https://github.com/imjuni/my-only-either) [![Github Issues](https://img.shields.io/github/issues-raw/imjuni/my-only-either.svg)](https://github.com/imjuni/my-only-either/issues) [![NPM version](https://img.shields.io/npm/v/my-only-either.svg)](https://www.npmjs.com/package/my-only-either) [![License](https://img.shields.io/npm/l/my-only-either.svg)](https://github.com/imjuni/my-only-either/blob/master/LICENSE)

Simple Type and Function set for Either interface. Either important concept in functional programming. But Node.js and TypeScript don't have implmentation. So you can choose another functional implementation like [fp-ts](https://github.com/gcanti/fp-ts) or anther functional utility. But if you need only Eihter, this package is good alternative.

# Why? use Either?

## Zero Dependency
my-only-either not use package. only 1k(1,489byte) size.

## Help functional programming
Helpful for functional programming and integrate return type. See below.

```ts
import { parse as jsoncParse } from 'jsonc-parser';
import { parse as json5Parse } from 'json5';

function json5Parse(value: string): PassFailEither<Error, Record<any, any>> {
  try {
    return pass(json5Parse(value));
  } catch (err) {
    return fail(new Error(err));
  }
}

function jsoncParse(value: string): PassFailEither<Error, Record<any, any>> {
  try {
    return pass(jsoncParse(value));
  } catch (err) {
    return fail(new Error(err));
  }
}

function parse(value: string): Record<any, any> {
  const jsoncParsedEither = jsoncParse(value);

  if (isPass(jsoncParsedEither)) {
    return jsoncParsedEither.pass;
  }

  const json5ParsedEither = json5Parse(value);

  if (isPass(json5ParsedEither)) {
    return json5ParsedEither.pass;    
  }

  throw new Error(json5ParsedEither.fail);
}
```

throw keyword move control-flow. But Either, PassFailEither don't move control-flow besides Either helpful functional programming and function pipe.

# Either
Name using left and right.

| name | category | description |
| :- | :-: | :- |
| ILeft | type | Left interface |
| IRight | type | Right interface |
| Either | type | Either type using ILeft and IRight |
| TPickLeft | utility type | Return Type of left in Either |
| TPickILeft | utility type | Return Type of ILeft in Either |
| TPickRight | utility type | Return Type of right in Either |
| TPickIRight | utility type | Return Type of IRight in Either |
| left | function | value convert ILeft type |
| right | function | value convert IRight type |
| isLeft | function | check given value is ILeft type |
| isRight | function | check given value is IRight type |

# PassFailEither
Name using pass and fail.

| name | category | description |
| :-: | :-: | :- |
| IFail | type | Fail interface |
| IPass | type | Pass interface |
| PassFailEither | type | PassFailEither type using IFail and IPass |
| TPickFail | utility type | Return Type of fail in Either |
| TPickIFail | utility type | Return Type of IFail in Either |
| TPickPass | utility type | Return Type of pass in Either |
| TPickIPass | utility type | Return Type of IPass in Either |
| fail | function | value convert IFail type |
| pass | function | value convert IPass type |
| efail | function | value convert IFail type, exactly same fail. If you use jest or test runner this function is helpful for auto import & auto complete |
| epass | function | value convert IPass type, exactly same pass. If you use jest or test runner this function is helpful for auto import & auto complete |
| isFail | function | check given value is IFail type |
| isPass | function | check given value is IPass type |

# Type order in Eiter, PassFailEither
First type arguments is ILeft or IFail. Because fp-ts and many functional programming language choose first type is left(or fail).

```ts
type Either<TLEFT, TRIGHT> = ILeft<TLEFT> | IRight<TRIGHT>;
```

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