consumed
Easy string consumption for parsing and lexing.
Installation
npm install --save consumed
Summary
Create a new instance of the Consumed object and pass in a string. Then you can use a single letter or a regex pattern to grab part of the string and remove it from the original.
Usage
var Consumed = require('consumed');
var consumer = new Consumed('foo bar baz');
var match = consumer.consumeTill('b');
console.log(match);
console.log(consumer.str);
match = consumer.consumeTill('b', true);
console.log(match);
console.log(consumer.str);
consumer = new Consumed('foo bar baz');
match = consumer.consume(/.*(.)\1/);
console.log(match);
console.log(consumer.str);
Contributing
I'll be happy to merge any pull request that adds value and has passing tests. Be sure to add a test both for node and for the browser. Tests are run with grunt
.