Skip to content

Commit 63b3b4d

Browse files
committed
Add guard for no entry
1 parent e8ceadd commit 63b3b4d

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

convert-to-pdf.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ const convert = (phones) => {
1616
// Cut everything after "The less quick version"
1717
let short = string.substring(0, string.indexOf('The Less Quick Version'));
1818
short = `${short}${extra}`
19-
// Insert phone numbers
20-
const text = "There'll always be at least one of them at any ReactVienna-sponsored space.";
21-
const index = short.indexOf(text);
22-
const before = short.substring(0, index);
23-
const after = short.substring(index);
24-
const numbers = `You can also call them:\n${phones.map(data => `- ${data.name}: ${data.phone}`).join('\n')}\n\n`;
25-
this.push(before + numbers + after);
19+
if (phones && phones.length > 0 && phones.every(data => data.name && data.phone)) {
20+
// Insert phone numbers
21+
const text = "There'll always be at least one of them at any ReactVienna-sponsored space.";
22+
const index = short.indexOf(text);
23+
const before = short.substring(0, index);
24+
const after = short.substring(index);
25+
const numbers = `You can also call them:\n${phones.map(data => `- ${data.name}: ${data.phone}`).join('\n')}\n\n`;
26+
this.push(before + numbers + after);
27+
} else {
28+
console.warn('No phone numbers provided, please provide at least one phone number if possible.')
29+
this.push(short);
30+
}
2631
callback();
2732
}),
2833
}).from('./readme.md').to('./readme.pdf', () => {

0 commit comments

Comments
 (0)