Util

Types

# NamedObject

interface NamedObject {
Name: string
}

Any object with a Name property.

Static Functions

# MakeDictionary static

Util.MakeDictionary(array: array<T>) → dictionary<T, true>

Accepts an array and flips it into a dictionary, its values becoming keys in the dictionary with the value of true.

Parameters

Name Type Required
array array<T>

Returns

Type
dictionary<T, true>

# Map static

Util.Map(

array: array<T>,
mapper: function(
value: T,
index: number
) → U
) → array<U>

Maps values from one array to a new array. Passes each value through the given callback and uses its return value in the same position in the new array.

Parameters

Name Type Required
array array<T>
mapper

function(

value: T,
index: number
) → U

Details

Parameters

Name Type Required
value T
index number

Returns

Type
U

Returns

Type
array<U>

# Each static

Util.Each(

mapper: function(value: T) → U,
...: T
) → U...

Maps arguments #2-n through callback and returns all values as tuple.

Parameters

Name Type Required
mapper

function(value: T) → U

Details

Parameters

Name Type Required
value T

Returns

Type
U
... T

Returns

Type
U...

# MakeFuzzyFinder static

Util.MakeFuzzyFinder(set:

   array<string>
|
array<Instance>
|
array<EnumItem>
|
array<NamedObject>
|
Instance
) → function(
text: string,
returnFirst?: boolean?
) → any

Makes a fuzzy finder for the given set or container. You can pass an array of strings, array of instances, array of EnumItems, array of dictionaries with a Name key or an instance (in which case its children will be used).

Parameters

Name Type Required
set

#

   array<string>
|
array<Instance>
|
array<EnumItem>
|
array<NamedObject>
|
Instance

Returns

Type

function(

text: string,
returnFirst?: boolean?
) → any

Details

Parameters

Name Type Required
text string
returnFirst boolean?

Returns

Type
any

Accepts a string and returns a table of matching objects. Exact matches are inserted in the front of the resultant array.

# GetNames static

Util.GetNames(instances: array<NamedObject>) → array<string>

Accepts an array of instances (or anything with a Name property) and maps them into an array of their names.

Parameters

Name Type Required
instances array<NamedObject>

Returns

Type
array<string>

# SplitStringSimple static

Util.SplitStringSimple(

text: string,
separator: string
) → array<string>

Slits a string into an array split by the given separator.

Parameters

Name Type Required
text string
separator string

Returns

Type
array<string>

# SplitString static

Util.SplitString(

text: string,
max?: number?
) → array<string>

Splits a string by spaces, but taking double-quoted sequences into account which will be treated as a single value.

Parameters

Name Type Required
text string
max number?

Returns

Type
array<string>

# TrimString static

Util.TrimString(text: string) → string

Trims whitespace from both sides of a string.

Parameters

Name Type Required
text string

Returns

Type
string

# GetTextSize static

Util.GetTextSize(

text: string,
label: TextLabel,
size?: Vector2?
) → Vector2

Returns the text bounds size as a Vector2 based on the given label and optional display size. If size is omitted, the absolute width is used.

Parameters

Name Type Required
text string
label TextLabel
size Vector2?

Returns

Type
Vector2

# MakeEnumType static

Util.MakeEnumType(

type: string,
values: array<string>
) → TypeDefinition

Makes an Enum type out of a name and an array of strings. See Enum Values.

Parameters

Name Type Required
type string
values array<string>

Returns

Type
TypeDefinition

# MakeListableType static

Util.MakeListableType(

type: TypeDefinition,
override: dictionary
) → TypeDefinition

Takes a singular type and produces a plural (listable) type out of it.

Parameters

Name Type Required
type TypeDefinition
override dictionary

Returns

Type
TypeDefinition

# MakeSequenceType static

Util.MakeSequenceType(options: {

TransformEach
ValidateEach
} & ({
Parse
}
| {
Constructor
}
)
) →

A helper function that makes a type which contains a sequence, like Vector3 or Color3. The delimeter can be either , or whitespace, checking , first. options is a table that can contain:

  • TransformEach: a function that is run on each member of the sequence, transforming it individually.
  • ValidateEach: a function is run on each member of the sequence validating it. It is passed the value and the index at which it occurs in the sequence. It should return true if it is valid, or false and a string reason if it is not.

And one of:

  • Parse: A function that parses all of the values into a single type.
  • Constructor: A function that expects the values unpacked as parameters to create the parsed object. This is a shorthand that allows you to set Constructor directly to Vector3.new, for example.

Parameters

Name Type Required
options

#

{
TransformEach
ValidateEach
}
& ({
Parse
}
| {
Constructor
}
)

Returns

Type

# SplitPrioritizedDelimeter static

Util.SplitPrioritizedDelimeter(

text: string,
delimters: array<string>
) → array<string>

Splits a string by a single delimeter chosen from the given set. The first matching delimeter from the set becomes the split character.

Parameters

Name Type Required
text string
delimters array<string>

Returns

Type
array<string>

# SubstituteArgs static

Util.SubstituteArgs(

text: string,
replace:
   array<string>
|
dictionary<string, string>
|
function(var: string) → string
) → string

Accepts a string with arguments (such as $1, $2, $3, etc) and a table or function to use with string.gsub. Returns a string with arguments replaced with their values.

Parameters

Name Type Required
text string
replace

#

   array<string>
|
dictionary<string, string>
|
function(var: string) → string

Returns

Type
string

# RunEmbeddedCommands static

Util.RunEmbeddedCommands(

dispatcher: Dispatcher,
commandString: string
) → string

Accepts the current dispatcher and a command string. Parses embedded commands from within the string, evaluating to the output of the command when run with dispatcher:EvaluateAndRun. Returns the response string.

Parameters

Name Type Required
dispatcher Dispatcher
commandString string

Returns

Type
string

# EmulateTabstops static

Util.EmulateTabstops(

text: string,
tabWidth: number
) → string

Returns a string emulating \t tab stops with spaces.

Parameters

Name Type Required
text string
tabWidth number

Returns

Type
string

# ParseEscapeSequences static

Util.ParseEscapeSequences(text: string) → string

Replaces escape sequences with their fully qualified characters in a string. This only parses \n, \t, \uXXXX, and \xXX where X is any hexadecimal character.

Parameters

Name Type Required
text string

Returns

Type
string
Last Updated: 10/3/2019, 12:39:58 AM