From 32782606e00112a2ef3eea7971d4bba7b30f3ca3 Mon Sep 17 00:00:00 2001 From: Diego Rey <diego.despaux@izundo.com> Date: Sun, 25 Nov 2018 20:40:41 -0300 Subject: [PATCH] Add custom titleCase Pipe --- .../src/app/shared/modules/titlecase.module.ts | 9 +++++++++ .../src/app/shared/pipes/titlecase.pipe.ts | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 Frontend Angular 4/src/app/shared/modules/titlecase.module.ts create mode 100644 Frontend Angular 4/src/app/shared/pipes/titlecase.pipe.ts 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 0000000..d3a9d95 --- /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 0000000..78abdce --- /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 -- GitLab