npm.io
0.0.5 • Published 10 years ago

optcase

Licence
MIT
Version
0.0.5
Deps
0
Vulns
0
Weekly
0
DeprecatedThis package is deprecated

optcase

.

Build Status

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?

Keywords