Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Pattern matched Map object in JavaScript.
JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src
.gitignore
LICENSE.markdown
README.md

README.md

PatternMap.js

Documentation coming soon.

Example:

var pmap = new PatternMap({
  "String:^hello":  "Hello Hello!",
  "String":         "A String",
  "Number:->10":    [function (x) { return x > 10; }, "Greater than 10..."],
  "Number:->5":     [function (x) { return x > 5; }, "Greater than 5..."],
  "Number":         "A Number...",
  "Array:->":       [function (a) { return a.length === 4; }, "Array of 4."],
  "Array:3":        "Array of 3.",
  "Array":          "Array."
});

pmap("Hello"); //-> "Hello Hello!"
pmap("Foo"); //-> "A String"
pmap(25); //-> "Greater than 10..."
pmap(10); //-> "Greater than 5..."
pmap(0); //-> "A Number..."
pmap([]); //-> "Array."
pmap([1, 2, 3]); //-> "Array of 3."
pmap([1, 2, 3, 4]); //-> "Array of 4."
Something went wrong with that request. Please try again.