Skip to content

Commit

Permalink
fix: fix types issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bconnorwhite committed Sep 30, 2020
1 parent d75fc84 commit a7a9aef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ import {
TokensList
} from "write-file-safe";

function readMarkdown(path: string): Promise<TokensList>;
function readMarkdown(path: string): Promise<TokensList | undefined>;

function readMarkdownSync(path: string): TokensList;
function readMarkdownSync(path: string): TokensList | undefined;

function readMarkdownString(path: string): Promise<string>;
function readMarkdownString(path: string): Promise<string | undefined>;

function readMarkdownStringSync(path: string): string;
function readMarkdownStringSync(path: string): string | undefined;

// a Marked token list
type TokensList = Token[] & {
Expand Down
15 changes: 13 additions & 2 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@ export function readMarkdownStringSync(path: string) {
}

export async function readMarkdown(path: string) {
return readMarkdownString(path).then((text) => lexer(text));
return readMarkdownString(path).then((text) => {
if(text === undefined) {
return undefined;
} else {
return lexer(text);
}
});
}

export function readMarkdownSync(path: string) {
return lexer(readMarkdownStringSync(path));
const text = readMarkdownStringSync(path);
if(text === undefined) {
return undefined;
} else {
return lexer(text);
}
}

export {
Expand Down

0 comments on commit a7a9aef

Please sign in to comment.