Skip to content

Commit 27a34eb

Browse files
committed
feat: added type checks and handled null type values
1 parent 1848d04 commit 27a34eb

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
### [3.0.2](https://github.com/codeskills-dev/md-to-react-email/compare/v3.0.1...v3.0.2) (2023-07-04)
7+
8+
### Features
9+
10+
- Added checks to handle `undefined | null | ''`
11+
- Added checks to handle input that is not of type `string`
12+
613
### [3.0.1](https://github.com/codeskills-dev/md-to-react-email/compare/v3.0.0...v3.0.1) (2023-07-04)
714

815
### Features

__tests__/parseMarkdownToReactEmailJSX.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,36 @@ import {
55
} from "../src";
66

77
describe("Markdown to React Mail JSX Parser", () => {
8+
it("handles empty string correctly", () => {
9+
const markdown = "";
10+
const expected = ``;
11+
12+
const rendered = parseMarkdownToReactEmailJSX({
13+
markdown,
14+
});
15+
expect(rendered).toBe(expected);
16+
});
17+
18+
it("handles undefined string correctly", () => {
19+
const markdown = undefined as unknown as string;
20+
const expected = ``;
21+
22+
const rendered = parseMarkdownToReactEmailJSX({
23+
markdown,
24+
});
25+
expect(rendered).toBe(expected);
26+
});
27+
28+
it("handles null string correctly", () => {
29+
const markdown = null as unknown as string;
30+
const expected = ``;
31+
32+
const rendered = parseMarkdownToReactEmailJSX({
33+
markdown,
34+
});
35+
expect(rendered).toBe(expected);
36+
});
37+
838
it("converts header one correctly", () => {
939
const markdown = "# Hello, World!";
1040
const expected = `<h1 style="${parseCssInJsToInlineCss(

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "md-to-react-email",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"description": "A simple Markdown parser for React-email written in typescript.",
55
"keywords": [
66
"markdown",

src/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ export function parseMarkdownToReactEmailJSX({
207207
customStyles,
208208
withDataAttr = false,
209209
}: ParseMarkdownToReactEmailJSXProps): string {
210+
if (
211+
markdown === undefined ||
212+
markdown === null ||
213+
markdown === "" ||
214+
typeof markdown !== "string"
215+
) {
216+
return "";
217+
}
218+
210219
const finalStyles = { ...styles, ...customStyles };
211220
let reactMailTemplate = "";
212221

0 commit comments

Comments
 (0)