Skip to content

Commit f6ac596

Browse files
committed
refactor(types): export domToReact and htmlToDom
1 parent 9bc66f8 commit f6ac596

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

index.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
import * as React from 'react';
44
import { DomElement } from 'domhandler';
5+
import domToReact from './lib/dom-to-react';
6+
import htmlToDOM from 'html-dom-parser';
57

68
export { DomElement };
79

8-
export as namespace HTMLReactParser;
9-
10-
export default HTMLReactParser;
11-
1210
type ReactElement = React.DetailedReactHTMLElement<{}, HTMLElement>;
1311

1412
export interface HTMLReactParserOptions {
@@ -28,3 +26,6 @@ declare function HTMLReactParser(
2826
html: string,
2927
options?: HTMLReactParserOptions
3028
): ReactElement | ReactElement[] | string;
29+
30+
export { domToReact, htmlToDOM };
31+
export default HTMLReactParser;

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ function HTMLReactParser(html, options) {
2323
* Export HTML to React parser.
2424
*/
2525
module.exports = HTMLReactParser;
26+
27+
module.exports.domToReact = domToReact;
28+
module.exports.htmlToDOM = htmlToDOM;

test/types/index.test.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import parse, { HTMLReactParserOptions } from 'html-react-parser';
1+
import parse, { HTMLReactParserOptions, domToReact, htmlToDOM } from 'html-react-parser';
22
import * as React from 'react';
33

44
// $ExpectType string | DetailedReactHTMLElement<{}, HTMLElement> | DetailedReactHTMLElement<{}, HTMLElement>[]
@@ -35,3 +35,12 @@ parse('<a id="header" href="#">Heading</a>', {
3535
}
3636
}
3737
});
38+
39+
// $ExpectType DomElement[]
40+
const dom = htmlToDOM('<div>text</div>');
41+
42+
/* $ExpectType ReactElement<any, string | ((props: any) => ReactElement<any, string | any | (new (props: any) => Component<any, any, any>)> | null) |
43+
(new (props: any) => Component<any, any, any>)> |
44+
ReactElement<any, string | ((props: any) => ReactElement<any, string | any | (new (props: any) => Component<any, any, any>)> | null) |
45+
(new (props: any) => Component<any, any, any>)>[] */
46+
domToReact(dom);

0 commit comments

Comments
 (0)