Sudoo-Optional

Continuous Integration codecov npm version downloads

Optional makes life better

Install

yarn add @sudoo/optional
yarn add @sudoo/symbol # Peer Dependency
# Or
npm install @sudoo/optional --save
npm install @sudoo/symbol --save # Peer Dependency

Usage

import { Optional } from "@sudoo/optional";

const foo: Optional = Optional.ofAny("bar");
foo.exists; // true
foo.value; // "bar"

const bar: Optional = Optional.ofUndefinable();
bar.exists; // false
bar.value; // undefined
bar.getOrThrow(); // Throw Error A
bar.getOrThrow(new Error("B")); // Throw Error B
bar.getOrDefault("baz"); // "baz"