Skip to content

Commit

Permalink
style: also convert some char to space for nickname
Browse files Browse the repository at this point in the history
  • Loading branch information
rafgugi committed Apr 10, 2024
1 parent 93313f1 commit 07e109f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/family.util.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ describe('deletePerson', () => {
describe('idAsNickName', () => {
test('convert correctly', () => {
expect(idAsNickName('satyr')).toEqual('Satyr');
expect(idAsNickName('satyr123')).toEqual('Satyr');
expect(idAsNickName(' satyr123 ')).toEqual('Satyr');
expect(idAsNickName('sat123yr')).toEqual('Satyr');
expect(idAsNickName('m..satyr')).toEqual('M Satyr');
});
});
6 changes: 5 additions & 1 deletion src/family.util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,9 @@ export function treesToPersonNode(

// remove number and capitalize first letter
export function idAsNickName(id: string): string {
return id.replace(/\d/g, '').replace(/^\w/, c => c.toUpperCase());
return id
.trim()
.replace(/\d/g, '')
.replace(/[-_. ]+/g, ' ')
.replace(/\b\w/g, c => c.toUpperCase());
}

0 comments on commit 07e109f

Please sign in to comment.