Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Better and cleaner switch case made for everyone
You can start by installing this library using the command below:
npm i --save suicchi
npm run coverage
import { Suicchi } from "suicchi";
const switchCase = new Suicchi();
switchCase.addCase("car", "Ford GT");
switchCase.addCase("name", "Rye");
switchCase.addCase("gender", "female");
const name = switchCase.evaluate("name");
console.log(name); // => "Rye"
// the above code will translate to:
// let name;
// switch ("name") {
// case "car":
// name = "Ford GT";¸¸
// break;
// case "name":˚v
// name = "Rye";
// break;
// case "gender":
// name = "female";
// break;
// default:
// name = () => {}
// break;
// }
// console.log(name);
import { Suicchi } from "suicchi";
const defaultCase = "no-record";
const switchCase = new Suicchi(defaultCase);
switchCase.addCase("car", "Ford GT");
switchCase.addCase("name", "Rye");
switchCase.addCase("gender", "female");
const age = switchCase.evaluate("age");
console.log(age); // => "no-record"
// the above code will translate to
// let age;
// switch ("age") {
// case "car":
// age = "Ford GT";
// break;
// case "name":
// age = "Rye";
// break;
// case "gender":
// age = "female";
// break;
// default:
// age = "no-record";
// break;
// }
// console.log(age);
import { Suicchi } from "suicchi";
const switchCase = new Suicchi();
switchCase.addCase(["car", "transportation"], "Ford GT");
switchCase.addCase("name", "Rye");
switchCase.addCase("gender", "female");
const car = switchCase.evaluate("car");
console.log(car); // will return "Ford GT"
// the above code will translate to
// let car;
// switch ("name") {
// case "car":
// case "transportation":
// car = "Ford GT";
// break;
// case "name":
// car = "Rye";
// break;
// case "gender":
// car = "female";
// break;
// default:
// car = () => {}
// break;
// }
The Suicchi Object constructor only takes in 1 optional parameter which can either a value, a function, or an object. And it generates the case depending on the type of parameter you pass in.
If you only pass in a value or a function, like the following:
const Switch = new Suicchi(() => {
// DO OTHER THINGS...
return 1 + 1;
});
const aSwitch = new Suicchi(() => ('aValue'));
const bSwitch = new Suicchi('anotherValue');
You'll be doing something equivalent to:
// Switch
switch(x) {
default:
// DO OTHER THINGS...
return 1 + 1;
}
// aSwitch
switch(x) {
default:
return 'aValue';
}
// bSwitch
switch(x) {
default:
return 'anotherValue';
}
But if you pass in an Object, you'll be able to pass in other cases and routines besides the default case and routine, like so: (Note: if you pass in an object - the 'default' property will be required)
const cSwitch = new Suicchi({
default: null;
case1: "What";
case2: () => (1234)
})
You'll be doing something similar to:
// cSwitch
switch(x) {
case 'case1':
return 'What';
case 'case2':
return 1234;
default:
return null;
}
The AddCase method allows you to add new or overwrite existing cases. It takes in 2 parameters - the case and the routine.
The case can be of the following types: string, string[], or object;
if the case is an object, then the 2nd parameter, the routine, is no longer required as it should be paired into the key-value case object.
Example of use:
const x = new Suicchi();
// To assign a single case to a single routine
x.addCase("aValue", "anotherValue");
// the above is equivalent to:
switch(X) {
case "aValue":
return "anotherValue";
// by default, this is already present at this point
// as this is set upon initialization of the Suicchi object instance
default:
return null;
}
// To assign a multiple cases to a single routine
x.addCase(["val1", "val2"], "anotherValue");
// the above is equivalent to:
switch(X) {
case "val1":
case "val2":
return "anotherValue";
default:
return null;
}
// To assign multiple cases to multiple routines
x.addCase({
condition1: "12345",
condition2: 12345,
});
// the above is equivalent to:
switch(X) {
// ...EXISTING CASES AND ROUTINES
case "condition1":
return "12345";
case "condition2":
return 12345;
// ...OTHER EXISTING CASES AND ROUTINES
default:
return null;
}
The GetCases method will return a string array containing the existing cases that you've set for the Suicchi instance.
const x = new Suicchi({
default: null;
case1: "What";
case2: () => (1234)
})
x.getCases(); // => ['case1', 'case2', 'default']
FAQs
Switch case on steroids
The npm package suicchi receives a total of 0 weekly downloads. As such, suicchi popularity was classified as not popular.
We found that suicchi 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.