2021-04-30 10:12:52 +00:00
|
|
|
const snakeCase = function(string) {
|
|
|
|
// wtf case
|
|
|
|
string = string.replace(/\.\./g, " ");
|
2017-08-25 19:16:42 +00:00
|
|
|
|
2021-04-30 10:12:52 +00:00
|
|
|
// this splits up camelcase IF there are no spaces in the word
|
|
|
|
if (string.indexOf(" ") < 0) {
|
|
|
|
string = string.replace(/([A-Z])/g, " $1");
|
|
|
|
}
|
2017-08-25 19:16:42 +00:00
|
|
|
|
2021-04-30 10:12:52 +00:00
|
|
|
return string
|
|
|
|
.trim()
|
|
|
|
.toLowerCase()
|
|
|
|
.replace(/[,\?\.]/g, "")
|
|
|
|
.replace(/\-/g, " ")
|
|
|
|
.split(" ")
|
|
|
|
.join("_");
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = snakeCase;
|