Skip to content

Commit

Permalink
feat: added type checks and handled null type values
Browse files Browse the repository at this point in the history
  • Loading branch information
lordelogos committed Jul 4, 2023
1 parent 1848d04 commit 27a34eb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

### [3.0.2](https://github.com/codeskills-dev/md-to-react-email/compare/v3.0.1...v3.0.2) (2023-07-04)

### Features

- Added checks to handle `undefined | null | ''`
- Added checks to handle input that is not of type `string`

### [3.0.1](https://github.com/codeskills-dev/md-to-react-email/compare/v3.0.0...v3.0.1) (2023-07-04)

### Features
Expand Down
30 changes: 30 additions & 0 deletions __tests__/parseMarkdownToReactEmailJSX.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ import {
} from "../src";

describe("Markdown to React Mail JSX Parser", () => {
it("handles empty string correctly", () => {
const markdown = "";
const expected = ``;

const rendered = parseMarkdownToReactEmailJSX({
markdown,
});
expect(rendered).toBe(expected);
});

it("handles undefined string correctly", () => {
const markdown = undefined as unknown as string;
const expected = ``;

const rendered = parseMarkdownToReactEmailJSX({
markdown,
});
expect(rendered).toBe(expected);
});

it("handles null string correctly", () => {
const markdown = null as unknown as string;
const expected = ``;

const rendered = parseMarkdownToReactEmailJSX({
markdown,
});
expect(rendered).toBe(expected);
});

it("converts header one correctly", () => {
const markdown = "# Hello, World!";
const expected = `<h1 style="${parseCssInJsToInlineCss(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "md-to-react-email",
"version": "3.0.1",
"version": "3.0.2",
"description": "A simple Markdown parser for React-email written in typescript.",
"keywords": [
"markdown",
Expand Down
9 changes: 9 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ export function parseMarkdownToReactEmailJSX({
customStyles,
withDataAttr = false,
}: ParseMarkdownToReactEmailJSXProps): string {
if (
markdown === undefined ||
markdown === null ||
markdown === "" ||
typeof markdown !== "string"
) {
return "";
}

const finalStyles = { ...styles, ...customStyles };
let reactMailTemplate = "";

Expand Down

0 comments on commit 27a34eb

Please sign in to comment.