Nozzle is a small TypeScript library for processing text as it arrives from language models or other streaming sources. It accepts synchronous or asynchronous iterables, including streams from common AI providers, and chains transformations without waiting for the full input. Its central design is to emit content as soon as it is safe while temporarily buffering only material whose meaning could change when more text arrives. For example, it can recognize a regular-expression match split across chunks, hold that possible match until confirmed or ruled out, and pass unrelated text downstream immediately. A parsing pipeline can therefore turn matched text into structured values while preserving the surrounding prose.
The library offers tools for regex scanning, matching, parsing and replacement, as well as splitting, filtering, mapping, buffering, timing, accumulation and stream conversion. Examples show extracting a code block for live preview and re-chunking bursty output into steadier word-sized pieces. Its behavior has explicit limits: lookarounds, anchors, word boundaries and other patterns dependent on unseen or arbitrary boundaries are unsupported, while open-ended quantifiers or ambiguous alternatives can delay output. Pipelines are lazy, generator sources can be consumed only once, and breaking iteration closes upstream iterators; errors surface at the awaiting call, though cancellation of provider-side I/O is not guaranteed. Nozzle is useful when applications need responsive, incremental handling of generated text without sacrificing correctness at chunk boundaries.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.