Skip to content

roli93/babel-plugin-js-pattern-matching

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A Plugin to make js-pattern-matching compatible with Babel transforms

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published