Skip to content

Commit

Permalink
use slugify utility
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomontero committed Dec 5, 2023
1 parent 786952a commit 348a583
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/cmd/logic-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const settings = require('../../settings');
const { normalizedApiError } = require('../lib/api-client');
const templateProcessor = require('../lib/template-processor');
const fs = require('fs-extra');

const { slugify } = require('../lib/utilities');
const logicFunctionTemplatePath = path.join(__dirname, '/../../assets/logicFunction');

/**
Expand Down Expand Up @@ -79,7 +79,7 @@ module.exports = class LogicFunctionsCommand extends CLICommandBase {
};
const result = await this.ui.prompt([question]);
const description = result.description;
const slugName = name.toLowerCase().replace(/\s/g, '-');
const slugName = slugify(name);
const destinationPath = path.join(filepath, slugName);

this.ui.stdout.write(`Creating Logic Function ${this.ui.chalk.bold(name)} for ${orgName}...${os.EOL}`);
Expand Down
19 changes: 18 additions & 1 deletion src/lib/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,23 @@ module.exports = {
const savedProp = fs.readFileSync(propPath, 'utf8');
const parsedPropFile = propertiesParser.parse(savedProp);
return parsedPropFile;
}
},

/**
* Converts a string to the slug version by replacing
* spaces and underscores with dashes, changing
* to lowercase, and removing anything other than
* numbers, letters, and dashes
* @param {String} str string to slugify
* @return {String} slugified version of str
*/
slugify(str) {
const slug = str.trim().toLowerCase()
// replace every group of spaces and underscores with a single hyphen
.replace(/[ _]+/g, '-')
// delete everything other than letters, numbers and hyphens
.replace(/[^a-z0-9-]/g, '');
return slug;
},
};

0 comments on commit 348a583

Please sign in to comment.