Skip to content

Commit

Permalink
Merge 00a4aad into 474c8cd
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jul 9, 2019
2 parents 474c8cd + 00a4aad commit 72c077f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 46 deletions.
9 changes: 4 additions & 5 deletions index.d.ts
Expand Up @@ -15,12 +15,11 @@ export interface HTMLReactParserOptions {
}

/**
* Convert HTML string to React elements.
* Converts HTML string to React elements.
*
* @param - Raw string of HTML to parse.
* @param options - Options to use when converting to react.
* @returns ReactElement on successful parse or string when `html` cannot be
* parsed as HTML
* @param html - The HTML string to parse to React.
* @param options - The parser options.
* @return - When parsed with HTML string, returns React elements; otherwise, returns string or empty array.
*/
declare function HTMLReactParser(
html: string,
Expand Down
17 changes: 7 additions & 10 deletions index.js
Expand Up @@ -5,12 +5,12 @@ var htmlToDOM = require('html-dom-parser');
var domParserOptions = { decodeEntities: true, lowerCaseAttributeNames: false };

/**
* Convert HTML string to React elements.
* Converts HTML string to React elements.
*
* @param {String} html - The HTML string.
* @param {Object} [options] - The additional options.
* @param {String} html - The HTML string to parse to React.
* @param {Object} [options] - The parser options.
* @param {Function} [options.replace] - The replace method.
* @return {ReactElement|Array}
* @return {ReactElement|Array|String} - When parsed with HTML string, returns React elements; otherwise, returns string or empty array.
*/
function HTMLReactParser(html, options) {
if (typeof html !== 'string') {
Expand All @@ -19,10 +19,7 @@ function HTMLReactParser(html, options) {
return domToReact(htmlToDOM(html, domParserOptions), options);
}

/**
* Export HTML to React parser.
*/
module.exports = HTMLReactParser;
HTMLReactParser.domToReact = domToReact;
HTMLReactParser.htmlToDOM = htmlToDOM;

module.exports.domToReact = domToReact;
module.exports.htmlToDOM = htmlToDOM;
module.exports = HTMLReactParser;
12 changes: 7 additions & 5 deletions package.json
Expand Up @@ -7,8 +7,8 @@
"scripts": {
"benchmark": "node benchmark",
"build": "npm run clean && npm run build:min && npm run build:unmin",
"build:min": "cross-env NODE_ENV=production webpack --output-filename html-react-parser.min.js",
"build:unmin": "cross-env NODE_ENV=development webpack --output-filename html-react-parser.js",
"build:min": "cross-env NODE_ENV=production rollup --config --file dist/html-react-parser.min.js --sourcemap",
"build:unmin": "cross-env NODE_ENV=development rollup --config --file dist/html-react-parser.js",
"clean": "rimraf dist",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"lint": "eslint --ignore-path .gitignore .",
Expand Down Expand Up @@ -58,9 +58,11 @@
"react": "^16",
"react-dom": "^16",
"rimraf": "^2.6.3",
"standard-version": "^6.0.1",
"webpack": "^4.35.0",
"webpack-cli": "^3.3.5"
"rollup": "^1.16.2",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-node-resolve": "^5.0.4",
"rollup-plugin-uglify": "^6.0.2",
"standard-version": "^6.0.1"
},
"peerDependencies": {
"react": "^0.14 || ^15 || ^16"
Expand Down
22 changes: 22 additions & 0 deletions rollup.config.js
@@ -0,0 +1,22 @@
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import { uglify } from 'rollup-plugin-uglify';

const config = {
external: ['react'],
input: 'index.js',
output: {
format: 'umd',
globals: {
react: 'React'
},
name: 'HTMLReactParser'
},
plugins: [commonjs(), resolve({ browser: true })]
};

if (process.env.NODE_ENV === 'production') {
config.plugins.push(uglify());
}

export default config;
26 changes: 0 additions & 26 deletions webpack.config.js

This file was deleted.

0 comments on commit 72c077f

Please sign in to comment.