Skip to content
Snippets Groups Projects
Commit 32782606 authored by Diego Rey's avatar Diego Rey
Browse files

Add custom titleCase Pipe

parent ab3c0578
No related branches found
No related tags found
No related merge requests found
import { NgModule } from '@angular/core';
import { TitleCasePipe } from '../pipes/titlecase.pipe';
@NgModule({
imports: [],
declarations: [TitleCasePipe],
exports: [TitleCasePipe]
})
export class TitleCaseModule { }
\ No newline at end of file
import { Pipe, PipeTransform } from '@angular/core';
/*
* Changes the case of the first letter of a given number of words in a string.
*/
@Pipe({
name: 'titleCase',
pure: false
})
export class TitleCasePipe implements PipeTransform {
transform(input:string, length: number): string{
return input.length > 0 ? input.replace(/\w\S*/g, (txt => txt[0].toUpperCase() + txt.substr(1).toLowerCase() )) : '';
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment