Skip to content

Commit

Permalink
update all-stars, use object-assign to merge person data
Browse files Browse the repository at this point in the history
  • Loading branch information
nexdrew committed Nov 16, 2015
1 parent 083985b commit 0cde7c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"tmp": "0.0.28"
},
"dependencies": {
"all-stars": "^0.1.0",
"es6-promise": "^3.0.2"
"all-stars": "^1.0.0",
"es6-promise": "^3.0.2",
"object-assign": "^4.0.1"
}
}
30 changes: 9 additions & 21 deletions util/package.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
'use strict';

var allStars = require( 'all-stars' );
var objectAssign = require( 'object-assign' );

/**
* Check all-stars db for given person and normalize person data if found.
* Check all-stars db for given person and assign to person if found.
*
* @param {Object|false} person object representing author or maintainer
* @param {Object} person object representing author or maintainer
*
* @return {Object|false} same object given, possibly modified or augmented
* @return {Object} same object given, possibly modified or augmented
*/
function getAllStar( person ) {
if ( !person ) return person;

var allStar = allStars( person );
if ( allStar ) {
// normalize name and email
var name = allStar.name();
var email = allStar.email();
if ( name ) person.name = name;
if ( email ) person.email = email;
// add values only defined in all-stars
person.npm = allStar.npmUser();
person.github = allStar.githubUser();
person.twitter = allStar.twitter();
}
return person;
// override properties from all-stars if available
return objectAssign( person, allStars( person ) );
}

/**
Expand Down Expand Up @@ -59,9 +47,9 @@ function getAuthor( packageJson ) {
return getPersonObject( packageJson.author );
}

return getAllStar( packageJson.author ?
packageJson.author :
false );
return packageJson.author ?
getAllStar( packageJson.author ) :
false;
}


Expand Down
13 changes: 5 additions & 8 deletions util/package.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,26 @@ test( 'getAuthor - author in all-stars has additional properties', t => {
};

// add our fake author to all-stars for mocking purposes
let allStarAuthors = authors();
let allStarIndex = index();

let fakeAuthorId = 'PiDude314159265359';

allStarAuthors[ fakeAuthorId ] = {
authors[ fakeAuthorId ] = {
npmUsers : [ fakeAuthorId ],
names : [ packageJson.author.name ],
emails : [ packageJson.author.email ],
githubUsers : [ fakeAuthorId ],
twitters : [ fakeAuthorId ]
};

allStarIndex[ packageJson.author.name ] = fakeAuthorId;
allStarIndex[ packageJson.author.email ] = fakeAuthorId;
index[ packageJson.author.name ] = fakeAuthorId;
index[ packageJson.author.email ] = fakeAuthorId;

// test
let author = packageUtil.getAuthor( packageJson );

t.is( author.name, packageJson.author.name );
t.is( author.email, packageJson.author.email );
t.is( author.npm, fakeAuthorId );
t.is( author.github, fakeAuthorId );
t.is( author.npmUser, fakeAuthorId );
t.is( author.githubUser, fakeAuthorId );
t.is( author.twitter, fakeAuthorId );
t.end();
} );
Expand Down

0 comments on commit 0cde7c0

Please sign in to comment.