import { bisectShareLink } from '@datamoc/mwg/core';
const notes = Array.from({ length: 500 }, (_, i) => [60 + (i % 12), i]);
const { link, kept } = await bisectShareLink('music', 'game@1.0.0', notes, (items, cut) => ({ cut, items }), {
maxChars: 800,
});
console.log(link.length <= 800, kept < notes.length); // true true
The longest prefix of
itemswhose link fits, found by bisection:buildmakes the payload for a count, and the answer is the largest count that fits (0 is allowed, for a payload with no items). Counts that do not fit are never tried twice.