Skip to content

Commit

Permalink
Change to yield undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 30, 2023
1 parent 910f1bb commit fa86ae2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
8 changes: 5 additions & 3 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {removePosition} from './index.js'

const tree: Root = {type: 'root', children: []}

expectType<Root>(removePosition(tree))
expectType<Root>(removePosition(tree, {force: false}))
expectType<Root>(removePosition(tree, {force: true}))
expectType<undefined>(removePosition(tree))

removePosition(tree, {force: false})

removePosition(tree, {force: true})
11 changes: 3 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,19 @@ import {visit} from 'unist-util-visit'
/**
* Remove the `position` field from a tree.
*
* @template {Node} Tree
* Node type.
* @param {Tree} tree
* @param {Node} tree
* Tree to clean.
* @param {Options | null | undefined} [options={force: false}]
* Configuration (default: `{force: false}`).
* @returns {Tree}
* The given, modified, `tree`.
* @returns {undefined}
* Nothing.
*/
// To do: next major: return `undefined`.
export function removePosition(tree, options) {
const config = options || {}
const force = config.force || false

visit(tree, remove)

return tree

/**
* @param {Node} node
*/
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Remove the `position` field from a tree.

###### Returns

The given, modified, `tree` ([`Node`][node]).
Nothing (`undefined`).

### `Options`

Expand Down
21 changes: 13 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ test('removePosition', async function (t) {
await t.test('should work softly', async function () {
const empty = {position: undefined}

const root = fromMarkdown('Some **strong**, _emphasis_, and `code`.')
removePosition(root)

assert.deepEqual(
removePosition(fromMarkdown('Some **strong**, _emphasis_, and `code`.')),
root,
u('root', empty, [
u('paragraph', empty, [
u('text', empty, 'Some '),
Expand All @@ -31,10 +34,12 @@ test('removePosition', async function (t) {
})

await t.test('should work by force', async function () {
const root = fromMarkdown('Some **strong**, _emphasis_, and `code`.')

removePosition(root, {force: true})

assert.deepEqual(
removePosition(fromMarkdown('Some **strong**, _emphasis_, and `code`.'), {
force: true
}),
root,
u('root', [
u('paragraph', [
u('text', 'Some '),
Expand All @@ -50,9 +55,9 @@ test('removePosition', async function (t) {
})

await t.test('should support options', async function () {
assert.deepEqual(
removePosition(fromMarkdown('x'), {force: true}),
u('root', [u('paragraph', [u('text', 'x')])])
)
const root = fromMarkdown('x')
removePosition(root, {force: true})

assert.deepEqual(root, u('root', [u('paragraph', [u('text', 'x')])]))
})
})

0 comments on commit fa86ae2

Please sign in to comment.