Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Hey people,

This is an attempt to create a small library that replaces the default switch from js.

The simpleSwitch function has three arguments:

  • a value that needs to be compared ;
  • an object of cases <Record<string, T>>;
  • the default value (optional) .

The object of cases should have the following structure:

{
  case1: return_value1,
  case2: return_value2,
  ...
}

There is always a break after the first found case.

Usage example:

const fruitColor = simpleSwitch<string>(
  "apple",
  {
    apple: "red",
    banana: "yellow",
    grape: "purple",
  },
  "unknownFruit"
);

console.log(fruitColor); // "red"

Open on npm

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages