@planet-a/affinity-node
Version:
API wrapper for the affinity.co API
17 lines (16 loc) • 509 B
JavaScript
/**
* @internal
*
* Converts a value to the corresponding enum value (only works for string enums)
* Borrowed from https://stackoverflow.com/questions/17380845
* @param val The value to convert
* @param _enum The enum to match against
* @returns The enum value or undefined if no match was found
*/
export const enumFromValue = (val, _enum) => {
const enumName = Object.keys(_enum).find((k) => _enum[k] === val);
if (!enumName) {
return undefined;
}
return _enum[enumName];
};