text-commander
tiny library for text-based interactions (e.g. MUDs, text-based adventure games, etc)
install
npm install text-commander
use
var cmdr = { return `looking at !` } { return `using on !` } console// looking at sun!console// using glove on lever!
(see templateer, on which this is built)
protip you can use es6 destructuring syntax to make your functions a little nicer. e.g.,
var cmdr = { // do stuff... // return stuff... }
api
var cmdr = require('text-commander')([ {'some {template}': ({template}) => { }}, ... ])
text-commander takes a list of objects { templateString: function }
. when templateString
is matched, function
will execute on the the template match. (see templateer, on which this is built)
cmdr('some command')
will try to match each template string, in order, executing the appropriate function if a match is found.
cmdr will pass the match object as arguments to the appropriate function, and return whatever that function returns.
if no match is found, cmdr will return undefined
.
license
BSD