Skip to content

Commit 8014473

Browse files
committed
Refactor code-style
1 parent a4c1753 commit 8014473

File tree

2 files changed

+243
-221
lines changed

2 files changed

+243
-221
lines changed

lib/index.js

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,56 @@ import {convert} from 'unist-util-is'
99
/**
1010
* Find nodes in `parent` after a `child` or after an index, that pass `test`.
1111
*
12-
* @param parent
12+
* @template {Node} Kind
13+
* Node type.
14+
*
15+
* @overload
16+
* @param {Parent} parent
17+
* @param {Node | number} index
18+
* @param {import('unist-util-is').PredicateTest<Kind>} test
19+
* @returns {Array<Kind>}
20+
*
21+
* @overload
22+
* @param {Parent} parent
23+
* @param {Node | number} index
24+
* @param {Test} [test]
25+
* @returns {Array<Node>}
26+
*
27+
* @param {Parent} parent
1328
* Parent node.
14-
* @param index
29+
* @param {Node | number} index
1530
* Child of `parent` or it’s index.
16-
* @param test
31+
* @param {Test} [test]
1732
* `unist-util-is`-compatible test.
18-
* @returns
33+
* @returns {Array<Node>}
1934
* Children of `parent` that pass `test`.
2035
*/
21-
export const findAllAfter =
22-
/**
23-
* @type {(
24-
* (<T extends Node>(node: Parent, index: Node | number, test: import('unist-util-is').PredicateTest<T>) => Array<T>) &
25-
* ((node: Parent, index: Node | number, test?: Test) => Array<Node>)
26-
* )}
27-
*/
28-
(
29-
/**
30-
* @param {Parent} parent
31-
* @param {Node | number} index
32-
* @param {Test} [test]
33-
* @returns {Array<Node>}
34-
*/
35-
function (parent, index, test) {
36-
const is = convert(test)
37-
/** @type {Array<Node>} */
38-
const results = []
39-
40-
if (!parent || !parent.type || !parent.children) {
41-
throw new Error('Expected parent node')
42-
}
36+
export function findAllAfter(parent, index, test) {
37+
const is = convert(test)
38+
/** @type {Array<Node>} */
39+
const results = []
4340

44-
if (typeof index === 'number') {
45-
if (index < 0 || index === Number.POSITIVE_INFINITY) {
46-
throw new Error('Expected positive finite number as index')
47-
}
48-
} else {
49-
index = parent.children.indexOf(index)
41+
if (!parent || !parent.type || !parent.children) {
42+
throw new Error('Expected parent node')
43+
}
5044

51-
if (index < 0) {
52-
throw new Error('Expected child node or index')
53-
}
54-
}
45+
if (typeof index === 'number') {
46+
if (index < 0 || index === Number.POSITIVE_INFINITY) {
47+
throw new Error('Expected positive finite number as index')
48+
}
49+
} else {
50+
index = parent.children.indexOf(index)
5551

56-
while (++index < parent.children.length) {
57-
if (is(parent.children[index], index, parent)) {
58-
results.push(parent.children[index])
59-
}
60-
}
52+
if (index < 0) {
53+
throw new Error('Expected child node or index')
54+
}
55+
}
6156

62-
return results
57+
while (++index < parent.children.length) {
58+
if (is(parent.children[index], index, parent)) {
59+
results.push(parent.children[index])
6360
}
64-
)
61+
}
62+
63+
return results
64+
}

0 commit comments

Comments
 (0)