File tree 3 files changed +13
-12
lines changed
3 files changed +13
-12
lines changed Original file line number Diff line number Diff line change 2
2
* @typedef {import('hast').Nodes } Nodes
3
3
*/
4
4
5
- // To do next major: return `undefined`.
6
5
/**
7
6
* Get the rank (`1` to `6`) of headings (`h1` to `h6`).
8
7
*
9
8
* @param {Nodes } node
10
9
* 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.
13
12
*/
14
13
export function headingRank ( node ) {
15
14
const name =
@@ -18,5 +17,7 @@ export function headingRank(node) {
18
17
name . length === 2 && name . charCodeAt ( 0 ) === 104 /* `h` */
19
18
? name . charCodeAt ( 1 )
20
19
: 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
22
23
}
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ In browsers with [`esm.sh`][esmsh]:
67
67
import {h } from ' hastscript'
68
68
import {headingRank } from ' hast-util-heading-rank'
69
69
70
- headingRank (h (' p' , ' Alpha' )) // => null
70
+ headingRank (h (' p' , ' Alpha' )) // => undefined
71
71
headingRank (h (' h5' , ' Alpha' )) // => 5
72
72
```
73
73
@@ -87,7 +87,7 @@ Get the rank (`1` to `6`) of headings (`h1` to `h6`).
87
87
88
88
###### Returns
89
89
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 ` ).
91
91
92
92
## Types
93
93
Original file line number Diff line number Diff line change @@ -10,17 +10,17 @@ test('headingRank', async function (t) {
10
10
] )
11
11
} )
12
12
13
- await t . test ( 'should return null for non-nodes' , async function ( ) {
13
+ await t . test ( 'should return `undefined` for non-nodes' , async function ( ) {
14
14
// @ts -expect-error runtime.
15
- assert . equal ( headingRank ( ) , null )
15
+ assert . equal ( headingRank ( ) , undefined )
16
16
} )
17
17
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 )
20
20
} )
21
21
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 )
24
24
} )
25
25
26
26
await t . test ( 'should return the rank of a heading' , async function ( ) {
You can’t perform that action at this time.
0 commit comments