Svelte switch case

Switch case syntax for your Svelte components.

Demo · StackBlitz · NPM Package


## :zap: Getting started **Step 1:** Add the preprocessor to your Svelte project ```bash # Install it: npm i -D svelte-switch-case ``` ```javascript // Then, in your svelte.config.js import switchCase from 'svelte-switch-case'; const config = { preprocess: [switchCase()], }; export default config; ``` **Step 2:** Start using it in your Svelte components ```html
{#switch animal} {:case "cat"}

meow

{:case "dog"}

woof

{:default}

oink?

{/switch}
```
## :mag: How it works `svelte-switch-case` transpiles the following code ```html {#switch animal} {:case "cat"}

meow

{:case "dog"}

woof

{:default}

oink?

{/switch} ``` into `if/else` statements ```html {#if animal === "cat"}

meow

{:else if animal === "dog"}

woof

{:else}

oink?

{/if} ```
## :raised_hands: Contribute Found a bug or just had a cool idea? Feel free to [open an issue](https://github.com/l-portet/svelte-switch-case/issues) or [submit a PR](https://github.com/l-portet/svelte-switch-case/pulls).