Skip to content

Commit

Permalink
Merge pull request #27 from openreview/fix/preferred-name-using-fullname
Browse files Browse the repository at this point in the history
use fullname to print preferred name
  • Loading branch information
carlosmondra committed Nov 8, 2023
2 parents b98dd94 + 863547b commit 29ab7dd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 23 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openreview/client",
"version": "0.0.22",
"version": "0.0.23",
"description": "Node.js client library for OpenReview's academic publishing API",
"main": "index.js",
"scripts": {
Expand Down
10 changes: 2 additions & 8 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,16 +514,12 @@ describe('OpenReview Client', function () {
content: {
names: [
{
first: 'First',
middle: 'Middle',
last: 'Last',
fullname: 'First Middle Last',
username: '~First_Middle_Last1',
preferred: false
},
{
first: 'AnotherFirst',
middle: 'AnotherMiddle',
last: 'AnotherLast',
fullname: 'AnotherFirst AnotherMiddle AnotherLast',
username: '~AnotherFirst_AnotherMiddle_AnotherLast1',
preferred: true
}
Expand All @@ -534,8 +530,6 @@ describe('OpenReview Client', function () {
let res = Tools.getPreferredName(fakeProfile);
assert.equal(res, 'AnotherFirst AnotherMiddle AnotherLast');

res = Tools.getPreferredName(fakeProfile, true);
assert.equal(res, 'AnotherLast');
});

it('should GET a profile with no params', async function () {
Expand Down
14 changes: 2 additions & 12 deletions tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,11 @@ class Tools {
* @param {boolean} [lastNameOnly=false] - A boolean indicating whether to return only the last name or the full name.
* @returns {string} - The user's preferred name or the first listed name.
*/
static getPreferredName(profile, lastNameOnly=false) {
static getPreferredName(profile) {
const names = profile.content.names;
const preferredNames = names.filter(name => name.preferred);
const preferredName = preferredNames.length > 0 ? preferredNames[0] : names[0];
let nameParts = [];
if (preferredName.first) {
nameParts.push(preferredName.first);
}
if (preferredName.middle) {
nameParts.push(preferredName.middle);
}
if (preferredName.last) {
nameParts.push(preferredName.last);
}
return lastNameOnly ? preferredName.last : nameParts.join(' ');
return preferredName.fullname;
}

/**
Expand Down

0 comments on commit 29ab7dd

Please sign in to comment.