Skip to content

Commit f8c0e3f

Browse files
Merge pull request #137 from remarkablemark/fix/types
fix: make `replace` optional in type declaration and update JSDoc
2 parents ccba051 + 801512b commit f8c0e3f

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import htmlToDOM from 'html-dom-parser';
77

88
export interface HTMLReactParserOptions {
99
// TODO: Replace `object` by type for objects like `{ type: 'h1', props: { children: 'Heading' } }`
10-
replace(domNode: DomElement): React.ReactElement | object | undefined | false;
10+
replace?: (
11+
domNode: DomElement
12+
) => React.ReactElement | object | void | undefined | null | false;
1113
library?: object;
1214
}
1315

lib/dom-to-react.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ var utilities = require('./utilities');
44
/**
55
* Converts DOM nodes to React elements.
66
*
7-
* @param {Array} nodes - The DOM nodes.
8-
* @param {Object} [options] - The additional options.
9-
* @param {Function} [options.replace] - The replace method.
10-
* @return {ReactElement|Array}
7+
* @param {DomElement[]} nodes - The DOM nodes.
8+
* @param {Object} [options={}] - The additional options.
9+
* @param {Function} [options.replace] - The replacer.
10+
* @param {Object} [options.library] - The library (React, Preact, etc.).
11+
* @return {String|ReactElement|ReactElement[]}
1112
*/
1213
function domToReact(nodes, options) {
1314
options = options || {};
@@ -95,6 +96,10 @@ function domToReact(nodes, options) {
9596
return result.length === 1 ? result[0] : result;
9697
}
9798

99+
/**
100+
* @param {React.ReactElement} node
101+
* @return {Boolean}
102+
*/
98103
function shouldPassAttributesUnaltered(node) {
99104
return (
100105
utilities.PRESERVE_CUSTOM_ATTRIBUTES &&

0 commit comments

Comments
 (0)