New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

optional-type

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

optional-type

Optional implementation in Typescript

latest
npmnpm
Version
1.0.5
Version published
Maintainers
1
Created
Source

Optional-type 🤷‍♂️

Maintainability Test Coverage Known Vulnerabilities CircleCI Greenkeeper badge

A Typescript class trying to be Java's Optional.

Resources

Why

  • Your application might need to add special meaning to null values.
  • Avoid repeating if(expr === null)
  • Avoid cannot read property prop of null

Examples

Some very good examples can be found here. The examples are written in Java, but the concept should get across regardless.

Sample code:

Optional.ofNullable(response)
        .map(response => response.data)
        .filter(data => !!data.length)
        .ifPresent(data => serialize(data))
        .orElse([]);

Now has support for pivoting on both undefined & null if you don't want to differentiate in JS, just expect it to work.

Optional.ofUndefinable(response);

Contributing

To get the project running locally:

  • git clone
  • npm install
  • npm run test to run jest

Before committing, please recompile the docs using npm run docs.

Keywords

optional

FAQs

Package last updated on 12 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts