scan through strings. supports forwards and backwards scanning.
In node.js:
$ npm install string-scanner
In the browser (with component):
$ component install matthewmueller/string-scanner
Initialize a scanner
for str
at the given offset
. If no offset
is given, default to 0
.
var s = scanner('apples, peaches, kiwis', 12);
Scan for the next expr
. expr
can either be a string or a regex.
Return the n
th match. n
defaults to 1, or the first match.
s.next(/apples?/) // apples
s.next('peaches') // peaches
Scan for the previous expr
. expr
can either be a string or a regex.
Return the n
th match. n
defaults to 1, or the first match.
s.last()
s.prev(/kiwis?/) // kiwis
s.prev('peaches') // peaches
Return the current match. Useful for regex captures.
If no match is found, this function returns null
.
s.next(/apples?/)
.match()
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) // peaches
Get or set the cursor within the string.
Move the cursor to the end of the string
Move the cursor to the beginning of the string
npm install component-test
make test
MIT