Skip to content

Commit

Permalink
Change to return undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 3, 2023
1 parent 824f157 commit b9ba870
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
11 changes: 5 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,23 @@ import {convert} from 'unist-util-is'
* @param {Parent} parent
* @param {Node | number} index
* @param {import('unist-util-is').PredicateTest<Kind>} test
* @returns {Kind | null}
* @returns {Kind | undefined}
*
* @overload
* @param {Parent} parent
* @param {Node | number} index
* @param {Test} [test]
* @returns {Node | null}
* @returns {Node | undefined}
*
* @param {Parent} parent
* Parent node.
* @param {Node | number} index
* Child of `parent`, or it’s index.
* @param {Test} [test]
* `unist-util-is`-compatible test.
* @returns {Node | null}
* Child of `parent` or `null`.
* @returns {Node | undefined}
* Child of `parent` or `undefined`.
*/
// To do: next major: return undefined.
export function findBefore(parent, index, test) {
const is = convert(test)

Expand Down Expand Up @@ -65,5 +64,5 @@ export function findBefore(parent, index, test) {
}
}

return null
return undefined
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ that passes `test`.

###### Returns

Child of `parent` ([`Node`][node]) or `null`.
Child of `parent` ([`Node`][node]) or `undefined`.

## Types

Expand Down
22 changes: 14 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test('`findBefore`', async function (t) {
await t.test(
'should return the preceding node when without `test` (#3)',
async function () {
assert.equal(findBefore(paragraph, 0), null)
assert.equal(findBefore(paragraph, 0), undefined)
}
)

Expand Down Expand Up @@ -117,21 +117,21 @@ test('`findBefore`', async function (t) {
await t.test(
'should return `node` when given a `node` and existing (#4)',
async function () {
assert.equal(findBefore(paragraph, head, head), null)
assert.equal(findBefore(paragraph, head, head), undefined)
}
)

await t.test(
'should return `node` when given a `node` and existing (#5)',
async function () {
assert.equal(findBefore(paragraph, 0, head), null)
assert.equal(findBefore(paragraph, 0, head), undefined)
}
)

await t.test(
'should return `node` when given a `node` and existing (#6)',
async function () {
assert.equal(findBefore(paragraph, 1, next), null)
assert.equal(findBefore(paragraph, 1, next), undefined)
}
)

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

Expand All @@ -162,7 +162,10 @@ test('`findBefore`', async function (t) {
await t.test(
'should return a child when given a `type` and existing (#4)',
async function () {
assert.equal(findBefore(paragraph, paragraph.children[3], 'strong'), null)
assert.equal(
findBefore(paragraph, paragraph.children[3], 'strong'),
undefined
)
}
)

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

Expand All @@ -193,7 +196,10 @@ test('`findBefore`', async function (t) {
await t.test(
'should return a child when given a `test` and existing (#4)',
async function () {
assert.equal(findBefore(paragraph, paragraph.children[3], check), null)
assert.equal(
findBefore(paragraph, paragraph.children[3], check),
undefined
)
}
)
})
Expand Down

0 comments on commit b9ba870

Please sign in to comment.