Created
August 30, 2024 19:48
-
-
Save zhe-t/0d961e0cfac0360877888cebc84882b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Function that converts a Rust enum to a string. | |
* Example rust: { switchboard: {} } -> ts: Switchboard | |
* @param value Rust enum value | |
*/ | |
public static convertRustEnumValueToString(value: any) { | |
// get the key of the enum | |
let key = Object.keys(value)[0]; | |
// capitalize first letter | |
key = key.charAt(0).toUpperCase() + key.slice(1); | |
return key; | |
} | |
/** | |
* Function that converts a Rust enum to a TS enum value. | |
* Example rust: { switchboard: {} } -> ts: OracleType.Switchboard | |
* @param value Rust enum value | |
* @param enumType TS enum type | |
*/ | |
public static convertRustEnumValueToTSEnumValue(value: any, enumType: any) { | |
let key = convertRustEnumValueToString(value); | |
return enumType[key]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment