Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/utils/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ export default {
return value.charAt(0).toUpperCase() + value.slice(1);
},

/**
* Make a string into a slug (all lower case, remove accent, replace space and the rest by -)
* Ex: Hello it's beautiful here => hello-it-s-beautiful-here
*
* @param value {string}
* @returns {string}
*/
slugify(value: string): string {
if (!value) {
return '';
}

return value
// make lower case and trim
.toLowerCase().trim()
// remove accents from characters
.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
// replace invalid chars with spaces
.replace(/[^a-z0-9\s-]/g, ' ')
.trim()
// replace multiple spaces or hyphens with a single hyphen
.replace(/[\s-]+/g, '-');
},

/**
* Search occurrence of a value in text
* @param text {string}
Expand Down