1.1.7 • Published 2 years ago

@amidevtech/optional.js v1.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

optional.js

Makes TypeScript/JavaScript code undefined/null safe!

Optional.js is a wrapper for undefined and null values in TypeScript/JavaScript which fixes problems with handling this values.

Reasons to use optional.js

  • Eliminate errors correlated with undefined / null handling in code.
  • Makes you aware of possible scenarios when value is undefined / null.
  • Built in methods for handling undefined / null to reduce required checks.
  • Makes code easier to read.

Change this:

const user: User = getUser(4);
if (user !== undefined) {
    console.log(user.name);
}

into this:

getUser(4).ifPresent(user => console.log(user.name))

Or this:

const users: User[] = getUsers();
const user: User = users.find(user => user.name == 'test');
if (user !== undefined) {
    console.log(user.name);
}

into this:

OptionalArray.ofArray(getAllUsers())
    .findOne(user => user.name == 'test')
    .ifPresent(user => console.log(user.name))

Usage

Library consist of two main class/helpers

Features

  • Contains known from Java Optional (Without stream()) and more.
  • Contains useful methods which reduce boilerplate code for array operations.
  • Written in TypeScript with type checking.
  • No external dependencies.
  • Small footprint.
  • 100% code coverage.

Installation

Download from npm or from GitHub

Changelog

Changelog

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago