node-action-parser
Extract arbitrary user commands from text strings.
Installation:
npm install --save node-action-parser
Usage:
The library's core function , parseText(), returns an array of objects containing the words surrounding the actionCharacter(s) dictated during initialization.
var ActionParser = ;var parser = "#"; var text = "follow #benjamin";console; // => "[{action: "follow", parameter: "benjamin", ...}]"
Default values can be given.
var ActionParser = ;var parser = "#" defaultAction: "message" ; var text = "#benjamin how's it going?";console; // => "[{action: "message", parameter: "benjamin", value: "how's it going?", ...}]"
Multiple commands at once.
var ActionParser = ;var parser = "@" defaultAction: "message" ; var text = "@benjamin how's it going? @Jamie are you free tonight?";console; // => "[{action: "message", parameter: "benjamin", value: "how's it going?", ...},// {action: "message", parameter: "Jamie", value: "are you free tonight?", ...}]"
Documentation:
The source code uses ES6, Babel, and JSDoc, with auto-generated markdown documentation in the /src directory.
Bugs:
Commands might inherit parts of subsequent commands..
var ActionParser = ;var parser = "@"; var text = "message @benjamin how's it going? message @Jamie are you free tonight?";console; // => "[{action: "message", parameter: "benjamin", value: "how's it going? message", ...},// {action: "message", parameter: "Jamie", value: "are you free tonight?", ...}]"
Contributions:
Welcome! :)
git clone https://github.com/bjones6/node-action-parser.gitnpm install# make improvements gulp build # => build documentation and transpile ES6 in /src to ES5 in /lib npm test # => run tests with mocha to make sure nothing broke
License:
MIT