diff --git a/apps/dashboard/app/javascript/dynamic_forms.js b/apps/dashboard/app/javascript/dynamic_forms.js index bc4d4b562..3a9616046 100644 --- a/apps/dashboard/app/javascript/dynamic_forms.js +++ b/apps/dashboard/app/javascript/dynamic_forms.js @@ -93,27 +93,10 @@ function mountainCaseWords(str) { function snakeCaseWords(str) { if(str === undefined) return undefined; - let snakeCase = ""; - - str.split('').forEach((c, index) => { - if(c === '-' || c === '_') { - snakeCase += '_'; - } else if (index == 0) { - snakeCase += c.toLowerCase(); - } else if(c == c.toUpperCase() && isNaN(c)) { - const nextIsUpper = (index + 1 !== str.length) ? str[index + 1] === str[index + 1].toUpperCase() : true; - const nextIsNum = !isNaN(str[index + 1]); - if ((str[index-1] === '_' || nextIsUpper) && !nextIsNum) { - snakeCase += c.toLowerCase(); - } else { - snakeCase += `_${c.toLowerCase()}`; - } - } else { - snakeCase += c; - } - }); + const rex = /([A-Z]{1}[a-z]*[0-9]*)/g; + const words = str.match(rex); - return snakeCase; + return words.map(word => word.toLowerCase()).join('_'); } /**