Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
better-switch
Advanced tools
The native Javascript switch statement doesn't really fit into the common coding style of Javascript code. Therefore this module aims to handle such use cases in a more intuitive way. This module does not offer the "fall-through" mechanism of a native switch statement.
npm install -S better-switch
Pass an object as first argument. The default
part will be executed in case nothing else matches. If default
is not specified and nothing matches it will return undefined
.
var betterSwitch = require('better-switch');
var map = {
foo: function () {
return 'bar';
},
baz: 42,
default: 'default'
};
var result = betterSwitch('foo', map); // => bar
The associated value can be of any type. If it is a function it will be executed and the result returned. With ES2015 you can make it even clearer:
const baz = 42,
const map = {
foo: () => 'bar',
baz,
default: 'default'
};
const result = betterSwitch('baz', map); // => 42
If you want to return a function you have to wrap it in a function. This is required, because otherwise the function will be executed.
const map = {
func: function() {
return function() {
// do stuff
}
}
}
FAQs
More intuitive version of a Javascript switch statement.
We found that better-switch 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
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.