1.0.3 • Published 9 months ago

simple_ts_switch v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

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"
1.0.3

9 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago