1.  
  2. import { Pipe, PipeTransform } from '@angular/core';
  3.  
  4. @Pipe({name: 'titlecase', pure: true})
  5. /** Transform to Title Case: uppercase the first letter of the words in a string.*/
  6. export class TitleCasePipe implements PipeTransform {
  7. transform(input: string): string {
  8. return input.length === 0 ? '' :
  9. input.replace(/\w\S*/g,(txt => txt[0].toUpperCase()+txt.substr(1).toLowerCase()));
  10. }
  11. }
  12.