@eastbanctech/ts-optional

TS adapted Java Optional class with extra utility classes.

Usage no npm install needed!

<script type="module">
  import eastbanctechTsOptional from 'https://cdn.skypack.dev/@eastbanctech/ts-optional';
</script>

README

Build Status

TS Optional

Typescript adapted Java Optional class.

The library barebone is generated with typescript-library-starter.

How to install

npm i @eastbanctech/ts-optional

API documentation

Documentation is available here.

Usage examples

Optional instance can be created with:
  • Optional.ofNullable(someValue)
  • Optional.of(nonNullableValue)
  • Optional.empty()
Can be used like:
  const entityUuid = Optional.of(response)
      .filter(resp => resp.isPresent)
      .map(responseToEntity)
      .map(entity => entity.uuid)
      .filter(isNotNullOrEmpty)
      .orElseGet(() => route.snapshot.queryParamMap.get('uuid') as string);

Supported Node versions

Automatically tested with Node versions:

  • 10
  • 11
  • 12
  • 14
  • Latest version