Skip to content

Stream

A Stream is a type of object that can be used to navigate through a string safely, this is used in obscure operations such as parsing FormData, JSON and other things.

Streams are not essential, but they do make things easier as we can avoid tracking the position of a string and instead rely on the Stream to peek, advance and so forth.

Properties

textSource

Stream.textSource  :: string

cursorPosition

Stream.cursorPosition  :: number

Methods

The Stream instance has no set methods!

Functions

peek

Stream . peek (

     self: Stream
     length: number?
)  -> ()

Responsible for peeking further ahead into the stream, without incrementing the cursor position.

advance

Stream . advance (

     self: Stream
     length: number?
)  -> ()

Responsible for advancing the cursor position of the stream, this will increment the cursor position by the amount specified. (defaults to 1)

advanceUntil

Stream . advanceUntil (

     self: Stream
     predicate: (char: string) -> ()
)  -> ()

Responsible for advancing the cursor position of the stream until a predicate is met, this will increment the cursor position by the amount specified.

readUntilEnd

Stream . readUntilEnd (

     self: Stream
)  -> ()

Will read the stream until the end, this will return the remaining text source.

trim

Stream . trim (

     self: Stream
)  -> ()

Trims all whitespaces from the current stream position and onwards

new

Stream . new (

     textSource: string
)  -> ()

Constructor for the Stream object, will return a new instance of the Stream object.