diff --git a/_templates/middleware/new/prompt.js b/_templates/middleware/new/prompt.js index f97f698..d1b46d3 100644 --- a/_templates/middleware/new/prompt.js +++ b/_templates/middleware/new/prompt.js @@ -1,10 +1,24 @@ +const uppercase = new RegExp("([A-Z])", "g"); +const underbar_prefix = new RegExp("^_"); + +function replaceAll(str, subStrs, by) { + let result = str; + for (const subStr of subStrs) { + result = result.split(subStr).join(by); + } + return result; +} + +function underscore(str) { + return replaceAll(str.replace(uppercase, "_$1"), ["-", " "], "_"); +} + module.exports = [ { type: "input", name: "name", - message: - "How do you want to call the middleware? Please separate with spaces, e. g. 'no sniff'", - result: (name) => name.toLowerCase(), + message: "How do you want to call the middleware?", + result: (name) => underscore(name), }, { type: "input",