string-scanner v0.0.2
string-scanner
scan through strings. supports forwards and backwards scanning.
Installation
In node.js:
$ npm install string-scannerIn the browser (with component):
$ component install matthewmueller/string-scannerAPI
scanner(str, [offset])
Initialize a scanner for str at the given offset. If no offset is given, default to 0.
var s = scanner('apples, peaches, kiwis', 12);scanner.next(expr, [n])
Scan for the next expr. expr can either be a string or a regex.
Return the nth match. n defaults to 1, or the first match.
s.next(/apples?/) // apples
s.next('peaches') // peachesscanner.prev(expr, [n]), scanner.previous(expr, [n])
Scan for the previous expr. expr can either be a string or a regex.
Return the nth match. n defaults to 1, or the first match.
s.last()
s.prev(/kiwis?/) // kiwis
s.prev('peaches') // peachesscanner.match()
Return the current match. Useful for regex captures.
If no match is found, this function returns null.
s.next(/apples?/)
.match()scanner.peak(expr, [n])
Peak forward or backwards n matches in search of expr.
Peaking does not change the offset.
s.peak(/\w+/, 2) // peaches
s.next(/\w+/, 2) // peachesscanner.cursor([i])
Get or set the cursor within the string.
scanner.last()
Move the cursor to the end of the string
scanner.first()
Move the cursor to the beginning of the string
Test
npm install component-test
make testLicense
MIT