babel-plugin-transform-ternary-to-if-else

2.0.1 • Public • Published

babel-plugin-transform-ternary-to-if-else

Build Status Coverage Status

Transform ternary operators (conditional expressions) into if-else statements.

Demo

Live 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-else

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["transform-ternary-to-if-else"]
}

Via CLI

babel --plugins transform-ternary-to-if-else script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-ternary-to-if-else"]
});

Readme

Keywords

Package Sidebar

Install

npm i babel-plugin-transform-ternary-to-if-else

Weekly Downloads

31

Version

2.0.1

License

GPL-3.0

Unpacked Size

41.1 kB

Total Files

6

Last publish

Collaborators

  • opengg