unist-util-stringify-position
Stringify a Unist position or location.
Installation
npm:
npm install unist-util-stringify-position
unist-util-stringify-position is also available as an AMD, CommonJS, and
globals module, uncompressed and compressed.
Usage
Dependencies:
var stringifyPosition = require('unist-util-stringify-position');
Given a position:
var result = stringifyPosition({ 'line': 2, 'column': 3 });
Yields:
2:3
Given a (partial) location:
result = stringifyPosition({
'start': { 'line': 2 },
'end': { 'line': 3 }
});
Yields:
2:1-3:1
Given a node:
result = stringifyPosition({
'type': 'text',
'value': '!',
'position': {
'start': { 'line': 5, 'column': 11 },
'end': { 'line': 5, 'column': 12 }
}
});
Yields:
5:11-5:12
API
stringifyPosition(node|location|position)
Stringify one position, a location (start and end positions), or
a node’s location.
Parameters:
-
node
(Node
)
— Node whose 'position'
property to stringify;
-
location
(Location
)
— Location whose 'start'
and 'end'
positions to stringify;
-
position
(Position
)
— Location whose 'line'
and 'column'
to stringify.
Returns: string?
— A range ls:cs-le:ce
(when given node
or
location
) or a point l:c
(when given position
), where l
stands
for line, c
for column, s
for start
, and e
for
end. null
is returned if the given value is neither node
,
location
, nor position
.
License
MIT © Titus Wormer