File tree 3 files changed +39
-2
lines changed 3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change 4
4
*
5
5
* @see {@link https://github.com/substack/node-browserify#browser-field }
6
6
*/
7
- module . exports = require ( './lib/server/html-to-dom' ) ;
7
+ var HTMLDOMParser = require ( './lib/server/html-to-dom' ) ;
8
+
9
+ module . exports = HTMLDOMParser ;
10
+ module . exports . default = HTMLDOMParser ;
Original file line number Diff line number Diff line change
1
+ import domparser from './domparser' ;
2
+ import { formatDOM } from './utilities' ;
3
+
4
+ var DIRECTIVE_REGEX = / < ( ! [ a - z A - Z \s ] + ) > / ; // e.g., <!doctype html>
5
+
6
+ /**
7
+ * Parses HTML string to DOM nodes in browser.
8
+ *
9
+ * @param {string } html - HTML markup.
10
+ * @return {DomElement[] } - DOM elements.
11
+ */
12
+ function HTMLDOMParser ( html ) {
13
+ if ( typeof html !== 'string' ) {
14
+ throw new TypeError ( 'First argument must be a string' ) ;
15
+ }
16
+
17
+ if ( html === '' ) {
18
+ return [ ] ;
19
+ }
20
+
21
+ // match directive
22
+ var match = html . match ( DIRECTIVE_REGEX ) ;
23
+ var directive ;
24
+
25
+ if ( match && match [ 1 ] ) {
26
+ directive = match [ 1 ] ;
27
+ }
28
+
29
+ return formatDOM ( domparser ( html ) , null , directive ) ;
30
+ }
31
+
32
+ module . exports = HTMLDOMParser ;
33
+ module . exports . default = HTMLDOMParser ;
Original file line number Diff line number Diff line change 86
86
" /lib"
87
87
],
88
88
"browser" : {
89
- "./index.js" : " ./lib/client/html-to-dom.js"
89
+ "./index.js" : " ./lib/client/html-to-dom.js" ,
90
+ "./index.mjs" : " ./lib/client/html-to-dom.mjs"
90
91
},
91
92
"react-native" : {
92
93
"./index.js" : " ./lib/server/html-to-dom.js"
You can’t perform that action at this time.
0 commit comments