babel-plugin-transform-beautifier
raw JSON → 0.1.1 verified Sat Apr 25 auth: no javascript deprecated
A Babel plugin (v0.1.1) that transforms JavaScript conditional expressions (ternary, logical AND/OR) into if/else statements for improved readability. It is a niche tool focused solely on beautifying ternaries, with no updates since 2021 and low maintenance. Unlike general formatters (Prettier) or codemods (jscodeshift), it performs a specific AST transformation. Intended for build-time use in Babel pipelines.
Common errors
error Error: Cannot find module 'babel-plugin-transform-beautifier' ↓
cause Package not installed or missing from node_modules.
fix
Run 'npm install --save-dev babel-plugin-transform-beautifier' and check your babel config plugin name.
error Plugin threw: 'babel-plugin-transform-beautifier' is not a valid plugin ↓
cause Using incorrect import syntax or missing plugin name as string.
fix
In babel.config.js, use plugins: ['babel-plugin-transform-beautifier'] (string, not a function or variable).
Warnings
deprecated Package is unmaintained since 2021. No support for modern Babel (v7.20+). Check for compatibility with your Babel version. ↓
fix Use an alternative like manual refactoring or a custom codemod.
gotcha Only transforms ternary expressions and logical AND/OR in conditional context. Does not beautify other patterns like nested ternaries or switch statements. ↓
fix Review transformed output manually; expected beautification may not apply.
gotcha Plugin may conflict with other Babel plugins that manipulate AST or formatting (e.g., minifiers, other transforms). ↓
fix Ensure plugin order and test output with other plugins in pipeline.
Install
npm install babel-plugin-transform-beautifier yarn add babel-plugin-transform-beautifier pnpm add babel-plugin-transform-beautifier Imports
- default export wrong
import beautifier from 'babel-plugin-transform-beautifier'correctmodule.exports = { plugins: ['babel-plugin-transform-beautifier'] }
Quickstart
// Install: npm i --save-dev babel-plugin-transform-beautifier
// babel.config.js
module.exports = {
plugins: ['babel-plugin-transform-beautifier']
}