Skip to content

Commit b9ba870

Browse files
committed
Change to return undefined
1 parent 824f157 commit b9ba870

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

lib/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,23 @@ import {convert} from 'unist-util-is'
1717
* @param {Parent} parent
1818
* @param {Node | number} index
1919
* @param {import('unist-util-is').PredicateTest<Kind>} test
20-
* @returns {Kind | null}
20+
* @returns {Kind | undefined}
2121
*
2222
* @overload
2323
* @param {Parent} parent
2424
* @param {Node | number} index
2525
* @param {Test} [test]
26-
* @returns {Node | null}
26+
* @returns {Node | undefined}
2727
*
2828
* @param {Parent} parent
2929
* Parent node.
3030
* @param {Node | number} index
3131
* Child of `parent`, or it’s index.
3232
* @param {Test} [test]
3333
* `unist-util-is`-compatible test.
34-
* @returns {Node | null}
35-
* Child of `parent` or `null`.
34+
* @returns {Node | undefined}
35+
* Child of `parent` or `undefined`.
3636
*/
37-
// To do: next major: return undefined.
3837
export function findBefore(parent, index, test) {
3938
const is = convert(test)
4039

@@ -65,5 +64,5 @@ export function findBefore(parent, index, test) {
6564
}
6665
}
6766

68-
return null
67+
return undefined
6968
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ that passes `test`.
108108

109109
###### Returns
110110

111-
Child of `parent` ([`Node`][node]) or `null`.
111+
Child of `parent` ([`Node`][node]) or `undefined`.
112112

113113
## Types
114114

test.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ test('`findBefore`', async function (t) {
8989
await t.test(
9090
'should return the preceding node when without `test` (#3)',
9191
async function () {
92-
assert.equal(findBefore(paragraph, 0), null)
92+
assert.equal(findBefore(paragraph, 0), undefined)
9393
}
9494
)
9595

@@ -117,21 +117,21 @@ test('`findBefore`', async function (t) {
117117
await t.test(
118118
'should return `node` when given a `node` and existing (#4)',
119119
async function () {
120-
assert.equal(findBefore(paragraph, head, head), null)
120+
assert.equal(findBefore(paragraph, head, head), undefined)
121121
}
122122
)
123123

124124
await t.test(
125125
'should return `node` when given a `node` and existing (#5)',
126126
async function () {
127-
assert.equal(findBefore(paragraph, 0, head), null)
127+
assert.equal(findBefore(paragraph, 0, head), undefined)
128128
}
129129
)
130130

131131
await t.test(
132132
'should return `node` when given a `node` and existing (#6)',
133133
async function () {
134-
assert.equal(findBefore(paragraph, 1, next), null)
134+
assert.equal(findBefore(paragraph, 1, next), undefined)
135135
}
136136
)
137137

@@ -145,7 +145,7 @@ test('`findBefore`', async function (t) {
145145
await t.test(
146146
'should return a child when given a `type` and existing (#2)',
147147
async function () {
148-
assert.equal(findBefore(paragraph, 3, 'strong'), null)
148+
assert.equal(findBefore(paragraph, 3, 'strong'), undefined)
149149
}
150150
)
151151

@@ -162,7 +162,10 @@ test('`findBefore`', async function (t) {
162162
await t.test(
163163
'should return a child when given a `type` and existing (#4)',
164164
async function () {
165-
assert.equal(findBefore(paragraph, paragraph.children[3], 'strong'), null)
165+
assert.equal(
166+
findBefore(paragraph, paragraph.children[3], 'strong'),
167+
undefined
168+
)
166169
}
167170
)
168171

@@ -176,7 +179,7 @@ test('`findBefore`', async function (t) {
176179
await t.test(
177180
'should return a child when given a `test` and existing (#2)',
178181
async function () {
179-
assert.equal(findBefore(paragraph, 3, check), null)
182+
assert.equal(findBefore(paragraph, 3, check), undefined)
180183
}
181184
)
182185

@@ -193,7 +196,10 @@ test('`findBefore`', async function (t) {
193196
await t.test(
194197
'should return a child when given a `test` and existing (#4)',
195198
async function () {
196-
assert.equal(findBefore(paragraph, paragraph.children[3], check), null)
199+
assert.equal(
200+
findBefore(paragraph, paragraph.children[3], check),
201+
undefined
202+
)
197203
}
198204
)
199205
})

0 commit comments

Comments
 (0)