Skip to content

Commit 60c4a49

Browse files
committed
Change to return undefined, not null
1 parent 4e8e670 commit 60c4a49

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

lib/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@
1818
* Heading node to check.
1919
* @param {Style | null | undefined} [relative]
2020
* Relative style (preferred style).
21-
* @returns {Style | null}
22-
* Style, if it can be inferred, `null` otherwise.
21+
* @returns {Style | undefined}
22+
* Style, if it can be inferred, `undefined` otherwise.
2323
*/
24-
// To do: next major: use `undefined`.
2524
export function headingStyle(node, relative) {
2625
const last = node.children[node.children.length - 1]
2726
const depth = node.depth
2827
const pos = node.position && node.position.end
2928
const final = last && last.position && last.position.end
3029

3130
if (!pos) {
32-
return null
31+
return undefined
3332
}
3433

3534
// This can only occur for `'atx'` and `'atx-closed'` headings.
@@ -59,12 +58,12 @@ export function headingStyle(node, relative) {
5958
*
6059
* @param {number} depth
6160
* @param {Style | null | undefined} relative
62-
* @returns {Style | null}
61+
* @returns {Style | undefined}
6362
*/
6463
function consolidate(depth, relative) {
6564
return depth < 3
6665
? 'atx'
6766
: relative === 'atx' || relative === 'setext'
6867
? relative
69-
: null
68+
: undefined
7069
}

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ headingStyle(fromMarkdown('# ATX').children[0]) // => 'atx'
7777
headingStyle(fromMarkdown('# ATX #\n').children[0]) // => 'atx-closed'
7878
headingStyle(fromMarkdown('ATX\n===').children[0]) // => 'setext'
7979

80-
headingStyle(fromMarkdown('### ATX').children[0]) // => null
80+
headingStyle(fromMarkdown('### ATX').children[0]) // => undefined
8181
headingStyle(fromMarkdown('### ATX').children[0], 'setext') // => 'setext'
8282
```
8383

@@ -103,7 +103,7 @@ considered setext.
103103

104104
###### Returns
105105

106-
Style ([`Style`][api-style]) if it can be inferred, `null` otherwise.
106+
Style ([`Style`][api-style]) if it can be inferred, `undefined` otherwise.
107107

108108
### `Style`
109109

test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test('headingStyle', async function (t) {
2828
type: 'heading',
2929
children: [{type: 'text', value: 'foo'}]
3030
}),
31-
null
31+
undefined
3232
)
3333
})
3434

@@ -45,7 +45,7 @@ test('headingStyle', async function (t) {
4545
})
4646

4747
await t.test('should work on ambiguous nodes', async function () {
48-
assert.equal(headingStyle(parseFirstNode('### ATX')), null)
48+
assert.equal(headingStyle(parseFirstNode('### ATX')), undefined)
4949
})
5050

5151
await t.test(

0 commit comments

Comments
 (0)