/*
* site-monitor/models/enumHelper.js Copyright 2021 cPanel, L.L.C.
* All rights reserved.
* copyright@cpanel.net http://cpanel.net
* This code is subject to the cPanel license. Unauthorized copying is prohibited
*/
/* global define, PAGE */
/** @namespace cpanel.siteMoniter.models.enumHelper */
define([],
function() {
"use strict";
return {
/**
* Return the key from the value if it exists in the enum.
*
* @param {object} theEnum
* @param {string} value
* @returns string
*/
fromString: function(theEnum, value) {
if (!theEnum || typeof theEnum !== 'object') {
throw new Error('You must pass an object as the enum.');
}
if (!value || !( typeof value === 'string' || typeof value === 'number' ) ) {
throw new Error('The value must be either a string or number');
}
var key = Object.keys(theEnum).find(function(key) { return theEnum[key] === value });
if (typeof key === 'undefined') {
throw new Error('The enum does not contain a property with the value ' + value);
}
return key;
}
}
}
);