Repository: remarkablemark/html-react-parser (ts)

Issue:
TypeError: htmlToDOM is not a function
<!--
Is this a bug report?

* Yes: Continue filling out the template.
* No: Delete the template and write in free form. (Apply a label to the issue if applicable.)
-->

## Expected Behavior

 import parser from 'html-react-parser';
Use the parser normally and render the html 

## Actual Behavior

Cause a type error
![image](https://user-images.githubusercontent.com/25417060/152686436-614c9c28-72d7-432b-8767-2a2d5579d5cd.png)


## Steps to Reproduce

1- Install the latest version of package 1.4.7
2- Use it normally like this
import parse from 'html-react-parser';
parse('<p>Hello, World!</p>');



## Environment

- Version: html-react-parser@1.4.7, react-dom@17.0.2, next@10.0.7
- Platform: ReactJS, NextJS
- Browser: Google Chrome


Pull request description:
fix: ensure backwards compatibility for html-dom-parser's ES Module
Fixes #445

## What is the motivation for this pull request?

fix: support backwards compatibility for `html-dom-parser`'s ES Module

Regression was caused in [1.4.7](https://github.com/remarkablemark/html-react-parser/releases/tag/v1.4.7). Related to https://github.com/remarkablemark/html-dom-parser/pull/202

## What is the current behavior?

next@10 throws an error:

```
TypeError: htmlToDOM is not a function
```

Note: next@11 and 12 did not have this error

## What is the new behavior?

No error in next@10

## Checklist:

- [x] [Conventional Commits](https://www.conventionalcommits.org/)
- [x] Tests

Patch:
diff --git a/index.js b/index.js
index 4f3a169..3830dfb 100644
--- a/index.js
+++ b/index.js
@@ -2,6 +2,11 @@ var domToReact = require('./lib/dom-to-react');
 var attributesToProps = require('./lib/attributes-to-props');
 var htmlToDOM = require('html-dom-parser');
 
+// support backwards compatibility for ES Module
+htmlToDOM =
+  /* istanbul ignore next */
+  typeof htmlToDOM.default === 'function' ? htmlToDOM.default : htmlToDOM;
+
 var domParserOptions = { lowerCaseAttributeNames: false };
 
 /**


Test patch:
diff --git a/test/index.test.js b/test/index.test.js
index a0cb28a..0b3bec5 100644
--- a/test/index.test.js
+++ b/test/index.test.js
@@ -6,18 +6,23 @@ const { render } = require('./helpers');
 describe('module', () => {
   it('exports default', () => {
     expect(parse.default).toBe(parse);
+    expect(parse.default).toBeInstanceOf(Function);
   });
 
   it('exports domToReact', () => {
     expect(parse.domToReact).toBe(require('../lib/dom-to-react'));
+    expect(parse.domToReact).toBeInstanceOf(Function);
   });
 
   it('exports htmlToDOM', () => {
     expect(parse.htmlToDOM).toBe(require('html-dom-parser'));
+    expect(parse.htmlToDOM).toBeInstanceOf(Function);
+    expect(parse.htmlToDOM.default).toBe(undefined);
   });
 
   it('exports attributesToProps', () => {
     expect(parse.attributesToProps).toBe(require('../lib/attributes-to-props'));
+    expect(parse.attributesToProps).toBeInstanceOf(Function);
   });
 });