node-action-parser

1.0.1 • Public • Published

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 = require("node-action-parser");
var parser = new ActionParser("#");
 
var text = "follow #benjamin";
console.log(parser.parseText(text)); // => "[{action: "follow", parameter: "benjamin", ...}]"

Default values can be given.

var ActionParser = require("node-action-parser");
var parser = new ActionParser("#", { defaultAction: "message" });
 
var text = "#benjamin how's it going?";
console.log(parser.parseText(text)); // => "[{action: "message", parameter: "benjamin", value: "how's it going?", ...}]" 

Multiple commands at once.

var ActionParser = require("node-action-parser");
var parser = new ActionParser("@", { defaultAction: "message" });
 
var text = "@benjamin how's it going? @Jamie are you free tonight?";
console.log(parser.parseText(text)); 
// => "[{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 = require("node-action-parser");
var parser = new ActionParser("@");
 
var text = "message @benjamin how's it going? message @Jamie are you free tonight?";
console.log(parser.parseText(text)); 
// => "[{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.git
npm 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

Readme

Keywords

none

Package Sidebar

Install

npm i node-action-parser

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • bjones6