1.0.6 • Published 3 years ago

babel-plugin-comparison-chaining v1.0.6

Weekly downloads
10
License
MIT
Repository
github
Last release
3 years ago

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

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago