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