Methods
TableUtils.all(tbl: [])
Returns whether every value in a table is true, iterating numerically.
@param tbl — The table to iterate through.
@return result — Whether every value was true or not.
Arguments:
| tbl: [] | The table to iterate through. |
Returns:
| result: boolean | Whether every value was true or not. |
TableUtils.any(tbl: [])
Returns whether any individual value in a table is true, iterating numerically.
@param tbl — The table to iterate through.
@return result — Whether any value was true or not.
Arguments:
| tbl: [] | The table to iterate through. |
Returns:
| result: boolean | Whether any value was true or not. |
TableUtils.clear(tbl: table)
Empties a table of all defined values.
@param tbl — The table to clear.
Arguments:
| tbl: table | The table to clear. |
TableUtils.contains(tbl: table, val: any)
Whether the table contains the specified value.
@param tbl — The table to check the value from.
@param val — The value to check.
@return result — Whether the table contains the specified value.
Arguments:
| tbl: table | The table to check the value from. |
| val: any | The value to check. |
Returns:
| result: boolean | Whether the table contains the specified value. |
TableUtils.copy(tbl: table?>, deep: boolean?, seen: table?)
Makes a new copy of a table, giving it all of the same values.
@param tbl — The table to copy.
@param deep — Whether tables inside the specified table should be copied as well.
@param seen — (Used internally) A table of values used to keep track of which objects have been cloned.
@return new — The new table.
Arguments:
| tbl: table?> | The table to copy. |
| deep: boolean? | Whether tables inside the specified table should be copied as well. |
| seen: table? | (Used internally) A table of values used to keep track of which objects have been cloned. |
Returns:
| new: table?> | The new table. |
TableUtils.copyInto(new_tbl: table, tbl: table, deep: boolean?, seen: table?)
Copies the values of one table into a different one.
@param new_tbl — The table receiving the copied values.
@param tbl — The table to copy values from.
@param deep — Whether tables inside the specified table should be copied as well.
@param seen — (Used internally) A table of values used to keep track of which objects have been cloned.
Arguments:
| new_tbl: table | The table receiving the copied values. |
| tbl: table | The table to copy values from. |
| deep: boolean? | Whether tables inside the specified table should be copied as well. |
| seen: table? | (Used internally) A table of values used to keep track of which objects have been cloned. |
Returns:
| 1: nil |
TableUtils.dump(o: any)
Returns a string converting a table value into readable text. Useful for debugging table values.
@param o — The value to convert to a string.
@return result — The newly generated string.
Arguments:
| o: any | The value to convert to a string. |
Returns:
| result: string | The newly generated string. |
TableUtils.endsWith(value: table, suffix: table)
Returns whether a table ends with the specified values.
The function will also return a second value, created by copying the initial value and removing the suffix.
@param value — The table to check the end of.
@param suffix — The values that should be checked.
@return success — Whether the value ended with the specified suffix.
@return rest — A new value created by removing the suffix substring or values from the initial value. If the result was unsuccessful, this value will simply be the initial unedited value.
Arguments:
| value: table | The table to check the end of. |
| suffix: table | The values that should be checked. |
Returns:
| success: boolean | Whether the value ended with the specified suffix. |
| rest: table | A new value created by removing the suffix substring or values from the initial value. If the result was unsuccessful, this value will simply be the initial unedited value. |
TableUtils.every(tbl: [], func: fun( <T)boolean)
Returns whether every value in a table satisfies a condition, iterating numerically.
@param tbl — The table to iterate through.
@param func — The condition function.
@return result — Whether every value satisfied the condition or not.
Arguments:
| tbl: [] | The table to iterate through. |
| func: fun( <T)boolean | The condition function. |
Returns:
| result: boolean | Whether every value satisfied the condition or not. |
TableUtils.filter(tbl: [], filter: fun( <T)boolean)
Returns a new table containing only values that a function returns true for.
@param tbl — An array of values.
@param filter — A function that should return true for all values in the table to keep, and false for values to discard.
@return result — A new array containing only approved values.
Arguments:
| tbl: [] | An array of values. |
| filter: fun( <T)boolean | A function that should return |
Returns:
| result: [] | A new array containing only approved values. |
TableUtils.filterInPlace(tbl: [], filter: fun( <T)boolean)
Removes values from a table if a function does not return true for them.
@param tbl — An array of values.
@param filter — A function that should return true for all values in the table to keep, and false for values to discard.
Arguments:
| tbl: [] | An array of values. |
| filter: fun( <T)boolean | A function that should return |
TableUtils.flatten(tbl: [][], deep: boolean?)
Merges a list of tables containing values into a single table containing each table's contents.
@param tbl — The array of tables to merge.
@param deep — If true, tables contained inside nested tables will also be merged.
@return result — The new table containing all values.
Arguments:
| tbl: [][] | The array of tables to merge. |
| deep: boolean? | If true, tables contained inside nested tables will also be merged. |
Returns:
| result: [] | The new table containing all values. |
TableUtils.flip(tbl: table)
Flips the values of a 2-dimensional array, such that its columns become its rows, and vice versa.
As an example, the following table:
{
{1, 2},
{3, 4},
}
would result in this when passed into the function:
{
{1, 3},
{2, 4},
}
@param tbl — The table array to flip the values of.
@return result — The new flipped array.
Arguments:
| tbl: table | The table array to flip the values of. |
Returns:
| result: table | The new flipped array. |
TableUtils.getIndex(t: [], value: <T>)
Returns the position of a specified value found within an array.
@param t — The array to get the position from.
@param value — The value to find the position of.
@return position — The position found for the specified value.
Arguments:
| t: [] | The array to get the position from. |
| value: <T> | The value to find the position of. |
Returns:
| position: number? | The position found for the specified value. |
TableUtils.getKey(t: , <V, value: <V>)
Returns the key of a specified value found within a table.
@param t — The table to get the key from.
@param value — The value to find the key of.
@return key — The key found for the specified value.
Arguments:
| t: , <V | The table to get the key from. |
| value: <V> | The value to find the key of. |
Returns:
| key: <K>? | The key found for the specified value. |
TableUtils.getKeyCount(t: table)
Returns how many keys a table has.
@param t — The table to check.
@return result — The amount of keys found.
Arguments:
| t: table | The table to check. |
Returns:
| result: number | The amount of keys found. |
TableUtils.getKeys(t: , any)
Returns a list of every key in a table.
@param t — The table to get the keys from.
@return result — An array of each key in the table.
Arguments:
| t: , any | The table to get the keys from. |
Returns:
| result: [] | An array of each key in the table. |
TableUtils.isArray(tbl: table)
Returns whether a table contains exclusively numerical indexes.
@param tbl — The table to check.
@return result — Whether the table contains only numerical indexes or not.
Arguments:
| tbl: table | The table to check. |
Returns:
| result: boolean | Whether the table contains only numerical indexes or not. |
TableUtils.lerp(from: table, to: table, value: number)
Lerp between each value in a table.
@param from — The start values of the range.
@param to — The end values of the range.
@param value — The percentage (from 0 to 1) that determines the point on the specified range.
@return result — The new table containing the values from the ranges.
Arguments:
| from: table | The start values of the range. |
| to: table | The end values of the range. |
| value: number | The percentage (from 0 to 1) that determines the point on the specified range. |
Returns:
| result: table | The new table containing the values from the ranges. |
TableUtils.merge(tbl: table, other: table, deep: boolean?)
Merges the values of one table into another one.
@param tbl — The table to merge values into.
@param other — The table to copy values from.
@param deep — Whether shared table values between the two tables should also be merged.
@return tbl — The initial table, now containing new values.
Arguments:
| tbl: table | The table to merge values into. |
| other: table | The table to copy values from. |
| deep: boolean? | Whether shared table values between the two tables should also be merged. |
Returns:
| tbl: table | The initial table, now containing new values. |
TableUtils.mergeMany(: table)
Merges many tables into a new table.
@param ... — The tables to merge values from.
@return result — A new table containing the values of the series of tables provided.
Arguments:
| : table | The tables to merge values from. |
Returns:
| result: table | A new table containing the values of the series of tables provided. |
TableUtils.pick(tbl: [])
Returns a random value from an array.
@param tbl — An array of values.
@return result — The randomly selected value.
Arguments:
| tbl: [] | An array of values. |
Returns:
| result: <T> | The randomly selected value. |
TableUtils.removeDuplicates(tbl: table, deep: boolean?)
Remove duplicate elements from a table.
@param tbl — The table to remove duplicates from.
@param deep — Whether tables inside the tbl will also have their duplicates removed.
@return result — The new table that has its duplicates removed.
Arguments:
| tbl: table | The table to remove duplicates from. |
| deep: boolean? | Whether tables inside the tbl will also have their duplicates removed. |
Returns:
| result: table | The new table that has its duplicates removed. |
TableUtils.removeValue(tbl: table, val: <T>)
Removes the specified value from the table.
@param tbl — The table to remove the value from.
@param val — The value to be removed from the table.
@return val — The now removed value.
Arguments:
| tbl: table | The table to remove the value from. |
| val: <T> | The value to be removed from the table. |
Returns:
| val: <T>? | The now removed value. |
TableUtils.reverse(tbl: [])
Returns a table containing the values of an array in reverse order.
@param tbl — An array of values.
@return result — The new table containing the values of the specified array.
Arguments:
| tbl: [] | An array of values. |
Returns:
| result: [] | The new table containing the values of the specified array. |
TableUtils.rotate(tbl: table, ccw: boolean?)
Rotates the values of a 2-dimensional array.
As an example, the following table:
{
{1, 2},
{3, 4},
}
would result in this when passed into the function, rotating it clockwise:
{
{3, 1},
{4, 2},
}
@param tbl — The table array to rotate the values of.
@param ccw — Whether the rotation should be counterclockwise.
@return result — The new rotated array.
Arguments:
| tbl: table | The table array to rotate the values of. |
| ccw: boolean? | Whether the rotation should be counterclockwise. |
Returns:
| result: table | The new rotated array. |
TableUtils.shuffle(tbl: [])
Returns a table containing the values of another table, randomly rearranged.
@param tbl — An array of values.
@return result — The new randomly shuffled array.
Arguments:
| tbl: [] | An array of values. |
Returns:
| result: [] | The new randomly shuffled array. |
TableUtils.some(tbl: [], func: fun( <T)boolean)
Returns whether any individual value in a table satisfies a condition, iterating numerically.
@param tbl — The table to iterate through.
@param func — The condition function.
@return result — Whether any value satisfied the condition or not.
Arguments:
| tbl: [] | The table to iterate through. |
| func: fun( <T)boolean | The condition function. |
Returns:
| result: boolean | Whether any value satisfied the condition or not. |
TableUtils.startsWith(value: table, prefix: table)
Returns whether a table starts with the specified values.
The function will also return a second value, created by copying the initial value and removing the prefix.
@param value — The table to check the beginning of.
@param prefix — The values that should be checked.
@return success — Whether the value started with the specified prefix.
@return rest — A new value created by removing the prefix substring or values from the initial value. If the result was unsuccessful, this value will simply be the initial unedited value.
Arguments:
| value: table | The table to check the beginning of. |
| prefix: table | The values that should be checked. |
Returns:
| success: boolean | Whether the value started with the specified prefix. |
| rest: table | A new value created by removing the prefix substring or values from the initial value. If the result was unsuccessful, this value will simply be the initial unedited value. |
TableUtils.unpack(t: [])
Returns every numerically indexed value of a table.
This fixes the issue with unpack() not returning nil values.
@param t — The table to unpack.
@return ... — The values of the table.
Arguments:
| t: [] | The table to unpack. |
Returns:
| ...: <T> | The values of the table. |