# dom-string-wrapper

> Creates a Range that wraps a specified string

Latest version **1.0.0** (published 2016-05-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install dom-string-wrapper
pnpm add dom-string-wrapper
yarn add dom-string-wrapper
bun add dom-string-wrapper
```

## 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.0.0 |
| Published | 2016-05-06 |
| First published | 2016-05-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Guylian Cox |
| Maintainers | ephys |
| Keywords | DOM |

## Links

- npm: https://www.npmjs.com/package/dom-string-wrapper
- Repository: https://github.com/Ephys/dom-string-wrapper
- Homepage: https://github.com/Ephys/dom-string-wrapper#readme
- Issues: https://github.com/Ephys/dom-string-wrapper/issues
- npm.io page: https://npm.io/package/dom-string-wrapper

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-05-06

## README

# dom-text-finder

Utilitary functions to manipulate a DOM Node's textContent without damaging (reseting) its existing child nodes.

## Installation

`npm install --save dom-string-wrapper`

## Usage

The package provides 2 functions: `wrapText` and `wrapTextAll`, the first one returns a [`Range`](https://developer.mozilla.org/en/docs/Web/API/Range), the second one returns an array of `Range`s. They allow you to create a range that will wrap a part of a node's textContent.

```
/* For instance, let's take the following node */
var pNode = document.createElement('p');
var pNode.innerHTML = '<span>Well, <strong>Hello</strong> world :)</span>';

/* and add an event listener to the span child. */
pNode.querySelector('strong').addEventListener('hover', doSomethingImportant);

/* let's now say that we wish to wrap Hello World in a Anchor node, we could do the following: */
var pNode.innerHTML = '<span>Well, <a href="..."><strong>Hello</strong> world</a> :)</span>';

/* But that would reset the whole content and we would lose the event listener we added on <strong>.
 * That's where this module comes in. You can achieve the same goal without resetting anything. */
var wrapText = require('dom-string-wrapper').wrapText;

// returns a range wrapping '<strong>Hello</strong> world'
var range = wrapText(pNode, 'Hello world');

/* You can then use the native range methods to manipulate the content. In this case, we need surroundContents. */
var aNode = document.createElement('a');
aNode.href = '...';
range.surroundContents(aNode);
```

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