
9 Code Assists for Strings and Template Literals
Text manipulation has become more powerful with the introduction of template literals in JavaScript. The JS Assistant offers several code actions to help you work with text, be it strings or template literals:
- Convert string comparison chain to array.includes()
Replace
|| value === 'aString'
and&& value !== 'aString'
chains witharray.includes()
. - Convert string to template literal
Convert a string to a basic template literal without expressions.
- Convert template literal to string
Convert a simple template literal without expressions into a string.
- Extract selected text into variable
Extract the selected text (including expressions from template literals) into a
const
variable. - Inline into template
Inline a string or a basic template literal into an outer template literal.
- Remove unnecessary template literal
Simplify a template literal with a single inner expression and no prefix or suffix.
- Use string.endsWith()
string.endsWith()
checks if a string ends with another string. - Use string.startsWith()
string.startsWith()
checks if a string starts with another string. - Merge string concatenation
Merge string and template literal concatenation into a single template literal or string.