mern_utils_box
Version:
21 lines (15 loc) • 627 B
JavaScript
// Create Slug
const makeSlug = (title) => {
// Convert the title to lowercase and replace spaces with hyphens
const slug = title.toLowerCase().replace(/\s+/g, "-");
// Remove any special characters or symbols
const cleanSlug = slug.replace(/[^a-z0-9-]/g, "");
// Remove consecutive hyphens
const finalSlug = cleanSlug.replace(/-+/g, "-");
return finalSlug;
};
// Create Alert
const createAlert = (msg, type = "danger") => {
return `<p class="alert alert-${type}"> ${msg} <button class="btn-close" data-bs-dismiss="alert"></button> </p>`;
};
module.exports = { makeSlug, createAlert };