Skip to content

Commit

Permalink
Merge pull request #137 from remarkablemark/fix/types
Browse files Browse the repository at this point in the history
fix: make `replace` optional in type declaration and update JSDoc
  • Loading branch information
remarkablemark authored Feb 8, 2020
2 parents ccba051 + 801512b commit f8c0e3f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import htmlToDOM from 'html-dom-parser';

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

Expand Down
13 changes: 9 additions & 4 deletions lib/dom-to-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ var utilities = require('./utilities');
/**
* Converts DOM nodes to React elements.
*
* @param {Array} nodes - The DOM nodes.
* @param {Object} [options] - The additional options.
* @param {Function} [options.replace] - The replace method.
* @return {ReactElement|Array}
* @param {DomElement[]} nodes - The DOM nodes.
* @param {Object} [options={}] - The additional options.
* @param {Function} [options.replace] - The replacer.
* @param {Object} [options.library] - The library (React, Preact, etc.).
* @return {String|ReactElement|ReactElement[]}
*/
function domToReact(nodes, options) {
options = options || {};
Expand Down Expand Up @@ -95,6 +96,10 @@ function domToReact(nodes, options) {
return result.length === 1 ? result[0] : result;
}

/**
* @param {React.ReactElement} node
* @return {Boolean}
*/
function shouldPassAttributesUnaltered(node) {
return (
utilities.PRESERVE_CUSTOM_ATTRIBUTES &&
Expand Down

0 comments on commit f8c0e3f

Please sign in to comment.