Match-Toy
The pattern matching library for javascript.
Match-Toy is a pattern matching library for javascript with a powerful DSL and support for a wide range of patterns. The best kick off is read the tests, there are tons of them covering all the cases. For complete documentation, please check out the wiki. Another way is by examples:
Installation
From NPM
$ npm install match-toy --save
Or yarn:
$ yarn add match-toy
Then import/require the module.
const match = ;// or;
From CDN
Place the snippet into your html:
For specific version append the desired version (on the format @x.x.x
) before the word match-toy
just like this: https://cdn.jsdelivr.net/npm/match-toy@2.0.1/dist/bundle/index.min.js
.
This file is a bundle in the UMD format. In browser's environments, the module name is in camelcase and available on window
scope.
var myFunc = matchToymatch
See more in examples.
Usage
Most basic usage:
; // Create a new pattern matching functionconst convertOneToString = match ; ; // return 'one'; // return undefined // Create another one, but now we only need// the value returned by the matchconst one = match ; // using `return()` match runs immediately one === 'one'; // true
See more about usage in depth.
Built with
Other nice projects and initiatives
Syntax proposals:
- https://github.com/tc39/proposal-pattern-matching
- https://github.com/eborden/JS-Pattern-Matching
- https://gist.github.com/bterlson/da8f02b95b484cd4f8d9
Other JavaScript libraries:
- https://codemix.github.io/flow-runtime/#/docs/pattern-matching
- https://github.com/HerringtonDarkholme/Pat-Mat
- https://github.com/natefaubion/sparkler
- https://github.com/bramstein/funcy
- https://github.com/FGRibreau/match-when
- https://github.com/z-pattern-matching/z
- https://github.com/dherman/pattern-match
- https://github.com/mcollina/bloomrun
Contributing
- Improving or correcting the documentation.
- Translating.
- Finding bugs
- Sharing this project.
- PR are very welcome.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG file for details.