1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'slugify', }) export class SlugifyPipe implements PipeTransform { transform(text: string): string { return text .toString() .normalize('NFD') .replace(/[\u0300-\u036f]/g, '') .toLowerCase() .trim() .replace(/\s+/g, '-') .replace(/[^\w-]+/g, '-') .replace(/--+/g, '-') .replace(/^-|-$/g, ''); } }