This is a Visual Studio Code extension to help introducing Format.JS into an existing codebase. Select a string or template string then format it automatically to follow formatjs spec.
- Select a string in your code file, including quotes!
- Open the command palette (cmd + shif + P)
- Run the command "Refactor the selected message to formatjs"
Your string is formatted to follow Format.JS specification.
// before
`Hello ${username}`
// after
intl.formatMessage({ defaultMessage: 'Hello {username}' }, { username })This extension supports:
- Literal strings (between single or double quotes)
- Template strings with or without any code expressions
- Multiline template strings
- The built options don't necessarily have a perfect name. Complex code in a template string turns to "optionN".
- If you use the same code twice in a template string, the same option will be generated twice.
- The current version doesn't handle backquotes well.
Additionnally to the strict Format.js API, this extension also comes with a solution for Handlebars templates.
It supposes that you would implement a formatMessage helper that internally relies on Format.js, so you can
also extract and format bare strings in templates.
- Select the exact piece of string you want to be formatted
- Open the command palette (cmd + shif + P)
- Run the command "Refactor the selected HTML with a formatjs-like Handlebars helper"
This extension supports:
- Presence of double quotes in the formatted string
- Insertion of triple curlies to allow HTML in the formatted string
- Multiline strings
- The built options don't necessarily have a perfect name. Complex code in a template string turns to "optionN".
- If you use the same code twice in a handlebars variable, the same option will be generated twice.
- Calls to Handlebars helpers in the formatted piece are not supported.
N/A
- 0.2.0 - Add a command to refactor Handlebars templates.
- 0.1.0 - Supports template strings without code expressions and multiline template strings.
- 0.0.1 - Initial version.