fractional-indexing

Provides functions for generating ordering strings

Usage no npm install needed!

<script type="module">
  import fractionalIndexing from 'https://cdn.skypack.dev/fractional-indexing';
</script>

README

Fractional Indexing

This is based on Implementing Fractional Indexing by David Greenspan .

Fractional indexing is a technique to create an ordering that can be used for Realtime Editing of Ordered Sequences.

This implementation includes variable-length integers, and the prepend/append optimization described in David's article.

This should be byte-for-byte compatible with https://github.com/rocicorp/fracdex.

Usage

import {generateKeyBetween} from "fractional-indexing";

const first = generateKeyBetween(null, null); // "a0"

// Insert after 1st
const second = generateKeyBetween(first, null); // "a1"

// Insert after 2nd
const third = generateKeyBetween(second, null); // "a2"

// Insert before 1st
const zeroth = generateKeyBetween(null, first); // "Zz"

// Insert in between 2nd and 3rd. Midpoint
const secondAndHalf = generateKeyBetween(second, third); // "a1V"