ts-optional-class

Optional Type in TypeScript like Java Optional API

Optional

Optional for Typescript inspired by the Java Optional.

Install

npm install --save ts-optional-class

Usage

Example:

import {Optional} from '@ama-team/optional'

const fraudulent = Optional
  .of(user)
  .map(user => user.processors)
  .map(processors => processors.fraud)
  .map(metadata => metadata.fraudulent)
  .orElse(false);

API

You have four ways to create an optional:

Optional.empty();
Optional.of(value); // throws error if value is null
Optional.ofNullable(value);
Optional.ofAnything(value); // throws error if value is undefined

HomePage

https://github.com/D4v1X/ts-optional-class#readme

Repository

git+https://github.com/D4v1X/ts-optional-class.git