Skip to content

Commit 910f1bb

Browse files
committed
Change to remove force shortcut
1 parent b842bf6 commit 910f1bb

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

index.test-d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ import {removePosition} from './index.js'
55
const tree: Root = {type: 'root', children: []}
66

77
expectType<Root>(removePosition(tree))
8-
expectType<Root>(removePosition(tree, false))
9-
expectType<Root>(removePosition(tree, true))
10-
expectType<Root>(removePosition(tree, true))
8+
expectType<Root>(removePosition(tree, {force: false}))
9+
expectType<Root>(removePosition(tree, {force: true}))

lib/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ import {visit} from 'unist-util-visit'
2020
* Node type.
2121
* @param {Tree} tree
2222
* Tree to clean.
23-
* @param {Options | boolean | null | undefined} [options={force: false}]
23+
* @param {Options | null | undefined} [options={force: false}]
2424
* Configuration (default: `{force: false}`).
2525
* @returns {Tree}
2626
* The given, modified, `tree`.
2727
*/
2828
// To do: next major: return `undefined`.
29-
// To do: remove `force` shortcut, replace with options.
3029
export function removePosition(tree, options) {
31-
const force =
32-
typeof options === 'boolean' ? options : options ? options.force : false
30+
const config = options || {}
31+
const force = config.force || false
3332

3433
visit(tree, remove)
3534

readme.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`removePosition(node[, force|options])`](#removepositionnode-forceoptions)
20+
* [`removePosition(node[, options])`](#removepositionnode-options)
2121
* [`Options`](#options)
2222
* [Types](#types)
2323
* [Compatibility](#compatibility)
@@ -110,16 +110,14 @@ Yields:
110110
This package exports the identifier [`removePosition`][removeposition].
111111
There is no default export.
112112

113-
### `removePosition(node[, force|options])`
113+
### `removePosition(node[, options])`
114114

115115
Remove the `position` field from a tree.
116116

117117
###### Parameters
118118

119119
* `node` ([`Node`][node])
120120
— tree to clean
121-
* `force` (`boolean`)
122-
— equivalent to `{force: boolean}`
123121
* `options` ([`Options`][options], optional)
124122
— configuration
125123

@@ -224,6 +222,6 @@ abide by its terms.
224222

225223
[unist-util-stringify-position]: https://github.com/syntax-tree/unist-util-stringify-position
226224

227-
[removeposition]: #removepositionnode-forceoptions
225+
[removeposition]: #removepositionnode-options
228226

229227
[options]: #options

test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ test('removePosition', async function (t) {
3232

3333
await t.test('should work by force', async function () {
3434
assert.deepEqual(
35-
removePosition(
36-
fromMarkdown('Some **strong**, _emphasis_, and `code`.'),
37-
true
38-
),
35+
removePosition(fromMarkdown('Some **strong**, _emphasis_, and `code`.'), {
36+
force: true
37+
}),
3938
u('root', [
4039
u('paragraph', [
4140
u('text', 'Some '),

0 commit comments

Comments
 (0)