Skip to content

Commit f22ce5d

Browse files
committed
Update @types/hast, utilities
1 parent 935e5d4 commit f22ce5d

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

lib/index.js

+20-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {convertElement} from 'hast-util-is-element'
77
/**
88
* Check if a node is a *embedded content*.
99
*
10-
* @type {import('hast-util-is-element').AssertPredicate<Element & {tagName: 'audio' | 'canvas' | 'embed' | 'iframe' | 'img' | 'math' | 'object' | 'picture' | 'svg' | 'video'}>}
1110
* @param value
1211
* Thing to check (typically `Node`).
1312
* @returns
@@ -16,16 +15,23 @@ import {convertElement} from 'hast-util-is-element'
1615
* The elements `audio`, `canvas`, `embed`, `iframe`, `img`, `math`,
1716
* `object`, `picture`, `svg`, and `video` are embedded content.
1817
*/
19-
// @ts-expect-error Sure, the assertion matches.
20-
export const embedded = convertElement([
21-
'audio',
22-
'canvas',
23-
'embed',
24-
'iframe',
25-
'img',
26-
'math',
27-
'object',
28-
'picture',
29-
'svg',
30-
'video'
31-
])
18+
export const embedded = convertElement(
19+
/**
20+
* @param element
21+
* @returns {element is Element & {tagName: 'audio' | 'canvas' | 'embed' | 'iframe' | 'img' | 'math' | 'object' | 'picture' | 'svg' | 'video'}}
22+
*/
23+
function (element) {
24+
return (
25+
element.tagName === 'audio' ||
26+
element.tagName === 'canvas' ||
27+
element.tagName === 'embed' ||
28+
element.tagName === 'iframe' ||
29+
element.tagName === 'img' ||
30+
element.tagName === 'math' ||
31+
element.tagName === 'object' ||
32+
element.tagName === 'picture' ||
33+
element.tagName === 'svg' ||
34+
element.tagName === 'video'
35+
)
36+
}
37+
)

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"index.js"
3434
],
3535
"dependencies": {
36-
"hast-util-is-element": "^2.0.0"
36+
"@types/hast": "^3.0.0",
37+
"hast-util-is-element": "^3.0.0"
3738
},
3839
"devDependencies": {
3940
"@types/node": "^20.0.0",

test.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test('embedded', () => {
1010
'should expose the public api'
1111
)
1212

13+
// @ts-expect-error: check how a missing node is handled.
1314
assert.equal(embedded(), false, 'should return `false` without node')
1415

1516
assert.equal(embedded(null), false, 'should return `false` with `null`')

0 commit comments

Comments
 (0)