bravo

    0.1.5 • Public • Published

    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:
    <head>
        <title>rockdragon/bravo</title>
    </head>
    <body>
    <div class="wrapper">
        <h1>example repository.\r\n</h1>
    </div>
    
    • 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

    Install

    npm i bravo

    DownloadsWeekly Downloads

    4

    Version

    0.1.5

    License

    MIT

    Last publish

    Collaborators

    • moyerock