Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

suicchi

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

suicchi

Switch case on steroids

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

suicchi

codecov Greenkeeper badge Build Status NPM Version Downloads Stats Donate

Better and cleaner switch case made for everyone

Installation

You can start by installing this library using the command below:

npm i --save suicchi

Usage

import { Suicchi } from "suicchi";

const switchCase = new Suicchi();

switchCase.addCase("car", "Ford GT");
switchCase.addCase("name", "Rye");
switchCase.addCase("gender", "female");

const name = switchCase.assert("name");

console.log(name); // will return "Rye"

// the above code will translate to
let name;

switch ("name") {
  case "car":
    name = "Ford GT";
    break;
  case "name":
    name = "Rye";
    break;
  case "gender":
    name = "female";
    break;
  default:
    name = () => {}
    break;
}

console.log(name);

Adding default case

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.assert("age");

console.log(age); // will return "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);

Multiple keys

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.assert("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;
}
  1. Fork it https://github.com/yakovmeister/suicchi/fork
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Keywords

FAQs

Package last updated on 20 Dec 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc