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 32e8aee commit b7fc859
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
21 changes: 14 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
/**
* @typedef {import('hast').Element} Element
*/

import {convertElement} from 'hast-util-is-element'

/**
* Check if a node is sectioning content.
*
* @type {import('hast-util-is-element').AssertPredicate<Element & {tagName: 'article' | 'aside' | 'nav' | 'section'}>}
* @param value
* Thing to check (typically `Node`).
* @returns
* Whether `value` is an element considered sectioning content.
*
* The elements `article`, `aside`, `nav`, and `section` are sectioning.
*/
// @ts-expect-error Sure, the assertion matches.
export const sectioning = convertElement(['article', 'aside', 'nav', 'section'])
export const sectioning = convertElement(
/**
* @param element
* @returns {element is {tagName: 'article' | 'aside' | 'nav' | 'section'}}
*/
function (element) {
return (
element.tagName === 'article' ||
element.tagName === 'aside' ||
element.tagName === 'nav' ||
element.tagName === 'section'
)
}
)
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"index.js"
],
"dependencies": {
"@types/hast": "^2.0.0",
"hast-util-is-element": "^2.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('sectioning', () => {
'should expose the public api'
)

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

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

0 comments on commit b7fc859

Please sign in to comment.