Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Switch case syntax for Svelte ⚡️

License

NotificationsYou must be signed in to change notification settings

l-portet/svelte-switch-case

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Svelte switch case

Switch case syntax for yourSvelte components.

Demo ·StackBlitz ·NPM Package


⚡ Getting started

Step 1: Add the preprocessor to your Svelte project

# Install it:npm i -D svelte-switch-case
// Then, in your svelte.config.jsimportswitchCasefrom'svelte-switch-case';constconfig={preprocess:[switchCase()],};exportdefaultconfig;

Step 2: Start using it in your Svelte components

<!-- Component.svelte --><script>letanimal='dog';</script><section>  {#switch animal}    {:case "cat"}<p>meow</p>    {:case "dog"}<p>woof</p>    {:default}<p>oink?</p>  {/switch}</section>

🔍 How it works

svelte-switch-case transpiles the following code

{#switch animal}  {:case "cat"}<p>meow</p>  {:case "dog"}<p>woof</p>  {:default}<p>oink?</p>{/switch}

intoif/else statements

<!-- Injected by svelte-switch-case -->{#if animal === "cat"}<p>meow</p>{:else if animal === "dog"}<p>woof</p>{:else}<p>oink?</p>{/if}

🙌 Contribute

Found a bug or just had a cool idea? Feel free toopen an issue orsubmit a PR.

About

Switch case syntax for Svelte ⚡️

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp