Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>SwapTernaryNew to Visual Studio Code? Get it now.

SwapTernary

256hz

|
189 installs
| (0) | Free
Swap the outcome of a ternary.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

SwapTernary

Features

This extension automatically swaps the logic in a ternary expression for you. It will preserve formatting/whitespace, and a semicolon at the end, if included.

Supports nested ternaries. ? and : are ignored in strings. // and /* */ comments are ignored. It will show an error if the ternary won't resolve (unbalanced if/then, unterminated string).

Demos



Usage

  1. Highlight ternary (nothing after the ternary except a ; or formatting)
  2. Hit ⇧⌥s (shift + alt + s)

Known Issues

  • Comments are grouped with the condition that precedes them, so they will not switch with the true/false cases.
  • Testing that the error message is shown is not done, pending finding a way to mock some VS Code internals properly.

Release Notes

0.3.0

  • Add support for Typscript ?. operator
  • Ignore // and /* */ comments (fix single quotes in comments breaking parse)

0.1.7

Add keyboard shortcut

0.1.1

Initial release

  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2022 Microsoft