Optionals for JS
Download the latest release from GitHub or from NPM
via npm:
$ npm install js.optional
then just require in node:
var Optional = require('js.optional');
var numberOptional = Optional.of(123);
equals({*})
- Indicates whether some other object is "equal to" this Optional.filter({function})
- If a value is present, pass the Optional value to predicate function, return an Optional describing the value, otherwise return an empty Optional.isPresent()
- If a value is present, return true if Optional value is not 'null' of 'undefined', otherwise return false.isPresent({function})
- If a value is present, invoke the specified consumer with the value, otherwise do nothing.map({function})
- If a value is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result. Otherwise return an empty Optional.orElse({*})
- Return the value if present, otherwise return other.orElseGet({Optional})
- Return the value if present, otherwise invoke 'other.get' and return the result of that invocation.
empty()
- Returns an empty Optional.of()
- Returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional.ofNullable()
- Returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional.
Found a bug or missing feature? Please open an issue!
Send your feedback. Send your pull requests. All contributions are appreciated!
js.optional may be freely distributed under the MIT license.