babel-plugin-comparison-chaining

1.0.6 • Public • Published

babel-plugin-comparison-chaining

Unlike the discipline of mathematics, JavaScript interpreters don't recognize chains of comparison operators as a linear sequence, but as recursive calls compare the right-most node and everything to the left of the operator. If a developer wishes to write conditionally chained expressions that are linearly evaluated, this plugin is of use.

Examples

JavaScript will recursively evaluate the right-most node compared against whatever is on the left.

// written
1 < 6 < 4 < 2 < 7

//evaluated
   (1 < 6 < 4 < 2) < 7 
  ((1 < 6 < 4) < 2) < 7
 (((1 < 6) < 4) < 2) < 7
((((1) < 6) < 4) < 2) < 7

Written expression evaluated linearly

1 < 6 && 6 < 4 && 4 < 2 && 2 < 7;

Installation

$ npm install --save-dev babel-plugin-comparison-chaining

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["comparison-chaining"]
}

Via CLI

$ babel --plugins comparison-chaining script.js

Via Node API

require('babel-core').transform('code', {
  plugins: ['comparison-chaining']
});

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i babel-plugin-comparison-chaining

Weekly Downloads

2

Version

1.0.6

License

MIT

Unpacked Size

6.46 kB

Total Files

9

Last publish

Collaborators

  • samparsons