TableKit
The container for everything inside of TableKit.
-Functions
DeepCopy
TableKit.
DeepCopy
(
tableToClone:
table
) →
table
TableKit
Root table
+Functions
DeepCopy
TableKit.
DeepCopy
(
tableToClone:
table
) →
table
This function "deep" copies a table, and all of its contents. This means that it will clone the entire table, and tables within that table- as opposed to shallow-copying with table.clone @@ -24,7 +23,7 @@ }, } -local CopiedDictionary = TableKit.DeepCopy(Dictionary, SecondDictionary) +local CopiedDictionary = TableKit.DeepCopy(Dictionary) print(CopiedDictionary) -- prints { ["SomethingInside"] = { ["A"] = 1, ["B"] = 1 } } @@ -38,7 +37,7 @@
MergeDictionary
TableKit.
MergeDictionary
(
dictionary1:
table
,
dictionary2:
table
) →
table
MergeDictionary
TableKit.
MergeDictionary
(
dictionary1:
table
,
dictionary2:
table
) →
table
This function merges two dictionaries.
Keys will overwrite- if there are duplicate keys, dictionary2 will take priority.
local Dictionary = {
@@ -62,7 +61,7 @@
Keys
TableKit.
Keys
(
dictionary:
table
) →
table
Keys
TableKit.
Keys
(
dictionary:
table
) →
table
This function returns a table with the keys of the passed dictionary.
local Dictionary = {
A = 1,
@@ -72,7 +71,7 @@ (TableKit.Keys(Dictionary)) -- prints {"A", "B", "C"}
-Values
TableKit.
Values
(
dictionary:
table
) →
table
Values
TableKit.
Values
(
dictionary:
table
) →
table
This function returns a table with the values of the passed dictionary.
local Dictionary = {
A = 1,
@@ -82,14 +81,14 @@ (TableKit.Values(Dictionary)) -- prints {1, 2, 3}
-MergeArray
TableKit.
MergeArray
(
array1:
table
,
array2:
table
) →
table
Merges two arrays. array2 will be added to array1- this means that the indexes of array1 will be the same.
+MergeArrays
TableKit.
MergeArrays
(
array1:
table
,
array2:
table
) →
table
Merges two arrays; array2 will be added to array1- this means that the indexes of array1 will be the same.
local FirstArray = {"A", "B", "C", "D"}
local SecondArray = {"E", "F", "G", "H"}
-print(TableKit.MergeArray(FirstArray, SecondArray)) -- prints {"A", "B", "C", D", "E", "F", "G", "H"}
+print(TableKit.MergeArrays(FirstArray, SecondArray)) -- prints {"A", "B", "C", D", "E", "F", "G", "H"}
-Reconcile
TableKit.
Reconcile
(
original:
table
,
reconcile:
table
) →
table
Reconcile
TableKit.
Reconcile
(
original:
table
,
reconcile:
table
) →
table
Deep-reconciles a dictionary into another dictionary.
local template = {
A = 0,
@@ -107,21 +106,21 @@ (TableKit.Reconcile(toReconcile, template)) -- prints { A = 9, B = 8, C = { D = "" }
-IsArray
TableKit.
IsArray
(
mysteryTable:
table
) →
boolean
Detects if a table is an array, meaning purely number indexes.
+IsArray
TableKit.
IsArray
(
mysteryTable:
table
) →
boolean
Detects if a table is an array, meaning purely number indexes and indexes starting at 1.
local Array = {"A", "B", "C", "D"}
local Dictionary = { NotAnArray = true }
print(TableKit.IsArray(Array), TableKit.IsArray(Dictionary)) -- prints true, false
-IsDictionary
TableKit.
IsDictionary
(
mysteryTable:
table
) →
boolean
IsDictionary
TableKit.
IsDictionary
(
mysteryTable:
table
) →
boolean
Detects if a table is a dictionary, meaning it is not purely number indexes.
local Array = {"A", "B", "C", "D"}
local Dictionary = { NotAnArray = true }
print(TableKit.IsDictionary(Array), TableKit.IsDictionary(Dictionary)) -- prints false, true
-ToString
TableKit.
ToString
(
obj:
{
}
) →
string
ToString
TableKit.
ToString
(
obj:
{
}
) →
string
Converts a table into a string.
local DictionaryA = {
A = "Z",
@@ -135,34 +134,42 @@
-- }
-From
TableKit.
From
(
value:
any
) →
{
[
number
]
:
any
}
From
TableKit.
From
(
value:
unknown
) →
{
[
number
]
:
unknown
}
Takes in a data type, and returns it in array form.
local str = "Test"
print(TableKit.From(str)) -- prints ("T", "e", "s", t")
-Filter
TableKit.
Filter
(
arr:
{
[
number
]
:
any
}
,
callback:
(
value:
value
)
→
boolean
) →
{
[
number
]
:
any
}
Filter
TableKit.
Filter
(
arr:
{
[
number
]
:
unknown
}
,
callback:
(
value:
value
)
→
boolean
) →
{
[
number
]
:
unknown
}
Creates a shallow copy of an array, passed through a filter callback- if the callback returns false, the element is removed.
-local str = "Test"
+local str = {"a", "b", "c", "d", "e", "f", "g"}
-print(TableKit.From(str)) -- prints ("T", "e", "s", t")
+print(TableKit.Filter(str, function(value)
+ return value > "c"
+end))
+-- prints {
+ [1] = "d",
+ [2] = "e",
+ [3] = "f",
+ [4] = "g"
+}
-
Some
TableKit.
Some
(
arr:
{
}
,
callback:
(
value
)
→
boolean
) →
boolean
Some
TableKit.
Some
(
tbl:
table
,
callback:
(
value
)
→
boolean
) →
boolean
Loops through every single element, and puts it through a callback. If the callback returns true, the function returns true.
local array = {1, 2, 3, 4, 5}
local even = function(value) return value % 2 == 0 end
print(TableKit.Some(array, even)) -- Prints true
-IsFlat
TableKit.
IsFlat
(
tbl:
table
) →
boolean
IsFlat
TableKit.
IsFlat
(
tbl:
table
) →
boolean
Detects if a table has an embedded table as one of its members.
local Shallow = {"a", "b"}
local Deep = {"a", {"b"}}
print(TableKit.IsFlat(Shallow)) -- prints true
-print(TableKit.IsFlat(Deep)) -- prints true
+print(TableKit.IsFlat(Deep)) -- prints false
-Every
TableKit.
Every
(
array:
{
}
,
callback:
(
value
)
→
boolean
) →
boolean
Every
TableKit.
Every
(
tbl:
table
,
callback:
(
value
)
→
boolean
) →
boolean
Loops through every single element, and puts it through a callback. If any of the conditions return false, the function returns false.
local array = {1, 2, 3, 4, 5}
local even = function(value) return value % 2 == 0 end
@@ -171,7 +178,7 @@ (TableKit.Every(array, even)) -- Prints false
print(TableKit.Every(array, odd)) -- Prints false
-HasKey
TableKit.
HasKey
(
dictionary:
table
,
key:
any
) →
boolean
HasKey
TableKit.
HasKey
(
dictionary:
table
,
key:
unknown
) →
boolean
Detects if a dictionary has a certain key.
local Dictionary = {
Hay = "A",
@@ -182,13 +189,13 @@ (TableKit.HasKey(Dictionary, "Needle")) -- prints true
-HasValue
TableKit.
HasValue
(
tbl:
table
,
value:
any
) →
boolean
HasValue
TableKit.
HasValue
(
tbl:
table
,
value:
unknown
) →
boolean
Detects if a dictionary has a certain value.
local Array = { "Has", "this", "thing" }
print(TableKit.HasValue(Array, "Has")) -- prints true
-IsEmpty
TableKit.
IsEmpty
(
mysteryTable:
table
) →
boolean
IsEmpty
TableKit.
IsEmpty
(
mysteryTable:
table
) →
boolean
Detects if a table is empty.
local Empty = {}
local NotEmpty = { "Stuff" }
@@ -199,7 +206,7 @@