This commit is contained in:
tiago.kayaya
2022-03-28 13:34:01 +01:00
parent dd488c32e3
commit 80ddf8c764
6 changed files with 99 additions and 39 deletions
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { InitialsService } from './initials.service';
describe('InitialsService', () => {
let service: InitialsService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(InitialsService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -0,0 +1,18 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class InitialsService {
constructor() { }
getInitials(name:string){
let names = name.split(' '),
initials = names[0].substring(0, 1).toUpperCase();
if (names.length > 1) {
initials += names[names.length - 1].substring(0, 1).toUpperCase();
}
return initials;
}
}