Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import { Pipe, PipeTransform } from '@angular/core';
  2.  
  3. /**
  4. * @Description Slug or lispCase; All letters are downCased and spaces and specialChars are replaced by hyphens '-'.
  5. *
  6. * 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
  7. *
  8. * @param {String}
  9. * @return {String}
  10. * */
  11. @Pipe({name: 'slug'})
  12. export class SlugPipe implements PipeTransform {
  13. transform(input: string): string {
  14. return (!!input) ? String(input).toLowerCase().replace(/[^a-zá-źA-ZÁ-Ź0-9]/g, ' ').trim().replace(/\s{2,}/g, ' ').replace(/\s+/g, '-') : '';
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement