Move getKey() to util.ts

This commit is contained in:
Matt Visnovsky
2024-05-03 11:39:14 -06:00
parent 8e56a81ef1
commit c87ac2f043
3 changed files with 15 additions and 12 deletions

View File

@@ -643,3 +643,12 @@ export function intHash(str : string, length = 10) : number {
return (hash % length + length) % length; // Ensure the result is non-negative
}
/**
* Retrieves the key from the provided object corresponding to the given value.
* @param {object} obj - The object to search.
* @param {*} value - The value to search for.
* @returns {string|null} - The key associated with the value, or null if not found.
*/
export function getKey(obj: any, value: string) {
return Object.keys(obj).find(key => obj[key] === value) || null;
}