Util
Types
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<T>,
mapper:
function(
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 |
DetailsParameters
Returns
|
✔ |
Returns
| Type | |
|---|---|
array<U>
|
#
Each
static
Util.Each(
function(value:
T) →
U,
...:
T
U...
Maps arguments #2-n through callback and returns all values as tuple.
Parameters
| Name | Type | Required | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
mapper |
DetailsParameters
Returns
|
✔ | |||||||||||||
... |
T
|
✔ |
Returns
| Type | |
|---|---|
U...
|
#
MakeFuzzyFinder
static
Util.MakeFuzzyFinder(set:
array<string>
| array<Instance>
| array<EnumItem>
| array<NamedObject>
| Instance) →
function(
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 |
#
|
✔ |
Returns
| Type | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
DetailsParameters
Returns
|
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.
#
SplitStringSimple
static
Util.SplitStringSimple(
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(
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(
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(
string,
values:
array<string
|
{ Name
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
|
{ Name
|
✔ |
Returns
| Type | |
|---|---|
TypeDefinition
|
#
MakeListableType
static
Util.MakeListableType(
) →
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:
{} & ({} | {})) →
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 |
#
|
✔ |
Returns
| Type |
|---|
#
SplitPrioritizedDelimeter
static
Util.SplitPrioritizedDelimeter(
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(
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 |
#
|
✔ |
Returns
| Type | |
|---|---|
string
|
#
RunEmbeddedCommands
static
Util.RunEmbeddedCommands(
) →
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.
#
EmulateTabstops
static
Util.EmulateTabstops(
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
|
← Registry