0.2.1 • Published 4 years ago

babel-plugin-transform-reduce v0.2.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

babel-plugin-transform-reduce

Turns this

const fn = () => [1, 2, 3].filter(i => i > 1).map(i => i * 3)

Into this

const fn = () => {
  const _filterFn = (i) => i > 1
  const _mapFn = (i) => i * 3

  const _reducer = (_acc, _curr) => {
    if (_filterFn(_curr)) {
      _acc.push(_mapFn(_curr, _acc.length))
    }

    return _acc
  }

  return [1, 2, 3].reduce(_reducer, [])
}

Because it's way faster, but less readable. So I've created this plugin to deal with it: it transforms .filter() + .map() calls to .reduce() under the hood!

Usage:

yarn add babel-plugin-transform-reduce --dev

then, in your .babelrc:

{
  "plugins": ["transform-reduce"]
}

You're all set!

License

MIT

0.2.1

4 years ago

0.2.0

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago