API
renderRandomTidbit(options)
Section titled “renderRandomTidbit(options)”Renders the next tidbit in the shuffled sequence.
| Option | Type | Default | Description |
|---|---|---|---|
target |
string | HTMLElement |
required | CSS selector or element that receives the tidbit. |
tidbits |
Tidbit[] |
required | Tidbits to shuffle and render. |
useDefaultStyles |
boolean |
true |
Whether to inject the built-in stylesheet. |
Returns the current tidbit and two controls:
{ tidbit: Tidbit; renderNext: () => Tidbit; destroy: () => void;}renderNext()renders and returns the next tidbit.destroy()clears the target.
Tidbit
Section titled “Tidbit”import type { Tidbit } from 'random-tidbit';
type Tidbit = { text: string; attribution?: string;};Text and attribution values are trimmed. Entries without text are ignored. The renderer throws if no valid tidbits remain.
quotes
Section titled “quotes”quotes is an exported Tidbit[] containing the example quote collection. Pass
it explicitly as tidbits when you want to use it.
Persistence
Section titled “Persistence”When available, localStorage stores only sequence indexes.
Each distinct normalized tidbit list receives its own storage key, so different
lists do not interfere with one another. Across reshuffles, at least half of the
collection, rounded down, is rendered before the same tidbit appears again. If
localStorage is unavailable or inaccessible, rendering continues without
persistence and tidbits may repeat.