feat: add pipe that capitalize first word only

This commit is contained in:
2026-01-31 22:25:32 -03:00
parent 1723ea7a39
commit 6615912a35
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.charAt(0).toUpperCase();
value = value.slice(1);
return upperFirst + value;
}
}