Skip to content

Commit

Permalink
Update @types/hast, utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 1, 2023
1 parent 935e5d4 commit f22ce5d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
34 changes: 20 additions & 14 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {convertElement} from 'hast-util-is-element'
/**
* Check if a node is a *embedded content*.
*
* @type {import('hast-util-is-element').AssertPredicate<Element & {tagName: 'audio' | 'canvas' | 'embed' | 'iframe' | 'img' | 'math' | 'object' | 'picture' | 'svg' | 'video'}>}
* @param value
* Thing to check (typically `Node`).
* @returns
Expand All @@ -16,16 +15,23 @@ import {convertElement} from 'hast-util-is-element'
* The elements `audio`, `canvas`, `embed`, `iframe`, `img`, `math`,
* `object`, `picture`, `svg`, and `video` are embedded content.
*/
// @ts-expect-error Sure, the assertion matches.
export const embedded = convertElement([
'audio',
'canvas',
'embed',
'iframe',
'img',
'math',
'object',
'picture',
'svg',
'video'
])
export const embedded = convertElement(
/**
* @param element
* @returns {element is Element & {tagName: 'audio' | 'canvas' | 'embed' | 'iframe' | 'img' | 'math' | 'object' | 'picture' | 'svg' | 'video'}}
*/
function (element) {
return (
element.tagName === 'audio' ||
element.tagName === 'canvas' ||
element.tagName === 'embed' ||
element.tagName === 'iframe' ||
element.tagName === 'img' ||
element.tagName === 'math' ||
element.tagName === 'object' ||
element.tagName === 'picture' ||
element.tagName === 'svg' ||
element.tagName === 'video'
)
}
)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"index.js"
],
"dependencies": {
"hast-util-is-element": "^2.0.0"
"@types/hast": "^3.0.0",
"hast-util-is-element": "^3.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
Expand Down
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test('embedded', () => {
'should expose the public api'
)

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

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

0 comments on commit f22ce5d

Please sign in to comment.