Add snake_case param for validating generate input

This commit is contained in:
Eggwise 2022-03-02 10:58:17 +01:00 committed by GitHub
parent ec4bfad9fe
commit 79fd16cd23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,10 +1,10 @@
'use strict';
module.exports = input => {
const regex = /^[A-Za-z-]+$/g;
module.exports = (input, allowSnakeCase = false) => {
const regex = allowSnakeCase ? /^[A-Za-z-|_]+$/g : /^[A-Za-z-]+$/g;
if (!input) {
return 'You must provide an input';
return "You must provide an input";
}
return regex.test(input) || "Please use only letters, '-' and no spaces";