0.1.1 • Published 7 years ago

babel-plugin-js-pattern-matching v0.1.1

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

Build Status Dependency Status devDependencies Status

Babel Plugin for JS-Pattern-Matching

This is a Babel Plugin intended to make JS-Pattern-Matching compatible with Babel (and, therefore, with non-ES2015 environments)

import match from 'js-pattern-matching';

const sum = (list) =>  match (list) (
  ([x,...xs]) => x + sum(xs),
  ([]) => 0
)

console.log(sum([]));
// prints 0
console.log(sum([1,2,3]));
// prints 6

Installation

npm install --save-dev babel-plugin-js-pattern-matching

To use the plugin, first install it with the above command.

Usage

To use JS-Pattern-Matching together with Babel, just add the plugin to your .babelrc file:

{
  "presets": [
    "es2015"
  ],
  "plugins": [
      "babel-plugin-js-pattern-matching",
  ]
}

Important note about usage

The plugin currently relies on the match function being imported and used with that name. If you import it using another name, it will probably not work. Support for custom names is planned for the next release.