01 · Before and afterThe pattern
// before: 0 is falsy, so "start at 0" silently becomes "start at latest"
const cursor = startIndex ? String(startIndex - 1) : undefined;
// after: an explicit start always wins, and 0 means "no cursor, from the beginning"
const hasStart = startIndex !== undefined;
const cursor = hasStart && startIndex > 0 ? String(startIndex - 1) : undefined;
const from = hasStart ? undefined : options.from;02 · Run it on your appThe check
Do any of your API options treat 0 or an empty string as “not provided”?
If the honest answer is no or not sure, this is worth a look before it reaches production.