Skip to content

Commit bc66407

Browse files
Refactor index.js to let webpack handle UMD build
1 parent 3ae836a commit bc66407

File tree

1 file changed

+29
-61
lines changed

1 file changed

+29
-61
lines changed

index.js

Lines changed: 29 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,31 @@
1-
/* eslint-disable strict */
2-
// UMD template: https://github.com/ForbesLindesay/umd/blob/master/template.js
3-
;(function(factory) { // eslint-disable-line no-extra-semi
4-
5-
// CommonJS
6-
if (typeof exports === 'object' && typeof module !== 'undefined') {
7-
module.exports = factory();
8-
9-
// RequireJS (AMD)
10-
} else if (typeof define === 'function' && define.amd) { // eslint-disable-line no-undef
11-
define([], factory()); // eslint-disable-line no-undef
12-
13-
// Browser (script tag)
14-
} else {
15-
var root;
16-
if (typeof window !== 'undefined') {
17-
root = window;
18-
} else if (typeof global !== 'undefined') {
19-
root = global;
20-
} else if (typeof self !== 'undefined') {
21-
root = self;
22-
} else {
23-
// works provided we're not in strict mode
24-
root = this;
25-
}
26-
27-
// define namespace
28-
root.HTMLReactParser = factory();
29-
}
30-
31-
})(function() {
32-
33-
var domToReact = require('./lib/dom-to-react');
34-
var htmlToDOM;
35-
36-
// client (browser)
37-
if (typeof window !== 'undefined' && this === window) {
38-
htmlToDOM = require('./lib/html-to-dom-client');
39-
40-
// server (node)
41-
} else {
42-
htmlToDOM = require('./lib/html-to-dom-server');
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
var domToReact = require('./lib/dom-to-react');
7+
var htmlToDOM = (
8+
process.browser && process.title === 'browser' ?
9+
require('./lib/html-to-dom-client') :
10+
require('./lib/html-to-dom-server')
11+
);
12+
13+
/**
14+
* Convert HTML string to React elements.
15+
*
16+
* @param {String} html - The HTML.
17+
* @param {Object} [options] - The additional options.
18+
* @param {Function} [options.replace] - The replace method.
19+
* @return {ReactElement|Array}
20+
*/
21+
function HTMLReactParser(html, options) {
22+
if (typeof html !== 'string') {
23+
throw new Error('`HTMLReactParser`: The first argument must be a string.');
4324
}
25+
return domToReact(htmlToDOM(html), options);
26+
}
4427

45-
/**
46-
* Convert HTML string to React elements.
47-
*
48-
* @param {String} html - The HTML.
49-
* @param {Object} [options] - The additional options.
50-
* @param {Function} [options.replace] - The replace method.
51-
* @return {ReactElement|Array}
52-
*/
53-
function HTMLReactParser(html, options) {
54-
if (typeof html !== 'string') {
55-
throw new Error('`HTMLReactParser`: The first argument must be a string.');
56-
}
57-
return domToReact(htmlToDOM(html), options);
58-
}
59-
60-
// source
61-
return HTMLReactParser;
62-
63-
});
28+
/**
29+
* Export HTML to React parser.
30+
*/
31+
module.exports = HTMLReactParser;

0 commit comments

Comments
 (0)