Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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

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.