npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

match-toy

v3.0.3

Published

The pattern matching library for javascript

Downloads

443

Readme

Match-Toy

Build Status Test Coverage Greenkeeper badge npm version Try match-toy on RunKit

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:

Try it now.

Installation

From NPM

$ npm install match-toy --save

Or yarn:

$ yarn add match-toy

Then import/require the module.

const { match } = require('match-toy');
// or
import { match } from 'match-toy';

From CDN

Place the snippet into your html:

<script src="https://cdn.jsdelivr.net/npm/match-toy/dist/bundle/index.min.js"></script>

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/[email protected]/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 = matchToy.match
                      .case('1', () => 'one')
                      .end()

See more in examples.

Usage

Most basic usage:

import { match } from 'match-toy';

// Create a new pattern matching function
const convertOneToString = match
  .case('1', () => 'one')
  .end();

convertOneToString(1); // return 'one'
convertOneToString(2); // return undefined

// Create another one, but now we only need
// the value returned by the match
const one = match
  .case('1', () => 'one')
  .return(1); // 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.