sandhog
Version:
A virtual Open Source project maintainer
69 lines (67 loc) • 2.02 kB
JavaScript
// src/contributor/ensure-contributor.ts
var NAME_REGEXP = /([^<]*)/;
var NAME_EMAIL_REGEXP = /([^<]*)<([^>]*)>/;
var NAME_URL_REGEXP = /([^(]*)\s*\(([^)]*\))/;
var NAME_EMAIL_URL_REGEXP = /([^<]*)<([^>]*)>\s*\(([^)]*\))/;
function ensureContributor(contributor) {
if (typeof contributor !== "string") return contributor;
if (NAME_EMAIL_URL_REGEXP.test(contributor)) {
const [, name, email, url] = contributor.match(NAME_EMAIL_URL_REGEXP);
return {
name: name?.trim(),
email,
url
};
} else if (NAME_URL_REGEXP.test(contributor)) {
const [, name, url] = contributor.match(NAME_URL_REGEXP);
return {
name: name?.trim(),
url
};
} else if (NAME_EMAIL_REGEXP.test(contributor)) {
const [, name, email] = contributor.match(NAME_EMAIL_REGEXP);
return {
name: name?.trim(),
email
};
} else if (NAME_REGEXP.test(contributor)) {
const [, name] = contributor.match(NAME_REGEXP);
return {
name: name?.trim()
};
} else {
throw new TypeError(`Could not parse string: '${contributor}' as a contributor`);
}
}
// src/contributor/get-contributors-from-package.ts
function getContributorsFromPackage(pkg) {
const all = [];
const includesContributor = (contributor) => all.some(({ name }) => name === contributor.name);
if (pkg.author != null) {
const author = ensureContributor(pkg.author);
if (!includesContributor(author)) {
all.push(author);
}
}
if (pkg.authors != null) {
const authors = pkg.authors.map(ensureContributor);
authors.forEach((author) => {
if (!includesContributor(author)) {
all.push(author);
}
});
}
if (pkg.contributors != null) {
const contributors = pkg.contributors.map(ensureContributor);
contributors.forEach((contributor) => {
if (!includesContributor(contributor)) {
all.push(contributor);
}
});
}
return all;
}
export {
getContributorsFromPackage
};
//# sourceMappingURL=chunk-H3ZAQGMJ.js.map