-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(converter): factorize individual name utils in common file for iso
- Loading branch information
Showing
12 changed files
with
63 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
libs/api/metadata-converter/src/lib/iso19139/utils/individual-name.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { fullNameToParts, namePartsToFull } from './individual-name' | ||
|
||
describe('individual name utils', () => { | ||
it('fullNameToParts', () => { | ||
expect(fullNameToParts('John Doe')).toEqual(['John', 'Doe']) | ||
expect(fullNameToParts('John')).toEqual(['John', null]) | ||
expect(fullNameToParts(' John Jim Doe Blah ')).toEqual([ | ||
'John', | ||
'Jim Doe Blah', | ||
]) | ||
}) | ||
it('namePartsToFull', () => { | ||
expect(namePartsToFull('John', 'Doe')).toEqual('John Doe') | ||
expect(namePartsToFull('John', null)).toEqual('John') | ||
expect(namePartsToFull(null, 'Doe')).toEqual('Doe') | ||
expect(namePartsToFull(null, null)).toEqual(null) | ||
expect(namePartsToFull('', ' ')).toEqual(null) | ||
expect(namePartsToFull('John', 'Doe Blah')).toEqual('John Doe Blah') | ||
expect(namePartsToFull(' John Jim ', ' Doe Blah ')).toEqual( | ||
'John Jim Doe Blah' | ||
) | ||
}) | ||
}) |
20 changes: 20 additions & 0 deletions
20
libs/api/metadata-converter/src/lib/iso19139/utils/individual-name.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Parts are [firstName, lastName] | ||
* Second part will be null if no separation could be done | ||
* @param fullName | ||
*/ | ||
export function fullNameToParts(fullName: string): [string, string | null] { | ||
const parts = fullName.trim().split(/\s+/) | ||
const first = parts.shift() | ||
return [first, parts.join(' ').trim() || null] | ||
} | ||
|
||
export function namePartsToFull( | ||
firstName: string | null, | ||
lastName: string | null | ||
): string | null { | ||
const first = firstName?.trim() | ||
const last = lastName?.trim() | ||
if (!first && !last) return null | ||
return last && first ? `${first} ${last}` : last || first | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters