Skip to content

Commit

Permalink
author.uri and author.email should be optional in atom #115 (#124)
Browse files Browse the repository at this point in the history
* email/uri are optional for atom authors

* test: add coverage for optional cases

* test: update syntax

Co-authored-by: Josh Santangelo <josh@endquote.com>
Co-authored-by: Decebal Dobrica <decebal.dobrica@tellimer.com>
  • Loading branch information
3 people committed Jul 5, 2020
1 parent 50ed093 commit 15c6ccc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/__tests__/__snapshots__/atom1.spec.ts.snap
Expand Up @@ -42,6 +42,9 @@ exports[`atom 1.0 should generate a valid feed 1`] = `
<email>joesmith@example.com</email>
<uri>https://example.com/joesmith</uri>
</author>
<author>
<name>Joe Smith, Name Only</name>
</author>
<category label=\\"Grateful Dead\\"/>
<category label=\\"MSFT\\"/>
<contributor>
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/setup.ts
Expand Up @@ -45,13 +45,16 @@ sampleFeed.addItem({
{
name: "Jane Doe",
email: "janedoe@example.com",
link: "https://example.com/janedoe?link=sanitized&value=2"
link: "https://example.com/janedoe?link=sanitized&value=2",
},
{
name: "Joe Smith",
email: "joesmith@example.com",
link: "https://example.com/joesmith",
},
{
name: "Joe Smith, Name Only",
}
],
contributor: [
{
Expand Down
19 changes: 12 additions & 7 deletions src/atom1.ts
Expand Up @@ -167,21 +167,26 @@ export default (ins: Feed) => {
};

/**
* Returns a formated author
* Returns a formatted author
* @param author
*/
const formatAuthor = (author: Author) => {
const { name, email, link } = author;

return {
name,
email,
uri: sanitize(link)
};
const out: { name?: string, email?: string, uri?: string } = { name };
if (email) {
out.email = email;
}

if (link) {
out.uri = sanitize(link);
}

return out;
};

/**
* Returns a formated category
* Returns a formatted category
* @param category
*/
const formatCategory = (category: Category) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
@@ -1,4 +1,4 @@
export function sanitize(url: String | undefined): String | undefined {
export function sanitize(url: string | undefined): string | undefined {
if (typeof (url) === 'undefined') {
return;
}
Expand Down

0 comments on commit 15c6ccc

Please sign in to comment.