WhenSwitch adds Ruby-like case/when statements in JavaScript, through a single when function.

Ternary expressions become too much nested when handling too much cases, and switch statements are error-prone and block-only, WhenSwitch enables simple function conditional flows, as expressions:

const getDrinkPrice = drink =>
    .is('Coke', 1.5)
    .is('Pepsi', 1.8)

This is useful for conditional components in React for example:

    .is('Hello', () => <HelloPage />)
    .is('World', () => <WorldPage />)
    .else(() => (
      <Page404 />

JavaScript not being lazily evaluated though, it adds some overhead on expressions, needing to wrap them in thunks.

Another issue is with TypeScript: The goal here was to have something completely type-safe, but as it was impossible at the moment to define generic type guards, I left this library as it was, and for now only use it for simple cases.