Wondering what’s next for npm?Check out our public roadmap! »

dom-anchor-text-position

5.0.0 • Public • Published

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.

If the start or end offsets are outside the range of valid character offsets within the text content of the root node, an exception is thrown.

Install

npm i dom-anchor-text-position

DownloadsWeekly Downloads

2,324

Version

5.0.0

License

MIT

Unpacked Size

27.3 kB

Total Files

15

Last publish

Collaborators

  • avatar