|
1 |
| -'use strict'; |
2 |
| - |
3 |
| -/** |
4 |
| - * Module dependencies. |
5 |
| - */ |
6 |
| -var domToReact = require('./lib/dom-to-react'); |
7 |
| -var htmlToDOM; |
8 |
| - |
9 |
| -/** |
10 |
| - * Detect environment. |
11 |
| - */ |
12 |
| - |
13 |
| -/** Client (Browser). */ |
14 |
| -if (typeof window !== 'undefined' && this === window) { |
15 |
| - htmlToDOM = require('./html-to-dom-client'); |
16 |
| - |
17 |
| -/** Server (Node). */ |
18 |
| -} else { |
19 |
| - htmlToDOM = require('./lib/html-to-dom-server'); |
20 |
| -} |
21 |
| - |
22 |
| -/** |
23 |
| - * Convert HTML to React. |
24 |
| - * |
25 |
| - * @param {String} html - The HTML. |
26 |
| - * @param {Object} [options] - The additional options. |
27 |
| - * @param {Function} [options.replace] - The replace method. |
28 |
| - * @return {ReactElement|Array} |
29 |
| - */ |
30 |
| -module.exports = function(html, options) { |
31 |
| - return domToReact(htmlToDOM(html), options); |
32 |
| -}; |
| 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'); |
| 43 | + } |
| 44 | + |
| 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 | + return domToReact(htmlToDOM(html), options); |
| 55 | + } |
| 56 | + |
| 57 | + // source |
| 58 | + return HTMLReactParser; |
| 59 | + |
| 60 | +}); |
0 commit comments