
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
:sparkles: Optional values for JavaScript
Because null is evil for a variety of reasons and other languages, such as Scala,
address this issue through a simple Option
type, where any boxed value is either Some
or None
. This article covers the generic behaviors of Some
and None
using the Scala API.
optionize
simulates this behavior in JavaScript with an extremely simple and idiomatic API:
get
: returns the value without consideration of Some
/None
getOrElse
: returns the value if it is Some
, otherwise returns the provided fallbackmap
: maps the provided function against the value if it is Some
forEach
: applies the provided function to the value if it is Some
That's it!
By declaring values as either Some
or None
, you no longer need toconditionally access your data depending on if a value is present or not and can work with a consistent interface:
import { none, some } from 'optionize'
function badFoo (bar) {
if (bar) {
return bar.baz
}
return {}
}
function goodFoo (bar) {
return bar.getOrElse({}).baz
}
badFoo({ baz: 'boo' }) // returns 'boo'
badFoo(null) // returns {}
goodFoo(some({ baz: 'win' })) // returns 'win'
goodFoo(none) // returns {}
Nothing is perfect and everything comes with tradeoffs. Here's what isn't great about using Some
and None
:
||
or &&
if
or ternary conditions to wrap a value as either Some
or None
(this can probably be improved with a simple implicit method, TODO)npm install optionize
If you are interested in contributing, simply open up a well-justified PR or email me at me@madhax.io.
MIT
FAQs
Optional values for JavaScript
The npm package optionize receives a total of 1 weekly downloads. As such, optionize popularity was classified as not popular.
We found that optionize 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.