binaris
Version:
Binaris SDK & CLI
34 lines (29 loc) • 952 B
JavaScript
;
// allows only letters and numbers
const validNameRegex = /[^A-Za-z0-9_]/g;
/**
* Verifies whether the provided function name meets
* the validity criteria. If it does not, an informative
* error will be thrown.
*
* @param {string} functionName - name of function to validate
*/
const validateName = function validateName(functionName) {
if (validNameRegex.test(functionName)) {
throw new Error(`Invalid characters in function name '${functionName}'. Use only letters and digits`);
}
};
/**
* Removes any illegal characters from the provided name
* thereby making it valid to use for a Binaris function.
*
* @param {string} functionName - name to remove potential bad chars from
* @returns {string} - input name minus any illegal characters
*/
const makeNameValid = function makeNameValid(functionName) {
return functionName.replace(validNameRegex, '');
};
module.exports = {
makeNameValid,
validateName,
};