Skip to content

Commit 954ab51

Browse files
committed
Refactor code-style
* Add more docs to JSDoc * Add support for `null` in input of API types
1 parent 0a50017 commit 954ab51

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

lib/index.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
/**
22
* @typedef {import('mdast').Heading} Heading
3-
* @typedef {'atx'|'atx-closed'|'setext'} Style
43
*/
54

65
/**
6+
* @typedef {'atx' | 'atx-closed' | 'setext'} Style
7+
* Style of heading.
8+
*/
9+
10+
/**
11+
* Get the heading style of a heading, optionally `relative` to a preferred
12+
* style.
13+
*
14+
* This is because ATX headings with a depth of three or more could be
15+
* considered setext.
16+
*
717
* @param {Heading} node
8-
* @param {Style} [relative]
9-
* @returns {Style|null}
18+
* Heading node to check.
19+
* @param {Style | null | undefined} [relative]
20+
* Relative style.
21+
* @returns {Style | null}
22+
* Style, if it can be inferred.
1023
*/
1124
export function headingStyle(node, relative) {
1225
const last = node.children[node.children.length - 1]
1326
const depth = node.depth
14-
const pos = node && node.position && node.position.end
27+
const pos = node.position && node.position.end
1528
const final = last && last.position && last.position.end
1629

1730
if (!pos) {
@@ -44,8 +57,8 @@ export function headingStyle(node, relative) {
4457
* Get the probable style of an atx-heading, depending on preferred style.
4558
*
4659
* @param {number} depth
47-
* @param {Style|undefined} relative
48-
* @returns {Style|null}
60+
* @param {Style | null | undefined} relative
61+
* @returns {Style | null}
4962
*/
5063
function consolidate(depth, relative) {
5164
return depth < 3

0 commit comments

Comments
 (0)