Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
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']
The EvaluateCase (or Evaluate, as it's still supported atm) method lets you run a specific case by passing in the case as a parameter.
if the provided parameter is does not match any of the cases, it will run the default routine.
Also, the case parameter is case-sensitive.
const x = new Suicchi({
default: "Awesome",
Rye: "Gay",
rye: "Gay",
rYe: "Gay",
ryE: "Gay"
});
x.EvaluateCase("Ray"); // => "Awesome"
x.EvaluateCase("Jacob"); // => "Awesome"
x.EvaluateCase("Rye"); // => "Gay"
x.EvaluateCase("rye"); // => "Gay"
x.EvaluateCase("rYe"); // => "Gay"
x.EvaluateCase("ryE"); // => "Gay"
FAQs
Switch case on steroids
The npm package suicchi receives a total of 1 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.