Skip to content

Commit

Permalink
test: fix undefined error
Browse files Browse the repository at this point in the history
Signed-off-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com>
  • Loading branch information
kbdharun committed Mar 1, 2024
1 parent bed93ad commit ef70e1a
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,33 @@ export function parseTldrPage(source: string): TldrPage {
}

const name = markdownTokens[0].text;
const descriptionText = markdownTokens[1].tokens[0];
const descriptionText = markdownTokens[1].tokens ? markdownTokens[1].tokens[0] : undefined;

if (descriptionText.type !== 'paragraph') {
if (!descriptionText || descriptionText.type !== 'paragraph') {
throw new Error('Invalid tldr page provided.');
}

const descriptionTokens = descriptionText.tokens;
const hasMoreInfo = descriptionTokens[descriptionTokens.length - 2]?.type === 'link';
const hasMoreInfo = descriptionTokens && descriptionTokens[descriptionTokens.length - 2]?.type === 'link';

let description = '';
let moreInfo;

if (!hasMoreInfo) {
description = markdownTokens[1].text;
} else {
for (let i = 0; i <= descriptionTokens.length - 4; i++) {
description += descriptionTokens[i].raw;
}
if (descriptionTokens) {
for (let i = 0; i <= descriptionTokens.length - 4; i++) {
description += descriptionTokens[i].raw;
}

const descriptionSeperator = descriptionTokens[descriptionTokens.length - 3].raw.split('\n');
description += descriptionSeperator[0];
moreInfo = descriptionSeperator[1];
const descriptionSeperator = descriptionTokens[descriptionTokens.length - 3].raw.split('\n');
description += descriptionSeperator[0];
moreInfo = descriptionSeperator[1];

for (let i = descriptionTokens.length - 2; i < descriptionTokens.length; i++) {
moreInfo += descriptionTokens[i].raw;
for (let i = descriptionTokens.length - 2; i < descriptionTokens.length; i++) {
moreInfo += descriptionTokens[i].raw;
}
}
}

Expand Down

0 comments on commit ef70e1a

Please sign in to comment.