The goal of this library is to provide API that would look like the built-in RegExp class and would let easily write parsers for structures that cannot be parsed with regular expressions, such as XML-like structures, the e-mail pattern, data URL, URI and so on.
To parse a list of comma separated key-value pairs with a parser written as ABNF:
var ABNF = require('llkp/abnf');
var p = new ABNF('1*{","}(key "=" val)', { key: /\w+/, val: /\w+/ }).join(0, 2);
var r = p.exec('charset=utf8,type=text,subtype=html');
assert.deepEqual(r, { charset: 'utf8', type: 'text', subtype: 'html' });
To parse a list of comma separated key-value pairs with a parser written as PEG:
var PEG = require('llkp/peg');
var p = new PEG('(key "=" val)<",">+', { key: /\w+/, val: /\w+/ }).join(0, 2);
var r = p.exec('charset=utf8,type=text,subtype=html');
assert.deepEqual(r, { charset: 'utf8', type: 'text', subtype: 'html' });
Unit tests were written in the mocha's TDD style:
npm install -g mocha
mocha -u tdd
They can be run with npm:
npm test
istanbul
can be used with mocha
's unit tests in the following way (figure out the full path to _mocha
):
npm install -g istanbul
istanbul cover .../npm/node_modules/mocha/bin/_mocha -- -u tdd
It will produce an output like:
Statements : 98.89% ( 356/360 )
Branches : 92.97% ( 172/185 )
Functions : 100% ( 96/96 )
Lines : 98.8% ( 328/332 )
Static analysis is done by JSHint:
npm install -g jshint
jshint --verbose .
This command is mentioned in package.json so it's enough to run npm test
:
npm test
Check out the wiki page.
MIT