syntax-tree / unist-util-stringify-position

Compare 70fedb5 ... +22 ... 3b9f4cd

Coverage Reach
index.js

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 14 files from the diff.

@@ -1,50 +1,62 @@
Loading
1 -
'use strict'
2 -
3 -
var own = {}.hasOwnProperty
4 -
5 -
module.exports = stringify
6 -
7 -
function stringify(value) {
1 +
/**
2 +
 * @typedef {import('unist').Point} Point
3 +
 * @typedef {import('unist').Node} Node
4 +
 * @typedef {import('unist').Position} Position
5 +
 * @typedef {object & {type: string, position?: Position|undefined}} NodeLike
6 +
 */
7 +
8 +
/**
9 +
 * Stringify one point, a position (start and end points), or a node’s
10 +
 * positional information.
11 +
 *
12 +
 * @param {Node|NodeLike|Position|Point|null} [value]
13 +
 * @returns {string}
14 +
 */
15 +
export function stringifyPosition(value) {
8 16
  // Nothing.
9 17
  if (!value || typeof value !== 'object') {
10 18
    return ''
11 19
  }
12 20
13 21
  // Node.
14 -
  if (own.call(value, 'position') || own.call(value, 'type')) {
22 +
  if ('position' in value || 'type' in value) {
15 23
    return position(value.position)
16 24
  }
17 25
18 26
  // Position.
19 -
  if (own.call(value, 'start') || own.call(value, 'end')) {
27 +
  if ('start' in value || 'end' in value) {
20 28
    return position(value)
21 29
  }
22 30
23 31
  // Point.
24 -
  if (own.call(value, 'line') || own.call(value, 'column')) {
32 +
  if ('line' in value || 'column' in value) {
25 33
    return point(value)
26 34
  }
27 35
28 36
  // ?
29 37
  return ''
30 38
}
31 39
40 +
/**
41 +
 * @param {Point|undefined} point
42 +
 * @returns {string}
43 +
 */
32 44
function point(point) {
33 -
  if (!point || typeof point !== 'object') {
34 -
    point = {}
35 -
  }
36 -
37 -
  return index(point.line) + ':' + index(point.column)
45 +
  return index(point && point.line) + ':' + index(point && point.column)
38 46
}
39 47
48 +
/**
49 +
 * @param {Position|undefined} pos
50 +
 * @returns {string}
51 +
 */
40 52
function position(pos) {
41 -
  if (!pos || typeof pos !== 'object') {
42 -
    pos = {}
43 -
  }
44 -
45 -
  return point(pos.start) + '-' + point(pos.end)
53 +
  return point(pos && pos.start) + '-' + point(pos && pos.end)
46 54
}
47 55
56 +
/**
57 +
 * @param {number|undefined} value
58 +
 * @returns {number}
59 +
 */
48 60
function index(value) {
49 61
  return value && typeof value === 'number' ? value : 1
50 62
}

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
index.js 100.00%
Project Totals (1 files) 100.00%
Loading