feat: menambahkan kolom slug dan implement slug di module project
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
function slugify(value, fallback = 'item') {
|
||||
if (!value || typeof value !== 'string') {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
let slug = value
|
||||
.toString()
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.replace(/[^a-z0-9\s-]/g, '')
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/-+/g, '-')
|
||||
.replace(/^-|-$/g, '');
|
||||
|
||||
if (!slug) {
|
||||
slug = fallback;
|
||||
}
|
||||
|
||||
if (/^\d+$/.test(slug)) {
|
||||
slug = `${fallback}-${slug}`;
|
||||
}
|
||||
|
||||
return slug;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
slugify,
|
||||
};
|
||||
Reference in New Issue
Block a user