Skip to content

Commit 431dd4c

Browse files
committed
Update @types/hast, utilities
1 parent a85ad8a commit 431dd4c

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

lib/index.js

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

3+
const names = new Set(['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hgroup'])
4+
75
/**
86
* Check if the given value is a *heading content* element.
97
*
10-
* @type {import('hast-util-is-element').AssertPredicate<Element & {tagName: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'hgroup'}>}
118
* @param node
129
* Thing to check (typically `Node`).
1310
* @returns
@@ -16,13 +13,12 @@ import {convertElement} from 'hast-util-is-element'
1613
* The elements `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, and `hgroup` are
1714
* heading content.
1815
*/
19-
// @ts-expect-error Sure, the assertion matches.
20-
export const heading = convertElement([
21-
'h1',
22-
'h2',
23-
'h3',
24-
'h4',
25-
'h5',
26-
'h6',
27-
'hgroup'
28-
])
16+
export const heading = convertElement(
17+
/**
18+
* @param element
19+
* @returns {element is {tagName: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'hgroup'}}
20+
*/
21+
function (element) {
22+
return names.has(element.tagName)
23+
}
24+
)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"index.js"
3434
],
3535
"dependencies": {
36-
"@types/hast": "^2.0.0",
37-
"hast-util-is-element": "^2.0.0"
36+
"@types/hast": "^3.0.0",
37+
"hast-util-is-element": "^3.0.0"
3838
},
3939
"devDependencies": {
4040
"@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('heading', () => {
1010
'should expose the public api'
1111
)
1212

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

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

0 commit comments

Comments
 (0)