# xpath-range

> A (Browser) Range implementation / wrapper with XPath features, extracted from Annotator

Latest version **1.1.1** (published 2016-09-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install xpath-range
pnpm add xpath-range
yarn add xpath-range
bun add xpath-range
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2016-09-14 |
| First published | 2014-06-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 43 |
| Author | The Annotator project contributors |
| Maintainers | csillag, nickstenning, tilgovi |

## Links

- npm: https://www.npmjs.com/package/xpath-range
- Repository: https://github.com/openannotation/xpath-range
- Issues: https://github.com/openannotation/xpath-range/issues
- npm.io page: https://npm.io/package/xpath-range

## Dependencies (3)

- [dom-seek](https://npm.io/package/dom-seek.md) ^4.0.1
- [get-document](https://npm.io/package/get-document.md) ^1.0.0
- [simple-xpath-position](https://npm.io/package/simple-xpath-position.md) ^2.0.0

## Recent versions

- 1.1.1 (latest) — 2016-09-14
- 1.1.0 — 2015-10-23
- 1.0.1 — 2015-10-20
- 1.0.0 — 2015-10-20
- 0.0.6 — 2014-10-17
- 0.0.5 — 2014-10-07
- 0.0.4 — 2014-06-27
- 0.0.3 — 2014-06-27
- 0.0.2-dev03 — 2014-06-18
- 0.0.2-dev02 — 2014-06-18
- 0.0.2-dev01 — 2014-06-18
- 0.0.2 — 2014-06-18
- 0.0.1-dev08 — 2014-06-18
- 0.0.1-dev07 — 2014-06-18
- 0.0.1-dev06 — 2014-06-18
- … 5 more at https://npm.io/package/xpath-range/versions

## README

# XPath Range

[![Build Status](https://travis-ci.org/openannotation/xpath-range.svg?branch=master)](https://travis-ci.org/openannotation/xpath-range)
[![NPM Package](https://img.shields.io/npm/v/xpath-range.svg)](https://www.npmjs.com/package/xpath-range)
[![Coverage](https://img.shields.io/codecov/c/github/openannotation/xpath-range/master.svg)](https://codecov.io/gh/openannotation/xpath-range)

This module is for describing and resolving a DOM `Range` using XPath.

## Installation

Using npm:

    npm install xpath-range

## Usage

The module provides functions for converting to and from DOM Range objects
using a combination of XPath expressions and text offsets.

The presence of a working XPath evaluator is not strictly required. Without it,
the library will only support XPath expressions that use a child axis and
node names with number literal positions. All XPath expressions generated by
this library fit this description. For instance, the library can generate and
consume an expression like `/html/body/article/p[3]`.

### API

#### `fromRange(range, [root])`

Convert a `Range` to a pair of XPath expressions and offsets.

If the optional parameter `root` is supplied, the computed XPath expressions
will be relative to it.

Returns an object with the following properties:

  - start
  - startOffset
  - end
  - endOffset

#### `toRange(start, startOffset, end, endOffset, [root])`

Construct a `Range` from the given XPath expressions and offsets.

If the optional parameter `root` is supplied, the XPath expressions are
evaluated as relative to it.

Returns a `Range` object.

## Compatibility

This library should work with any browser implementing basic `Range` support.

### Internet Explorer version 8

- Basic support can be achieved with the [rangy][] shim.
- There is no support for namespaces in X(HT)ML documents (issue #17).

## Community

Originally, this code was part of the
[Annotator](http://annotatorjs.org/) project.

Any discussion should happen on the
[annotator-dev](https://lists.okfn.org/mailman/listinfo/annotator-dev) mailing
list.

## Development

To contribute, fork this repository and send a pull request with your changes,
including any necessary test and documentation updates.

## Testing

You can run the command-line test suite by executing `npm test`.

To run the test suite, install the karma test runner with the command
`npm install -g karma-cli` and then run `karma start`. Karma will print
instructions for debugging the tests in a browser.

  [rangy]: https://github.com/timdown/rangy "rangy"

---
_Source: https://npm.io/package/xpath-range · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
