isaacscript-common 1.2.191 → 1.2.192
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/functions/utils.d.ts +15 -0
- package/dist/functions/utils.lua +10 -0
- package/package.json +1 -1
|
@@ -36,6 +36,21 @@
|
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
38
|
export declare const ensureAllCases: (obj: never) => never;
|
|
39
|
+
/**
|
|
40
|
+
* TypeScriptToLua will transpile TypeScript enums to Lua tables that have a double mapping. Thus,
|
|
41
|
+
* when you iterate over them, you will get both the names of the enums and the values of the enums,
|
|
42
|
+
* in a random order. If all you need are the keys of an enum, use this helper function.
|
|
43
|
+
*
|
|
44
|
+
* This function will return the enum keys in a sorted order, which may not necessarily be the same
|
|
45
|
+
* order as which they were declared in.
|
|
46
|
+
*
|
|
47
|
+
* This function will work properly for both number enums and string enums. (Reverse mappings are
|
|
48
|
+
* not created for string enums.)
|
|
49
|
+
*
|
|
50
|
+
* For a more in depth explanation, see:
|
|
51
|
+
* https://isaacscript.github.io/docs/gotchas#iterating-over-enums
|
|
52
|
+
*/
|
|
53
|
+
export declare function getEnumKeys<T>(transpiledEnum: T): string[];
|
|
39
54
|
/**
|
|
40
55
|
* TypeScriptToLua will transpile TypeScript enums to Lua tables that have a double mapping. Thus,
|
|
41
56
|
* when you iterate over them, you will get both the names of the enums and the values of the enums,
|
package/dist/functions/utils.lua
CHANGED
|
@@ -6,6 +6,16 @@ local __TS__StringSubstr = ____lualib.__TS__StringSubstr
|
|
|
6
6
|
local ____exports = {}
|
|
7
7
|
local HEX_STRING_LENGTH = 6
|
|
8
8
|
____exports.ensureAllCases = function(____, obj) return obj end
|
|
9
|
+
function ____exports.getEnumKeys(self, transpiledEnum)
|
|
10
|
+
local enumKeys = {}
|
|
11
|
+
for key in pairs(transpiledEnum) do
|
|
12
|
+
if type(key) == "string" then
|
|
13
|
+
__TS__ArrayPush(enumKeys, key)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
__TS__ArraySort(enumKeys)
|
|
17
|
+
return enumKeys
|
|
18
|
+
end
|
|
9
19
|
function ____exports.getEnumValues(self, transpiledEnum)
|
|
10
20
|
local enumValues = {}
|
|
11
21
|
for key, value in pairs(transpiledEnum) do
|