API reference

Interface Chunker<TChunk>

Presents the pieces of text contained in some underlying ‘file’ as a sequence of Chunks.

Rather than presenting a list of all pieces, the Chunker provides methods to walk through the file piece by piece. This permits implementations to read and convert the file to Chunks lazily.

For those familiar with the DOM APIs, it is similar to a NodeIterator (but unlike NodeIterator, it has no concept of being ‘before’ or ‘after’ a chunk).

Type parameters

  • TChunk: Chunk<any>

    (sub)type of Chunk being used.

Hierarchy

  • Chunker

Index

Properties

Readonly currentChunk

currentChunk: TChunk

The chunk currently being pointed at.

Initially, this should normally be the first chunk in the file.

Methods

nextChunk

  • nextChunk(): null | TChunk
  • Point currentChunk at the chunk following it, and return that chunk. If there are no chunks following it, keep currentChunk unchanged and return null.

    Returns null | TChunk

precedesCurrentChunk

  • precedesCurrentChunk(chunk: TChunk): boolean
  • Test if a given chunk is before the current chunk.

    Returns true if chunk is before this.currentChunk, false otherwise (i.e. if chunk follows it or is the current chunk).

    The given chunk need not necessarily be obtained from the same Chunker, but the chunkers would need to represent the same file. Otherwise behaviour is unspecified (an implementation might throw or just return false).

    Parameters

    • chunk: TChunk

      A chunk, typically obtained from the same Chunker.

    Returns boolean

previousChunk

  • previousChunk(): null | TChunk
  • Point currentChunk at the chunk preceding it, and return that chunk. If there are no chunks preceding it, keep currentChunk unchanged and return null.

    Returns null | TChunk