{"id":20192776,"url":"https://github.com/rocicorp/fractional-indexing","last_synced_at":"2025-05-14T16:10:41.708Z","repository":{"id":41835731,"uuid":"310685910","full_name":"rocicorp/fractional-indexing","owner":"rocicorp","description":"Fractional Indexing in JavaScript","archived":false,"fork":false,"pushed_at":"2024-12-09T22:43:50.000Z","size":37,"stargazers_count":359,"open_issues_count":2,"forks_count":25,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-06T16:02:49.995Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npmjs.com/fractional-indexing","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rocicorp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-06T19:16:20.000Z","updated_at":"2025-04-03T08:37:55.000Z","dependencies_parsed_at":"2024-12-28T22:01:31.605Z","dependency_job_id":"2a12f87d-f465-4f4d-8360-d8df641af265","html_url":"https://github.com/rocicorp/fractional-indexing","commit_stats":{"total_commits":38,"total_committers":8,"mean_commits":4.75,"dds":0.368421052631579,"last_synced_commit":"89f811086386847d639480028ef83357d00dc15d"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocicorp%2Ffractional-indexing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocicorp%2Ffractional-indexing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocicorp%2Ffractional-indexing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocicorp%2Ffractional-indexing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rocicorp","download_url":"https://codeload.github.com/rocicorp/fractional-indexing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248759398,"owners_count":21157150,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T04:01:09.858Z","updated_at":"2025-04-13T18:25:25.089Z","avatar_url":"https://github.com/rocicorp.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Fractional Indexing\n\nThis is based on [Implementing Fractional Indexing\n](https://observablehq.com/@dgreensp/implementing-fractional-indexing) by [David Greenspan\n](https://github.com/dgreensp).\n\nFractional indexing is a technique to create an ordering that can be used for [Realtime Editing of Ordered Sequences](https://www.figma.com/blog/realtime-editing-of-ordered-sequences/).\n\nThis implementation includes variable-length integers, and the prepend/append optimization described in David's article.\n\n## API\n\n### `generateKeyBetween`\n\nGenerate a single key in between two points.\n\n```ts\ngenerateKeyBetween(\n  a: string | null | undefined, // start\n  b: string | null | undefined, // end\n  digits?: string | undefined = BASE_62_DIGITS, // optional character encoding\n): string;\n```\n\n```ts\nimport { generateKeyBetween } from 'fractional-indexing';\n\nconst first = generateKeyBetween(null, null); // \"a0\"\n\n// Insert after 1st\nconst second = generateKeyBetween(first, null); // \"a1\"\n\n// Insert after 2nd\nconst third = generateKeyBetween(second, null); // \"a2\"\n\n// Insert before 1st\nconst zeroth = generateKeyBetween(null, first); // \"Zz\"\n\n// Insert in between 2nd and 3rd (midpoint)\nconst secondAndHalf = generateKeyBetween(second, third); // \"a1V\"\n```\n\n### `generateNKeysBetween`\n\nUse this when generating multiple keys at some known position, as it spaces out indexes more evenly and leads to shorter keys.\n\n```ts\ngenerateNKeysBetween(\n  a: string | null | undefined, // start\n  b: string | null | undefined, // end\n  n: number // number of keys to generate evenly between start and end\n  digits?: string | undefined = BASE_62_DIGITS, // optional character encoding\n): string[];\n```\n\n```ts\nimport { generateNKeysBetween } from 'fractional-indexing';\n\nconst first = generateNKeysBetween(null, null, 2); // ['a0', 'a1']\n\n// Insert two keys after 2nd\ngenerateNKeysBetween(first[1], null, 2); // ['a2', 'a3']\n\n// Insert two keys before 1st\ngenerateNKeysBetween(null, first[0], 2); // ['Zy', 'Zz']\n\n// Insert two keys in between 1st and 2nd (midpoints)\ngenerateNKeysBetween(second, third, 2); // ['a0G', 'a0V']\n```\n\n\n## Other Languages\n\nThese should be byte-for-byte compatible.\n\n| Language | Repo                                                  |\n| -------- | ----------------------------------------------------- |\n| Go       | https://github.com/rocicorp/fracdex                   |\n| Python   | https://github.com/httpie/fractional-indexing-python  |\n| Kotlin   | https://github.com/darvelo/fractional-indexing-kotlin |\n| Ruby     | https://github.com/kazu-2020/fractional_indexer       |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocicorp%2Ffractional-indexing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frocicorp%2Ffractional-indexing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocicorp%2Ffractional-indexing/lists"}