feat: add pipe to upper only the first letter in a string

This commit is contained in:
2025-12-11 21:15:43 -03:00
parent 2f1de6bea3
commit bda4cb9136
2 changed files with 35 additions and 0 deletions

View File

@@ -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);
});
});

View File

@@ -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;
}
}