|
1 |
| -/** |
2 |
| - * @typedef {import('unist').Position} Position |
3 |
| - * @typedef {import('unist').Node} Node |
4 |
| - * @typedef {Record<string, unknown> & {type: string, position?: PositionLike|undefined}} NodeLike |
5 |
| - * @typedef {import('unist').Point} Point |
6 |
| - * |
7 |
| - * @typedef {Partial<Point>} PointLike |
8 |
| - * |
9 |
| - * @typedef PositionLike |
10 |
| - * @property {PointLike} [start] |
11 |
| - * @property {PointLike} [end] |
12 |
| - */ |
13 |
| - |
14 |
| -export const pointStart = point('start') |
15 |
| -export const pointEnd = point('end') |
16 |
| - |
17 |
| -/** |
18 |
| - * Get the positional info of `node`. |
19 |
| - * |
20 |
| - * @param {NodeLike|Node} [node] |
21 |
| - * @returns {Position} |
22 |
| - */ |
23 |
| -export function position(node) { |
24 |
| - return {start: pointStart(node), end: pointEnd(node)} |
25 |
| -} |
26 |
| - |
27 |
| -/** |
28 |
| - * Get the positional info of `node`. |
29 |
| - * |
30 |
| - * @param {'start'|'end'} type |
31 |
| - */ |
32 |
| -function point(type) { |
33 |
| - return point |
34 |
| - |
35 |
| - /** |
36 |
| - * Get the positional info of `node`. |
37 |
| - * |
38 |
| - * @param {NodeLike|Node} [node] |
39 |
| - * @returns {Point} |
40 |
| - */ |
41 |
| - function point(node) { |
42 |
| - const point = (node && node.position && node.position[type]) || {} |
43 |
| - |
44 |
| - // To do: next major: don’t return points when invalid. |
45 |
| - return { |
46 |
| - // @ts-expect-error: in practice, null is allowed. |
47 |
| - line: point.line || null, |
48 |
| - // @ts-expect-error: in practice, null is allowed. |
49 |
| - column: point.column || null, |
50 |
| - // @ts-expect-error: in practice, null is allowed. |
51 |
| - offset: point.offset > -1 ? point.offset : null |
52 |
| - } |
53 |
| - } |
54 |
| -} |
| 1 | +export {pointEnd, pointStart, position} from './lib/index.js' |
0 commit comments