Created
December 9, 2016 11:41
-
-
Save romelgomez/9a008a9c67cef6033f85350f9f302981 to your computer and use it in GitHub Desktop.
TypeScript Filters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, '-') : ''; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment