Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qiushiyan/range-serializer
Serialize and deserialize browser `Range` objects
https://github.com/qiushiyan/range-serializer
Last synced: about 2 months ago
JSON representation
Serialize and deserialize browser `Range` objects
- Host: GitHub
- URL: https://github.com/qiushiyan/range-serializer
- Owner: qiushiyan
- Created: 2023-09-02T11:33:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-02T11:37:59.000Z (over 1 year ago)
- Last Synced: 2024-10-31T17:46:17.295Z (2 months ago)
- Language: TypeScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rangy-serializer
A library for serializing and deserializing browser `Range` objects.
```javascript
const range = window.getSelection().getRangeAt(0);
const serialized = serializeRange(range);
const deserialized = deserializeRange(serialized);// by default serialization is done relative to the top level Document object
// can also serialize and deserialize relative to a specific node
const serialized2 = serializeRange(range, document.getElementById("main"));
const deserialized2 = deserializeRange(serialized2, document.getElementById("main"));
```The code is based on the [rangy](https://timdown/rangy) library (specifically the [`rangy/lib/rangy-serializer`](https://github.com/timdown/rangy/blob/master/lib/rangy-serializer.js) module). This library refactors it with modern ES syntax and TypeScript.