position-strings
Version:
Lexicographically-ordered position strings for collaborative lists and text
56 lines (55 loc) • 2.04 kB
TypeScript
import type seedrandom from "seedrandom";
/**
* Utitilies for generating `PositionSource` IDs
* (the `options.ID` constructor argument).
*/
export declare class IDs {
private constructor();
/**
* Default characters used in IDs: alphanumeric chars.
*/
static readonly DEFAULT_CHARS: string;
/**
* The default length of an ID, in characters.
*/
static readonly DEFAULT_LENGTH: number;
/**
* Returns a cryptographically random ID made of alphanumeric characters.
*
* @param options.length The length of the ID, in characters.
* Default: `IDs.DEFAULT_LENGTH`.
* @param options.chars The characters to draw from. Default: `IDs.DEFAULT_CHARS`.
*
* If specified, only the first 256 elements are used, and you achieve
* about `log_2(chars.length)` bits of entropy per `length`.
*/
static random(options?: {
length?: number;
chars?: string;
}): string;
/**
* Returns a psuedorandom ID made of alphanumeric characters,
* generated using `rng` from package [seedrandom](https://www.npmjs.com/package/seedrandom).
*
* Pseudorandom IDs with a fixed seed are recommended for
* tests and benchmarks, to make them deterministic.
*
* @param options.length The length of the ID, in characters.
* Default: `IDs.DEFAULT_LENGTH`.
* @param options.chars The characters to draw from. Default: `IDs.DEFAULT_CHARS`.
*
* If specified, only the first 256 elements are used, and you achieve
* about `log_2(chars.length)` bits of entropy per `length`.
*/
static pseudoRandom(rng: seedrandom.prng, options?: {
length?: number;
chars?: string;
}): string;
/**
* Throws an error if `ID` does not satisfy the
* following requirements from `PositionSource`'s constructor:
* - It does not contain `','` or `'.'`.
* - The first character is lexicographically less than `'~'` (code point 126).
*/
static validate(ID: string): void;
}