Last active
June 15, 2023 16:37
-
-
Save ChecksumFailed/b40e01aead257ea956efb58b9568f459 to your computer and use it in GitHub Desktop.
Function Utils
This file contains 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
/** | |
* Used to validate arguments passed into methods. | |
*/ | |
var argumentValidation = Class.create(); | |
argumentValidation.prototype = { | |
initialize: function(logLevel) { | |
this.logger = new global.GSLog('cf.argumentValidation.log.level'); | |
if (this.notNil(logLevel)) { | |
logger.setLevel(logLevel); | |
} | |
}, | |
/** | |
* Checks if variable is null, undefined, empty. Throws error message if falase | |
* @param {array} Argument - list of values to check | |
* @param {function} validationFunction - used to validate the argumetn | |
* @param {string} errorMsg - error thrown if validation fails | |
*/ | |
argumentValidation: function (args, validationFunction, errorMsg) { | |
errorMsg = errorMsg || "All arguments required"; | |
for (var argIdx = 0; argIdx < arguments.length; argIdx++) { | |
if (validationFunction(arguments[argIdx]) === false) { | |
throw msg; | |
} | |
} | |
}, | |
/** | |
* Checks if variable is an Object | |
* @param varToCheck | |
* @returns {boolean} | |
*/ | |
isObject : function(varToCheck) { | |
return typeof varToCheck === "object"; | |
}, | |
/** | |
* Check if variable is null,undefined, blank | |
* @param {*} varToCheck | |
* @returns {boolean} | |
*/ | |
notNil: function (varToCheck) { | |
return !gs.nil(varToCheck); | |
}, | |
/** | |
* Chhecks if variable is valid sysid | |
* @param {string} sysid | |
* @returns {boolean} | |
*/ | |
isValidSysID: function (sysid) { | |
return GlideStringUtil.isEligibleSysID(sysid); | |
}, | |
type: 'argumentValidation' | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment