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.
Simple Enumerable object in javascript.
Enum.extend function expect two parameters:
var HTTPCodeEnum = Enum.extend({
CONTINUE: "100",
OK: "200",
MULTIPLE_CHOISES: "300",
BAD_REQUEST: "400",
INTERNAL_ERROR: "500"
});
You can also pass in first object:
MyEnum.myFunction()
__myInternalValue
Enum throws error in some usual cases. So there is an ability to use custom Errors for your custom Enums, to catch them upper and check with instanceOf
function:
var HTTPCodeEnum = Enum.extend({
... // constants
__error: MyOwnError // reference to your Error constructor
});
If
__error
does not present in first parameter object, then Enum will use its own EnumError constructor. Anyway, u can always get the reference to the Error function viaEnum.__error
function ajaxCallback(data) {
if (data.code == HTTPCodeEnum.OK) {
// ...
}
}
function ajaxCallback(data) {
// Throws a EnumError if catch non existing code
var status = new HTTPCodeEnum(data.code);
// Returns mapped message
// getMessage must be implemented in HTTPCodeEnum.prototype
console.log(status.getMessage());
}
// Exceptions handling
function indexController() {
try {
var request = $.ajax(...).done(ajaxCallback);
} catch(e) {
if (e instanceof HTTPCodeEnum.__error) {
console.log('Catched non existing HTTP code!', e.message);
}
}
}
FAQs
Javascript enum object
We found that enum-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.
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.