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..af93b13 --- /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[0].toUpperCase(); + value = value.slice(1); + return upperFirst + value; + } + +}