File tree Expand file tree Collapse file tree 3 files changed +13
-12
lines changed
Expand file tree Collapse file tree 3 files changed +13
-12
lines changed Original file line number Diff line number Diff line change 22 * @typedef {import('hast').Nodes } Nodes
33 */
44
5- // To do next major: return `undefined`.
65/**
76 * Get the rank (`1` to `6`) of headings (`h1` to `h6`).
87 *
98 * @param {Nodes } node
109 * Node to check.
11- * @returns {number | null }
12- * Rank of the heading or `null ` if not a heading.
10+ * @returns {number | undefined }
11+ * Rank of the heading or `undefined ` if not a heading.
1312 */
1413export function headingRank ( node ) {
1514 const name =
@@ -18,5 +17,7 @@ export function headingRank(node) {
1817 name . length === 2 && name . charCodeAt ( 0 ) === 104 /* `h` */
1918 ? name . charCodeAt ( 1 )
2019 : 0
21- return code > 48 /* `0` */ && code < 55 /* `7` */ ? code - 48 /* `0` */ : null
20+ return code > 48 /* `0` */ && code < 55 /* `7` */
21+ ? code - 48 /* `0` */
22+ : undefined
2223}
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ In browsers with [`esm.sh`][esmsh]:
6767import {h } from ' hastscript'
6868import {headingRank } from ' hast-util-heading-rank'
6969
70- headingRank (h (' p' , ' Alpha' )) // => null
70+ headingRank (h (' p' , ' Alpha' )) // => undefined
7171headingRank (h (' h5' , ' Alpha' )) // => 5
7272```
7373
@@ -87,7 +87,7 @@ Get the rank (`1` to `6`) of headings (`h1` to `h6`).
8787
8888###### Returns
8989
90- Rank of the heading or ` null ` if not a heading (` number? ` ).
90+ Rank of the heading or ` undefined ` if not a heading (` number | undefined ` ).
9191
9292## Types
9393
Original file line number Diff line number Diff line change @@ -10,17 +10,17 @@ test('headingRank', async function (t) {
1010 ] )
1111 } )
1212
13- await t . test ( 'should return null for non-nodes' , async function ( ) {
13+ await t . test ( 'should return `undefined` for non-nodes' , async function ( ) {
1414 // @ts -expect-error runtime.
15- assert . equal ( headingRank ( ) , null )
15+ assert . equal ( headingRank ( ) , undefined )
1616 } )
1717
18- await t . test ( 'should return null for non-elements' , async function ( ) {
19- assert . equal ( headingRank ( { type : 'text' , value : '!' } ) , null )
18+ await t . test ( 'should return `undefined` for non-elements' , async function ( ) {
19+ assert . equal ( headingRank ( { type : 'text' , value : '!' } ) , undefined )
2020 } )
2121
22- await t . test ( 'should return null for non-headings' , async function ( ) {
23- assert . equal ( headingRank ( h ( 'p' , '!' ) ) , null )
22+ await t . test ( 'should return `undefined` for non-headings' , async function ( ) {
23+ assert . equal ( headingRank ( h ( 'p' , '!' ) ) , undefined )
2424 } )
2525
2626 await t . test ( 'should return the rank of a heading' , async function ( ) {
You can’t perform that action at this time.
0 commit comments