@datalayer/core
Version:
[](https://datalayer.io)
37 lines (36 loc) • 921 B
JavaScript
/*
* Copyright (c) 2023-2025 Datalayer, Inc.
* Distributed under the terms of the Modified BSD License.
*/
export const asDisplayName = (givenName, familyName) => {
return givenName
? familyName
? givenName + ' ' + familyName
: givenName
: (familyName ?? '');
};
export const nameAsInitials = (name) => {
return name
.replace(/\s+/, ' ')
.split(' ')
.slice(0, 2)
.map(v => v && v[0].toUpperCase())
.join('');
};
export const namesAsInitials = (firstName, lastName) => {
return ((firstName || ' ').charAt(0) + (lastName || ' ').charAt(0))
.toLocaleUpperCase()
.trim();
};
/**
* Convert first and last names to a friendly name.
*/
export const toFriendlyName = (firstName, lastName) => {
if (firstName) {
return firstName;
}
if (lastName) {
return lastName;
}
return '';
};