Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Pipe, PipeTransform } from '@angular/core';
- /**
- * @Description Slug or lispCase; All letters are downCased and spaces and specialChars are replaced by hyphens '-'.
- *
- * EXAMPLE: {{ 'Your best days are not behind you; your best days are out in front of you.' | slug }} // your-best-days-are-not-behind-you-your-best-days-are-out-in-front-of-you
- *
- * @param {String}
- * @return {String}
- * */
- @Pipe({name: 'slug'})
- export class SlugPipe implements PipeTransform {
- transform(input: string): string {
- return (!!input) ? String(input).toLowerCase().replace(/[^a-zá-źA-ZÁ-Ź0-9]/g, ' ').trim().replace(/\s{2,}/g, ' ').replace(/\s+/g, '-') : '';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement