1.0.2 • Published 9 years ago
js.optional v1.0.2
js.optional
Optionals for JS
Installation
Download the latest release from GitHub or from NPM
via npm:
$ npm install js.optionalthen just require in node:
var Optional = require('js.optional');
var numberOptional = Optional.of(123);API
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.
Static
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.
Contributing
Found a bug or missing feature? Please open an issue!
Send your feedback. Send your pull requests. All contributions are appreciated!
License
js.optional may be freely distributed under the MIT license.