Skip to content

Commit 8cd9c5d

Browse files
committed
Update @types/hast, utilities
1 parent 8ddfb05 commit 8cd9c5d

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

lib/index.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
1-
/**
2-
* @typedef {import('hast').Element} Element
3-
*/
4-
51
import {convertElement} from 'hast-util-is-element'
62

7-
/**
8-
* Check if a node is an element with a [*transparent content model*].
9-
*
10-
* @type {import('hast-util-is-element').AssertPredicate<Element & {tagName: 'a' | 'audio' | 'canvas' | 'datalist' | 'dd' | 'del' | 'ins' | 'map' | 'menu' | 'noscript' | 'object' | 'ol' | 'picture' | 'select' | 'table' | 'tbody' | 'tfoot' | 'thead' | 'tr' | 'ul' | 'video'}>}
11-
* @param value
12-
* Thing to check (typically `Node`).
13-
* @returns
14-
* Whether `value` is an element with a transparent content model.
15-
*
16-
* The elements `a`, `audio`, `canvas`, `datalist`, `dd`, `del`, `ins`,
17-
* `map`, `menu`, `noscript`, `object`, `ol`, `picture`, `select`, `table`,
18-
* `tbody`, `tfoot`, `thead`, `tr`, `ul`, and `video` have transparent
19-
* content models.
20-
*/
21-
// @ts-expect-error Sure, the assertion matches.
22-
export const transparent = convertElement([
3+
const names = new Set([
234
'a',
245
'audio',
256
'canvas',
@@ -42,3 +23,26 @@ export const transparent = convertElement([
4223
'ul',
4324
'video'
4425
])
26+
27+
/**
28+
* Check if a node is an element with a [*transparent content model*].
29+
*
30+
* @param value
31+
* Thing to check (typically `Node`).
32+
* @returns
33+
* Whether `value` is an element with a transparent content model.
34+
*
35+
* The elements `a`, `audio`, `canvas`, `datalist`, `dd`, `del`, `ins`,
36+
* `map`, `menu`, `noscript`, `object`, `ol`, `picture`, `select`, `table`,
37+
* `tbody`, `tfoot`, `thead`, `tr`, `ul`, and `video` have transparent
38+
* content models.
39+
*/
40+
export const transparent = convertElement(
41+
/**
42+
* @param element
43+
* @returns {element is {tagName: 'a' | 'audio' | 'canvas' | 'datalist' | 'dd' | 'del' | 'ins' | 'map' | 'menu' | 'noscript' | 'object' | 'ol' | 'picture' | 'select' | 'table' | 'tbody' | 'tfoot' | 'thead' | 'tr' | 'ul' | 'video'}}
44+
*/
45+
function (element) {
46+
return names.has(element.tagName)
47+
}
48+
)

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
"index.js"
3434
],
3535
"dependencies": {
36-
"@types/hast": "^2.0.0",
37-
"hast-util-is-element": "^2.0.0"
36+
"hast-util-is-element": "^3.0.0"
3837
},
3938
"devDependencies": {
4039
"@types/node": "^20.0.0",

test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test('transparent', () => {
1010
'should expose the public api'
1111
)
1212

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

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

0 commit comments

Comments
 (0)