2.0.1 • Published 4 years ago
babel-plugin-transform-ternary-to-if-else v2.0.1
babel-plugin-transform-ternary-to-if-else
Transform ternary operators (conditional expressions) into if-else statements.
Demo
Example
In
const val = a1 ? a2 : a3;Out
const val = function() {
if (a1) {
return a2;
}
return a3;
}();Installation
npm install babel-plugin-transform-ternary-to-if-elseUsage
Via .babelrc (Recommended)
.babelrc
{
"plugins": ["transform-ternary-to-if-else"]
}Via CLI
babel --plugins transform-ternary-to-if-else script.jsVia Node API
require("babel-core").transform("code", {
plugins: ["transform-ternary-to-if-else"]
});