Skip to main content

@rbxts/expect > ExpectMessageBuilder > encode

ExpectMessageBuilder.encode() method

Encodes a value to a string, in the same way this instance would.

Signature:

encode(value: unknown, valueType?: string, overrideOptions?: Partial<ExpectMessageBuilderOptions>, array?: boolean, collapsable?: boolean, collapseLength?: number): string;

Parameters

Parameter

Type

Description

value

unknown

The value of variable to encode.

valueType

string

(Optional) A string representing the type of the variable to encode. Defaults to the typeOf of the value.

overrideOptions

Partial<ExpectMessageBuilderOptions>

(Optional) Provide overrides for the existing options on this instance.

array

boolean

(Optional) Is the value an array? This is used for formatting purposes. Defaults to false.

collapsable

boolean

(Optional) Should we collapse the value if it exceeds the collapseLength? Defaults to false.

collapseLength

number

(Optional) Provide a length for when the string output should be collapsed. Defaults to the collapseLength defined in the default config, at the time of the call.

Returns:

string

A string that can be used in-place of the variable.

Remarks

You won't generally need this, but it can come in handy when you need to display extra values, and want to ensure their format is the same as the VariableData attached to this message.

Internally, this uses a local weak table for encoding. This means that you can safely re-call this method with the same value, but different settings, and you won't take a performance hit for large objects.

Example

print(message.encode(5, "string"))

Output:

"5"