Skip to content

Commit

Permalink
Merge pull request #6 from howmanysmall/v2.2.1
Browse files Browse the repository at this point in the history
updated to v2.2.1
  • Loading branch information
howmanysmall authored May 16, 2021
2 parents bc6b428 + 2d965d6 commit 8702cde
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Lua.runtime.version": "Luau",
"rojo.buildOutputPath": "enumerator"
"rojo.buildOutputPath": "enumerator",
"stylua.styluaPath": "C:/Path/stylua2Roact.exe",
}
2 changes: 1 addition & 1 deletion rotriever.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "howmanysmall/enumerator"
version = "2.2.0"
version = "2.2.1"
author = "howmanysmall"
dependencies_root = "./src/enumerator/"
content_root = "./src/enumerator"
Expand Down
16 changes: 14 additions & 2 deletions src/enumerator/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ local function lockTable(tab, name)
})
end

--t:union<t:array<t:string>, t:keys<t:string>>

--[[**
Creates a new enumeration.
@param [t:string] enumName The unique name of the enumeration.
@param [t:union<t:array<t:string>, t:keys<t:string>>] enumValues The values of the enumeration.
@param [t:{string}|{string:any}] enumValues The values of the enumeration.
@returns [t:userdata] a new enumeration
**--]]
local function enumerator(enumName, enumValues)
Expand All @@ -57,10 +59,20 @@ local function enumerator(enumName, enumValues)
local rawValues = {}
local totalEnums = 0

--[[**
Returns an `EnumerationValue` from the calling `Enumeration` or `nil` if the raw value does not exist.
@param [t:any] rawValue The raw value of the enum.
@returns [t:EnumerationValue?] The `EnumerationValue` if it was found.
**--]]
function internal.fromRawValue(rawValue)
return rawValues[rawValue]
end

--[[**
Returns `true` only if the provided value is an `EnumerationValue` that is a member of the calling `Enumeration`.
@param [t:any] value The value to check for.
@returns [t:boolean] True iff it is an `EnumerationValue`.
**--]]
function internal.isEnumValue(value)
if typeof(value) ~= "userdata" then
return false
Expand All @@ -78,7 +90,7 @@ local function enumerator(enumName, enumValues)
--[[**
This function will cast values to the appropriate enumerator. This behaves like a type checker from t, except it returns the value if it was found.
@param [t:any] value The value you want to cast.
@returns [t:tuple<t:union<t:literal<false>, enumerator>, t:optional<t:string>>] Either returns the appropriate enumeration if found or false and an error message if it couldn't find it.
@returns [t:false|enumerator,string?] Either returns the appropriate enumeration if found or false and an error message if it couldn't find it.
**--]]
function internal.cast(value)
if internal.isEnumValue(value) then
Expand Down
2 changes: 2 additions & 0 deletions testez-companion.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
roots = ["ReplicatedStorage"]
extraOptions = {}

0 comments on commit 8702cde

Please sign in to comment.