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
Node
var Consumed = ;
Browser
Serve dist/consumed.js
or dist/consumed.min.js
:
This script is only 446 bytes!
Example
var consumer = 'foo bar baz'; // Get up to the first instance of a lettervar match = consumer;console; // 'foo 'console; // 'bar baz' // Get up to the first instance of a letter, but include that lettermatch = consumer;console; // 'bar b'console; // 'az' // Or match a patternconsumer = 'foo bar baz';match = consumer;console; // 'foo'console; // ' bar baz'
Contributing
Please see the contribution guidelines.