bravo
v0.1.5
Published
simplified Regular Expression pattern match framework based on RegExp.
Downloads
26
Maintainers
Readme
bravo
simplified Regular Expression pattern match framework based on RegExp.
Requirements
- Node 0.10+
- Able to write regular expression
Installation
$ npm install bravo
Run
- HTML input:
- JSON-like configuration file:
- {expr} represents either regular expression string, or an array composed of : [{ expr:"", g:1},...]
- {g} represents either the group number of the RegExp; return the all groups if {g} absent; it should not exist when {expr} was an array.
- {sep} represents a separator be used to concatenate result when {expr} was an array.
- {replace} is used for result substitution, it could be either an array or an object whose contains two fields : {a} represent source, and {b} represent destination.
{
"title": {
"expr": "<title>([^<]+)</title>",
"g": 1
},
"heading": {
"expr": "<div class=\"wrapper\">\\s+<h1>([^<]+)</h1>",
"g": 1,
"replace": [
{
"a": "\\\\r\\\\n",
"b": ""
},
{
"a": "example",
"b": "awesome"
}
]
},
"titleAndheading": {
"expr": [
{
"expr": "<title>([^<]+)</title>",
"g": 1
},
{
"expr": "<div class=\"wrapper\">\\s+<h1>([^<]+)</h1>",
"g": 1
}
],
"sep": " - ",
"replace": [
{
"a": "\\\\r\\\\n",
"b": ""
},
{
"a": "example",
"b": "awesome"
}
]
}
}
- Invocation:
//var html = readFromFile();
var request = require('bravo');
var jsonFile = path.join(process.cwd(), 'example.json');
var obj = bravo.Parse(jsonFile, html);
console.log(obj)
});
- Result is a object which had been defined in the JSON file:
{ title: 'rockdragon/bravo',
heading: 'awesome repository.',
titleAndheading: 'rockdragon/bravo - awesome repository.' }
License
MIT