0.0.5 • Published 9 years ago
optcase v0.0.5
optcase
.
Installation
$ npm install --save optcase
Usage
import optcase from "optcase";
function who(){
optcase(arguments)
.case("string", (name) => {
console.log(`My name is ${name}.`);
})
.case("string", "number", (name, age) => {
if (age === 1)
console.log(`My name is ${name}, I'm ${age} year old.`);
else if (age > 1)
console.log(`My name is ${name}, I'm ${age} years old.`);
else
console.log("I wasn't born yet.");
})
.default(() => {
console.log("Who am I?");
});
}
who("haruna"); // My name is haruna.
who("haruna", 102); // My name is haruna, I'm 102 years old.
who("girlfriend", -Infinity); // I wasn't born yet.
who(); // Who am I?