Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/samthor/split-dom

Helper JavaScript to split DOM nodes within text
https://github.com/samthor/split-dom

dom html

Last synced: 17 days ago
JSON representation

Helper JavaScript to split DOM nodes within text

Awesome Lists containing this project

README

        

Helper to split DOM nodes at a position within text.
This is not published anywhere.

Create a `SliceIndex` if you'll be doing this a lot, otherwise, you can just use the top-level `slice` method.

Usage:

```js
import {SliceIndex, slice} from './path/to/split.js';

const dom = `

Hello There
`;

// #1: SliceIndex
const index = new SliceIndex(dom); // accepts node (cloned) or string
index.slice(0, 4); // `

Hell
`
index.slice(8); // `
ere
`

// #2: slice()
const node = document.createElement('div');
node.innerHTML = dom;
slice(node, 0, 4); // same as above, but not indexed and without copy
```