Skip to content

Commit 75ec747

Browse files
committed
Refactor some types
1 parent d48a10a commit 75ec747

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

lib/browser.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
/**
2-
* @typedef {typeof import('./index.js').fromHtmlIsomorphic} FromHtmlIsomorphic
32
* @typedef {import('hast').Root} Root
3+
* @typedef {typeof import('./index.js').fromHtmlIsomorphic} FromHtmlIsomorphic
44
*/
55

66
import {fromDom} from 'hast-util-from-dom'
77

88
const parser = new DOMParser()
99

10-
/**
11-
* @param {string} value
12-
*/
13-
function parseFragment(value) {
14-
const template = document.createElement('template')
15-
template.innerHTML = value
16-
return template.content
17-
}
18-
1910
/** @type {FromHtmlIsomorphic} */
2011
export function fromHtmlIsomorphic(value, options) {
2112
const node = options?.fragment
@@ -24,3 +15,15 @@ export function fromHtmlIsomorphic(value, options) {
2415

2516
return /** @type {Root} */ (fromDom(node))
2617
}
18+
19+
/**
20+
* Parse as a fragment.
21+
*
22+
* @param {string} value
23+
* @returns {DocumentFragment}
24+
*/
25+
function parseFragment(value) {
26+
const template = document.createElement('template')
27+
template.innerHTML = value
28+
return template.content
29+
}

lib/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ import {fromHtml} from 'hast-util-from-html'
77
import {removePosition} from 'unist-util-remove-position'
88

99
/**
10+
* Turn HTML into a syntax tree, using browser APIs when available, so it has
11+
* a smaller bundle size there.
12+
*
1013
* @param {string} value
1114
* Serialized HTML to parse.
12-
* @param {Options} [options]
15+
* @param {Options | null | undefined} [options]
1316
* Configuration (optional).
14-
* @returns {import('hast').Root}
15-
* Tree
17+
* @returns {Root}
18+
* Tree.
1619
*/
1720
export function fromHtmlIsomorphic(value, options) {
1821
const tree = fromHtml(value, options)

0 commit comments

Comments
 (0)