Rebasely Beta: data may be purged

examples/live-notes Public

TypeScript · 23 lines · 814 B · at 27f140d

import { del, insert, type Op } from "../../src/ops.ts";// A small seeded generator (mulberry32) so a failing case can be replayed.export function rng(seed: number): () => number {  let s = seed >>> 0;  return () => {    s = (s + 0x6d2b79f5) >>> 0;    let t = s;    t = Math.imul(t ^ (t >>> 15), t | 1);    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;  };}// A random op that fits `doc`.export function randomOp(doc: string, next: () => number): Op {  const pos = Math.floor(next() * (doc.length + 1));  if (doc.length === pos || next() < 0.5) {    const words = ["a", "bc", "def", "\n", " ", "xyz!"];    return insert(pos, words[Math.floor(next() * words.length)]);  }  return del(pos, 1 + Math.floor(next() * Math.min(4, doc.length - pos)));}