diff --git a/Frontend Angular 4/src/app/shared/modules/titlecase.module.ts b/Frontend Angular 4/src/app/shared/modules/titlecase.module.ts new file mode 100644 index 0000000000000000000000000000000000000000..d3a9d95bc46d8f6095ee7fe3e249e16287d2068b --- /dev/null +++ b/Frontend Angular 4/src/app/shared/modules/titlecase.module.ts @@ -0,0 +1,9 @@ +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 diff --git a/Frontend Angular 4/src/app/shared/pipes/titlecase.pipe.ts b/Frontend Angular 4/src/app/shared/pipes/titlecase.pipe.ts new file mode 100644 index 0000000000000000000000000000000000000000..78abdceb6f557c935f271575114139d0aa079e66 --- /dev/null +++ b/Frontend Angular 4/src/app/shared/pipes/titlecase.pipe.ts @@ -0,0 +1,15 @@ +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