Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
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
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.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.