Skip to content

Instantly share code, notes, and snippets.

@gausby
Created February 9, 2014 19:23
Show Gist options
  • Save gausby/8904594 to your computer and use it in GitHub Desktop.
Save gausby/8904594 to your computer and use it in GitHub Desktop.
Extending the default Pursuit dictionary with a custom checker function.
// 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