1
1
/**
2
- * @typedef {import('unist').Point } Point
3
- * @typedef {import('../types.js').TrackFields } TrackFields
2
+ * @typedef {import('../types.js').CreateTracker } CreateTracker
3
+ * @typedef {import('../types.js').TrackCurrent } TrackCurrent
4
+ * @typedef {import('../types.js').TrackMove } TrackMove
5
+ * @typedef {import('../types.js').TrackShift } TrackShift
4
6
*/
5
7
6
8
/**
7
- * Functions to track output positions .
9
+ * Track positional info in the output .
8
10
*
9
- * This info isn’t used yet but suchs functionality allows line wrapping,
10
- * and theoretically source maps (though, is there practical use in that?).
11
- *
12
- * @param {TrackFields } options_
11
+ * @type {CreateTracker }
13
12
*/
14
- export function track ( options_ ) {
13
+ export function track ( config ) {
15
14
// Defaults are used to prevent crashes when older utilities somehow activate
16
15
// this code.
17
16
/* c8 ignore next 5 */
18
- const options = options_ || { }
17
+ const options = config || { }
19
18
const now = options . now || { }
20
19
let lineShift = options . lineShift || 0
21
20
let line = now . line || 1
@@ -26,7 +25,7 @@ export function track(options_) {
26
25
/**
27
26
* Get the current tracked info.
28
27
*
29
- * @returns { TrackFields }
28
+ * @type { TrackCurrent }
30
29
*/
31
30
function current ( ) {
32
31
return { now : { line, column} , lineShift}
@@ -35,19 +34,20 @@ export function track(options_) {
35
34
/**
36
35
* Define an increased line shift (the typical indent for lines).
37
36
*
38
- * @param { number } value
37
+ * @type { TrackShift }
39
38
*/
40
39
function shift ( value ) {
41
40
lineShift += value
42
41
}
43
42
44
43
/**
45
- * Move past a string .
44
+ * Move past some generated markdown .
46
45
*
47
- * @param {string } value
48
- * @returns {string }
46
+ * @type {TrackMove }
49
47
*/
50
- function move ( value = '' ) {
48
+ function move ( input ) {
49
+ // eslint-disable-next-line unicorn/prefer-default-parameters
50
+ const value = input || ''
51
51
const chunks = value . split ( / \r ? \n | \r / g)
52
52
const tail = chunks [ chunks . length - 1 ]
53
53
line += chunks . length - 1
0 commit comments