Skip to content

Commit

Permalink
chore: allow different casing in middleware names in template
Browse files Browse the repository at this point in the history
  • Loading branch information
dbartholomae committed Aug 13, 2020
1 parent 666d56a commit 540b4b4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions _templates/middleware/new/prompt.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 540b4b4

Please sign in to comment.