Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
Parse out email and urls from author/maintainers/contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jul 25, 2010
1 parent 1a0fb06 commit d9b2ac1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/utils/read-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function processObject (tag, cb) { return function (er, json) {

json._id = json.name+"-"+json.version
json = testEngine(json)
json = parsePeople(json)
if (cb) cb(null,json)
return json
}}
Expand All @@ -97,3 +98,22 @@ function testEngine (json) {
json._nodeSupported = semver.satisfies(nodeVer, json.engines.node || "undefined")
return json
}

function parsePeople (json) {
if (json.author) json.author = parsePerson(json.author)
;["maintainers", "contributors"].forEach(function (set) {
if (Array.isArray(json[set])) json[set] = json[set].map(parsePerson)
})
return json
}
function parsePerson (person) {
if (typeof person !== "string") return person
var name = person.match(/^([^\(<]+)/)
, url = person.match(/\(([^\)]+)\)/)
, email = person.match(/<([^>]+)>/)
, obj = { "name" : (name && name[0] || person).trim() }
if (email) obj.email = email[1]
if (url) obj.url = url[1]
log(obj, "parsed person: "+person)
return obj
}

0 comments on commit d9b2ac1

Please sign in to comment.