# @kylejlin/option

> Inspired by Rust's Option.

Latest version **2.0.1** (published 2020-02-02) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @kylejlin/option
pnpm add @kylejlin/option
yarn add @kylejlin/option
bun add @kylejlin/option
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2020-02-02 |
| First published | 2019-11-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 25.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kyle Lin |
| Maintainers | kylejlin |
| Keywords | typescript, rust, option, monad |

## Links

- npm: https://www.npmjs.com/package/@kylejlin/option
- Repository: https://github.com/kylejlin/option
- Homepage: https://github.com/kylejlin/option#readme
- Issues: https://github.com/kylejlin/option/issues
- npm.io page: https://npm.io/package/@kylejlin/option

## 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

- 2.0.1 (latest) — 2020-02-02
- 2.0.0 — 2020-02-02
- 1.1.3 — 2019-12-05
- 1.1.2 — 2019-11-17
- 1.1.1 — 2019-11-14
- 1.1.0 — 2019-11-14
- 1.0.0 — 2019-11-10

## README

# Option

[![Build Status](https://travis-ci.com/kylejlin/option.svg?branch=master)](https://travis-ci.com/kylejlin/option)
[![Coverage Status](https://coveralls.io/repos/github/kylejlin/option/badge.svg?branch=master)](https://coveralls.io/github/kylejlin/option?branch=master)
[![npm version](https://badge.fury.io/js/%40kylejlin%2Foption.svg)](https://www.npmjs.com/package/@kylejlin/option)
[![Downloads](https://img.shields.io/npm/dm/%40kylejlin%2Foption.svg)](https://www.npmjs.com/package/@kylejlin/option)

A [Rust-inspired](https://doc.rust-lang.org/std/option/enum.Option.html) `Option` type for TypeScript.

## DEPRECATION NOTICE

This package has been deprecated.

Use [`rusty-ts`](https://www.npmjs.com/package/rusty-ts) instead.

## Usage

```bash
npm install --save @kylejlin/option
```

```ts
import { Option, option } from "@kylejlin/option";

const a = option.some("foo");
const b = a.map(x => x.toUpperCase());

const c = option.some(3);
const d = a.andThen(a => c.map(c => a.repeat(c)));

function f(opt: Option<string>) {
  console.log(opt.unwrap());
}

// Logs "FOOFOOFOO"
f(d);
```

### Why `Option` _and_ `option`?

`Option` is just an interface—any `Option`-compatible code you write will be compatible with any implementation of `Option`.
This gives you the flexibility to implement `Option` however you like.

However, you probably don't want to write your own implementation, so we provide you with one out-of-the-box via the `option` factory object.
To instantiate a Some or None variant, simply call `option.some()` or `option.none()`, respectively.

## API Docs

Docs can be found [here](https://kylejlin.github.io/option/).

## Caveats

### Forgetting to import `Option` in a browser environment

_Note: You only have to worry about the following section if your tsconfig's `lib` includes `"dom"`._

If you reference `Option` but forget to import it from this package, this will likely be a silent error instead of the expected `Cannot find name 'Option'. (2304)`. This is because the browser declares [an `Option` constructor](https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/Option) as part of its DOM API.

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