range-lookup
Version:
Find matching DOM ranges for a given text string
57 lines (33 loc) • 1.11 kB
Markdown
[](https://nodei.co/npm/range-lookup/)
[![Dependency Status][david-badge]][david]
Find all matching DOM [ranges][range] for a given text string.
[][demo]
[]: https://developer.mozilla.org/en-US/docs/Web/API/range
[]: https://eush77.github.io/range-lookup
[]: https://david-dm.org/eush77/range-lookup
[]: https://david-dm.org/eush77/range-lookup.png
```js
var rangeLookup = require('range-lookup');
var ranges = rangeLookup('some string');
ranges
//=> Array [ Range, Range, Range, Range ]
// Highlight ranges.
var selection = window.getSelection();
ranges.forEach(selection.addRange.bind(selection));
```
`query` — string to search for.
Returns array of matching [ranges][range].
Whether to ignore case while attempting a match in a string. Defaults to `false`.
- This module is not capable of matching text that crosses text nodes boundaries.
```
npm install range-lookup
```
MIT