Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/samthor/split-dom
- Owner: samthor
- License: apache-2.0
- Created: 2018-07-25T06:06:33.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-22T02:50:19.000Z (almost 5 years ago)
- Last Synced: 2024-11-17T21:39:12.550Z (3 months ago)
- Topics: dom, html
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```