blob: 11dd77cc53abd0c788901bf31dfba7bbf98d9c9f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
export function slugify(value: string): string {
// Copied from https://github.com/vuejs/docs/blob/b392b068fb893e3ac6079710fe34decbde7a3be3/src/api/ApiIndex.vue#L50-L65
return (
value
// Replace special characters
.replace(/[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'<>,.?/]+/g, '-')
// Remove continuous separators
.replace(/\-{2,}/g, '-')
// Remove prefixing and trailing separators
.replace(/^\-+|\-+$/g, '')
// ensure it doesn't start with a number (like #123)
.replace(/^(\d)/, '_$1')
// lowercase
.toLowerCase()
);
}
|