Utilities class

Utility functions for manipulating .

Methods

formatCitationsResponse(string)

Convert citation tags [doc(s)n] to [n] where n is a number.

getUsedCitations(string, ClientCitation[])

Get the citations used in the text. This will remove any citations that are included in the citations array from the response but not referenced in the text.

snippet(string, number)

Clips the text to a maximum length in case it exceeds the limit.

toString(Tokenizer, any, boolean)

Converts a value to a string.

Method Details

formatCitationsResponse(string)

Convert citation tags [doc(s)n] to [n] where n is a number.

static function formatCitationsResponse(text: string): string

Parameters

text

string

The text to format.

Returns

string

The formatted text.

getUsedCitations(string, ClientCitation[])

Get the citations used in the text. This will remove any citations that are included in the citations array from the response but not referenced in the text.

static function getUsedCitations(text: string, citations: ClientCitation[]): undefined | ClientCitation[]

Parameters

text

string

The text to search for citation references, i.e. [1], [2], etc.

citations

ClientCitation[]

The list of citations to search for.

Returns

undefined | ClientCitation[]

The list of citations used in the text.

snippet(string, number)

Clips the text to a maximum length in case it exceeds the limit.

static function snippet(text: string, maxLength: number): string

Parameters

text

string

The text to clip.

maxLength

number

The maximum length of the text to return, cutting off the last whole word.

Returns

string

The modified text

toString(Tokenizer, any, boolean)

Converts a value to a string.

static function toString(tokenizer: Tokenizer, value: any, asJSON?: boolean): string

Parameters

tokenizer
Tokenizer

Tokenizer to use for encoding.

value

any

Value to convert.

asJSON

boolean

Optional. If true objects will always be converted to JSON instead of YAML. Defaults to false.

Returns

string

Converted value.

Remarks

Dates are converted to ISO strings and Objects are converted to JSON or YAML, whichever is shorter.