Have ideas to improve npm?Join in the discussion! »

    fractional-indexing
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.0 • Public • Published

    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"

    Install

    npm i fractional-indexing

    DownloadsWeekly Downloads

    132

    Version

    2.0.0

    License

    CC0-1.0

    Unpacked Size

    27.6 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar
    • avatar