From 6615912a356bca162cc320b5a4fe18b1c9a15d92 Mon Sep 17 00:00:00 2001 From: Gabriel De Los Rios Date: Sat, 31 Jan 2026 22:25:32 -0300 Subject: [PATCH] feat: add pipe that capitalize first word only --- src/app/pipes/upperfirst-pipe.spec.ts | 21 +++++++++++++++++++++ src/app/pipes/upperfirst-pipe.ts | 14 ++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/app/pipes/upperfirst-pipe.spec.ts create mode 100644 src/app/pipes/upperfirst-pipe.ts diff --git a/src/app/pipes/upperfirst-pipe.spec.ts b/src/app/pipes/upperfirst-pipe.spec.ts new file mode 100644 index 0000000..f54617b --- /dev/null +++ b/src/app/pipes/upperfirst-pipe.spec.ts @@ -0,0 +1,21 @@ +import { UpperfirstPipe } from './upperfirst-pipe'; + +describe('UpperfirstPipe', () => { + let pipe: UpperfirstPipe; + + beforeEach(() => { + pipe = new UpperfirstPipe(); + }); + + it('create an instance', () => { + const pipe = new UpperfirstPipe(); + expect(pipe).toBeTruthy(); + }); + + it('should uppercase only the first letter on a string', () => { + const unformattedString = "today is a great day"; + const expectedString = "Today is a great day"; + expect(pipe.transform(unformattedString)).toBe(expectedString); + }); + +}); diff --git a/src/app/pipes/upperfirst-pipe.ts b/src/app/pipes/upperfirst-pipe.ts new file mode 100644 index 0000000..bf98f12 --- /dev/null +++ b/src/app/pipes/upperfirst-pipe.ts @@ -0,0 +1,14 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'upperfirst' +}) +export class UpperfirstPipe implements PipeTransform { + + transform(value: string) { + const upperFirst = value.charAt(0).toUpperCase(); + value = value.slice(1); + return upperFirst + value; + } + +}