Skip to content

Commit 51d3cda

Browse files
committed
Add improved docs
1 parent 53c5d82 commit 51d3cda

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

lib/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
/**
2222
* Turn an estree `node` into a unist `position`.
2323
*
24-
* @param {NodeLike | null | undefined} [value]
24+
* @param {NodeLike | null | undefined} [node]
2525
* estree node.
2626
* @returns {Position}
2727
* unist position.
2828
*/
29-
export function positionFromEstree(value) {
30-
const node = value || {}
31-
const loc = node.loc || {}
32-
const range = node.range || [0, 0]
29+
export function positionFromEstree(node) {
30+
const nodeLike = node || {}
31+
const loc = nodeLike.loc || {}
32+
const range = nodeLike.range || [0, 0]
3333
const startColumn = loc.start
3434
? numberOrUndefined(loc.start.column)
3535
: undefined
@@ -41,14 +41,14 @@ export function positionFromEstree(value) {
4141
line: loc.start ? numberOrUndefined(loc.start.line) : undefined,
4242
// @ts-expect-error: return no point / no position next major.
4343
column: startColumn === undefined ? undefined : startColumn + 1,
44-
offset: numberOrUndefined(range[0] || node.start)
44+
offset: numberOrUndefined(range[0] || nodeLike.start)
4545
},
4646
end: {
4747
// @ts-expect-error: return no point / no position next major.
4848
line: loc.end ? numberOrUndefined(loc.end.line) : undefined,
4949
// @ts-expect-error: return no point / no position next major.
5050
column: endColumn === undefined ? undefined : endColumn + 1,
51-
offset: numberOrUndefined(range[1] || node.end)
51+
offset: numberOrUndefined(range[1] || nodeLike.end)
5252
}
5353
}
5454
}

readme.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ nodes.
3636
## Install
3737

3838
This package is [ESM only][esm].
39-
In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [npm][]:
39+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
4040

4141
```sh
4242
npm install unist-util-position-from-estree
@@ -92,12 +92,21 @@ Yields:
9292

9393
## API
9494

95-
This package exports the identifier `positionFromEstree`.
95+
This package exports the identifier [`positionFromEstree`][positionfromestree].
9696
There is no default export.
9797

9898
### `positionFromEstree(node)`
9999

100-
Given a [`node`][estree], returns a [`position`][position].
100+
Turn an estree `node` into a unist `position`.
101+
102+
###### Parameters
103+
104+
* `node` ([`Node`][node])
105+
— estree node
106+
107+
###### Returns
108+
109+
unist position ([`Position`][position]).
101110

102111
## Types
103112

@@ -108,7 +117,7 @@ It exports no additional types.
108117

109118
Projects maintained by the unified collective are compatible with all maintained
110119
versions of Node.js.
111-
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
120+
As of now, that is Node.js 14.14+ and 16.0+.
112121
Our projects sometimes work with older versions, but this is not guaranteed.
113122

114123
## Contribute
@@ -175,6 +184,10 @@ abide by its terms.
175184

176185
[estree]: https://github.com/estree/estree
177186

187+
[node]: https://github.com/estree/estree/blob/master/es5.md#node-objects
188+
178189
[unist]: https://github.com/syntax-tree/unist
179190

180191
[position]: https://github.com/syntax-tree/unist#position
192+
193+
[positionfromestree]: #positionfromestreenode

0 commit comments

Comments
 (0)