diff --git a/lib/index.js b/lib/index.js index e05db06..2262c1c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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} * @param value * Thing to check (typically `Node`). * @returns @@ -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' + ) + } +) diff --git a/package.json b/package.json index c97134c..3ed8ede 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test.js b/test.js index a3f751e..ff13df1 100644 --- a/test.js +++ b/test.js @@ -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`')