Skip to content

Commit d23f808

Browse files
committed
Refactor to move implementation to lib/
1 parent e79fa69 commit d23f808

File tree

3 files changed

+56
-54
lines changed

3 files changed

+56
-54
lines changed

index.js

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1 @@
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'

lib/index.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"main": "index.js",
2828
"types": "index.d.ts",
2929
"files": [
30+
"lib/",
3031
"index.d.ts",
3132
"index.js"
3233
],

0 commit comments

Comments
 (0)