feat: add pipe to upper only the first letter in a string
This commit is contained in:
21
src/app/pipes/upperfirst-pipe.spec.ts
Normal file
21
src/app/pipes/upperfirst-pipe.spec.ts
Normal 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);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
14
src/app/pipes/upperfirst-pipe.ts
Normal file
14
src/app/pipes/upperfirst-pipe.ts
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user