Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
fractional-indexing
Advanced tools
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.
generateKeyBetween
Generate a single key in between two points.
generateKeyBetween(
a: string | null | undefined, // start
b: string | null | undefined, // end
digits?: string | undefined = BASE_62_DIGITS, // optional character encoding
): string;
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"
generateNKeysBetween
Use this when generating multiple keys at some known position, as it spaces out indexes more evenly and leads to shorter keys.
generateNKeysBetween(
a: string | null | undefined, // start
b: string | null | undefined, // end
n: number // number of keys to generate evenly between start and end
digits?: string | undefined = BASE_62_DIGITS, // optional character encoding
): string[];
import { generateNKeysBetween } from 'fractional-indexing';
const first = generateNKeysBetween(null, null, 2); // ['a0', 'a1']
// Insert two keys after 2nd
generateNKeysBetween(first[1], null, 2); // ['a2', 'a3']
// Insert two keys before 1st
generateNKeysBetween(null, first[0], 2); // ['Zy', 'Zz']
// Insert two keys in between 1st and 2nd (midpoints)
generateNKeysBetween(second, third, 2); // ['a0G', 'a0V']
These should be byte-for-byte compatible.
Language | Repo |
---|---|
Go | https://github.com/rocicorp/fracdex |
Python | https://github.com/httpie/fractional-indexing-python |
FAQs
Provides functions for generating ordering strings
The npm package fractional-indexing receives a total of 111,209 weekly downloads. As such, fractional-indexing popularity was classified as popular.
We found that fractional-indexing demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.