This is a preview for the invert-if
Extension that allows you to quickly and easily invert if blocks, merge nested if blocks, invert conditions and create guard clauses. It also provides the option to generate truth tables to verify update if conditions.
While still in active development, the following features are already available:
Command | Description |
---|---|
Invert If: Invert If Block |
Inverts selected if / else block(s) |
Invert If: Merge selected if block |
Merge selected if / else blocks into a single if block (concatenating the conditions using && ) |
Invert If: Create Guard Clause from Condition |
Creates guard clause for the selected Condition |
Invert If: Create Custom Guard Clause from Condition |
Creates guard clause for the selected Condition with custom options |
Invert If: Invert Condition |
Invert selected condition(s) |
Invert If: Generate truth table |
Generate truth tables for the selected conditions |
Invert If: Invert Condition and compare truth tables |
Invert selected editions and show their truth tables |
The selection is the condition under the active cursors. The commands take into account all cursors, so multiple selections are possible.
Truth tables can be used to compare or analyze if conditions as well as verify the inversion process of the extension. They are provided using a temporary markdown
document:
(1) `a > b || c == d && e !== f`
(2) `a <= b && (c != d || e === f)`
| a > b | c == d | e === f | (1) | (2) |
| ----- | ------ | ------- | ----- | ----- |
| false | false | false | false | true |
| false | false | true | true | false |
| false | true | false | false | true |
| false | true | true | true | false |
| true | false | false | true | false |
| true | false | true | true | false |
| true | true | false | true | false |
| true | true | true | true | false |
To make it possible for tables to be compared, some operators are flipped to their simplest version, e.g. !==
to ==
or <=
to >
.
Currently only the following languages are supported:
javascript
typescript
-
markdown
(embedded code sections in supported languages) -
php
through the Invert Of PHP extension -
vue
through the Invert Of Vue SFC extension
You can add additional language support by providing an extension that registers itself with Invert If
.
Setting | Description | Default |
---|---|---|
truthTableBooleanText |
The text to use for the boolean values in the truth table | { true: "true", false: "false" } |
*truthTableConditionIndex* |
The index text for evaluated conditions in the truth tables | (#1) |
There are most likely a few Bugs, but the tests are in the process of being expanded.
There are currently no feature contributions required, but when you encounter an error or weird behavior feel free to open an issue. I still need a lot of test data to provide solid fixtures for all edge cases.
You can also add additional language support by providing an extension that registers itself with Invert If
.