0.1.2 • Published 10 years ago

character-iterator v0.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

character-iterator

Iterate through text characters in the DOM tree. Handles parent & sibling relationships.

Installation

Install with component(1):

$ component install matthewmueller/character-iterator

Example

var el = domify('<p>hi<u></u> there, <strong>cowboy <em>dude</em>!</strong>!</p>');
var it = iterator(el.querySelector('em'), 2)
assert('d' == it.next());
assert('e' == it.next());
assert('!' == it.next());
assert('!' == it.next());

API

iterator(el, [offset], [root])

Get the next character in the DOM starting at el with offset. If offset isn't specified it starts at 0. You can also set an optional root to contain the iterator.

iterator#next()

Move on to the next character. If at the end, return null.

iterator#prev()

Move on to the previous character. If at the end, return null.

Test

npm install component-test
make test

License

MIT

0.1.2

10 years ago

0.1.1

10 years ago