Skip to content

Commit 53df5b6

Browse files
authored
feat(utils) parse the first author of multiple comma seperated authors (#447)
1 parent a233dfd commit 53df5b6

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

.changeset/proud-yaks-run.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nodesecure/utils": minor
3+
---
4+
5+
feat(utils): can parse the first author of multiple comma seperated authors

workspaces/utils/src/parseManifestAuthor.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function parseManifestAuthor(
2222
return null;
2323
}
2424

25-
const match = manifestAuthorRegex().exec(manifestAuthorField);
25+
const match = matchManifestAuthor(manifestAuthorField);
2626
if (!match) {
2727
return null;
2828
}
@@ -44,6 +44,15 @@ export function parseManifestAuthor(
4444
return author;
4545
}
4646

47+
function matchManifestAuthor(manifestAuthorField: string) {
48+
const match = manifestAuthorRegex().exec(manifestAuthorField);
49+
if (match) {
50+
return match;
51+
}
52+
53+
return manifestAuthorRegex().exec(manifestAuthorField.split(",")[0]);
54+
}
55+
4756
export function parseAuthor(author: any): ParsedMaintainer | null {
4857
if (typeof author === "string") {
4958
return parseManifestAuthor(author);

workspaces/utils/test/parseManifestAuthor.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,30 @@ describe("parseManifestAuthor", () => {
103103
assert.strictEqual(error.message, "expected manifestAuthorField to be a string");
104104
}
105105
});
106+
107+
it("should be able to parse a name with a comma in it", () => {
108+
const result = utils.parseManifestAuthor("aaa,bbb");
109+
assert.deepEqual(result, {
110+
name: "aaa,bbb"
111+
});
112+
});
113+
114+
describe("multiple authors seperated by comma", () => {
115+
it("should be able to parse the first author when there is mutliple authors separated by comma", () => {
116+
const result = utils.parseManifestAuthor("John Doe <[email protected]>, Alicia B <[email protected]>");
117+
assert.deepEqual(result, {
118+
name: "John Doe",
119+
120+
});
121+
});
122+
123+
it("should be able to parse the first author author field with name and URL", () => {
124+
const result = utils.parseManifestAuthor("John-David Dalton (http://allyoucanleet.com/), Alicia B (http://a.com/)");
125+
assert.deepEqual(result, {
126+
name: "John-David Dalton",
127+
url: "http://allyoucanleet.com/"
128+
});
129+
});
130+
});
106131
});
132+

0 commit comments

Comments
 (0)