ts-optional-class
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Optional

npm Build Coverage Status Code style: prettier License

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

Readme

Keywords

Package Sidebar

Install

npm i ts-optional-class

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

10.5 kB

Total Files

6

Last publish

Collaborators

  • d4v1x