Created
February 9, 2014 19:23
-
-
Save gausby/8904594 to your computer and use it in GitHub Desktop.
Extending the default Pursuit dictionary with a custom checker function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm install pursuit-core | |
// npm install pursuit-dictionary | |
var pursuitCore = require('pursuit-core'), | |
dictionary = require('pursuit-dictionary') | |
; | |
// add a random function to the dictionary | |
dictionary.random = function() { | |
return 'Math.random() - 0.5 > 0 ? true : false'; | |
} | |
// compile the language using the extended dictionary | |
var compile = pursuitCore({ | |
dictionary: dictionary | |
}); | |
// using the new function | |
var customMatcher = compile({ | |
random: '' | |
}); | |
// this list will return a list of 'foo', 'bar' and 'baz', or [] at random | |
console.log(['foo', 'bar', 'baz'].filter(customMatcher)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment