0.1.5 • Published 11 years ago

bravo v0.1.5

Weekly downloads
7
License
MIT
Repository
github
Last release
11 years ago

bravo

Build Status Coverage Status npm version Dependency Status

https://www.npmjs.org/package/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

0.1.5

11 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.9

11 years ago

0.0.8

11 years ago

0.0.7

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago