
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.
assert-exists
Advanced tools
A package for consistently asserting if a variable exists.
Install.
npm install assert-exists --save
Use it.
var a = require("assert-exists");
var errorMsg = a.msg("MyPackage");
function MyPackage(options) {
a.exists(options, errorMsg('options'));
a.exists(options.someString, errorMsg('someString'), 'string');
}
.exists(value, errorMessage, *type)
typeof
type (if it's provided), otherwise throws AssertionError: "errorMessage"
..msg(packageString)
"ERROR: Expected {1} to be passed into {packageString}."
When passing configs into constructors, I ran into a problem where the same code was copied and pasted lots of times. That was annoying, verbose and error prone. It looked like this:
function MyPackage(configs) {
assert(configs, "Expected configs to be passed into MyPackage");
assert(
typeof configs.enabled === 'bool',
"Expected configs to be passed into MyPackage" // not correct
);
this.enabled = configs.enabled;
assert(
configs.db && typeof configs.db.host === 'string',
'Expected host to be passed into MyPackage' // not really correct
);
assert(
configs.db && typeof configs.db.port === 'string',
'Expected host to be passed into MyPackage' // wrong string
);
}
This sucks. So, I made the package to constrict my ability to mess this stuff up, and take away some of the copy-pasta incentive.
Now we have one function to check if it exists, and one to get an error message. Simple.
a.exists(finished, a.msg('README')('finished'), 'bool');
FAQs
A small package for consistently asserting if a value exists
The npm package assert-exists receives a total of 99 weekly downloads. As such, assert-exists popularity was classified as not popular.
We found that assert-exists 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.