blob: 3d78a4442f72be8167c2ecd3ed2690349716b7ce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
'use strict'
var own = {}.hasOwnProperty
module.exports = stringify
function stringify(value) {
// Nothing.
if (!value || typeof value !== 'object') {
return ''
}
// Node.
if (own.call(value, 'position') || own.call(value, 'type')) {
return position(value.position)
}
// Position.
if (own.call(value, 'start') || own.call(value, 'end')) {
return position(value)
}
// Point.
if (own.call(value, 'line') || own.call(value, 'column')) {
return point(value)
}
// ?
return ''
}
function point(point) {
if (!point || typeof point !== 'object') {
point = {}
}
return index(point.line) + ':' + index(point.column)
}
function position(pos) {
if (!pos || typeof pos !== 'object') {
pos = {}
}
return point(pos.start) + '-' + point(pos.end)
}
function index(value) {
return value && typeof value === 'number' ? value : 1
}
|