/dom-anchor-text-position

Convert between DOM Range instances and text positions.

Primary LanguageJavaScriptMIT LicenseMIT

Text Position Anchor

License NPM Package Build Status codecov

This library offers conversion between a DOM Range instance and a text position selector as defined by the Web Annotation Data Model.

For more information on Range see the documentation.

For more information on the text position selector see the specification.

Installation

To require('dom-anchor-text-position'):

npm install dom-anchor-text-position

Usage

API Documentation

The module exposes only two functions.

fromRange(root, range)

Provided with an existing Range instance this will return an object that stores the offsets of the beginning and end of the text selected by the range as measured from the beginning of the root Node.

toRange(root, selector = {start, end})

This method returns a Range object that covers the interval [start, end) of the text content of the root Node.

If the end is not provided, returns a collapsed range. If the start is not provided, the default is 0.