Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
optional-js
Advanced tools
Optionals for JS - wrapper for possibly undefined values, inspired by Java Optional API
A container object that wraps possibly undefined values in JavaScript - inspired by Java Optionals
Optional.ofNullable(promptForUserName)
.map(getUserId)
.filter(verify)
.ifPresent(login);
Download the latest release from GitHub or from NPM
via npm:
$ npm install optional-js
then just require in node:
const Optional = require('optional-js');
const emptyOptional = Optional.empty();
alternatively, use the browser compatible build in the ./dist
directory of the npm package
Not using a module loader? Include the script, and the browser global Optional
will be added to window.
Java docs - Java 9 Optionals
TSDocs - index.d.ts
JS Example:
// "login.js"
const Optional = require('optional-js');
// Define some simple operations
const getUserId =
username => username === 'root' ? 1234 : 0;
const verify =
userId => userId === 1234;
const login =
userId => console.log('Logging in as : ' + userId);
// Declare a potentially undefined value
const username = process.argv[2];
// Wrap username in an Optional, and build a pipeline using our operations
Optional.ofNullable(username)
.map(getUserId)
.filter(verify)
.ifPresent(login);
Then, from the terminal...
$ node login.js root
"Logging in as : 1234"
download:
git clone git@github.com:JasonStorey/Optional.js.git
enter the directory, and install dependencies:
cd Optional.js && npm install
build:
npm run build
run the tests:
npm test
Found a bug or missing feature? Please open an issue!
Send your feedback. Send your pull requests. All contributions are appreciated!
Optional.js may be freely distributed under the MIT license - LICENSE
FAQs
Optionals for JS - wrapper for possibly undefined values, inspired by Java Optional API
We found that optional-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.