Urara-Blog/node_modules/.pnpm-store/v3/files/3d/95152f36d8f3ddb95f61d747f9541862d41e918632e8b9382191acf0aaa8ffc0c512b5bd5be79b30a1f18028c8e70585d0a2648f9ba7826bc6321b7b7801e1
2022-08-14 01:14:53 +08:00

62 lines
1.3 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @typedef {import('unist').Point} Point
* @typedef {import('unist').Node} Node
* @typedef {import('unist').Position} Position
* @typedef {object & {type: string, position?: Position|undefined}} NodeLike
*/
/**
* Stringify one point, a position (start and end points), or a nodes
* positional information.
*
* @param {Node|NodeLike|Position|Point|null} [value]
* @returns {string}
*/
export function stringifyPosition(value) {
// Nothing.
if (!value || typeof value !== 'object') {
return ''
}
// Node.
if ('position' in value || 'type' in value) {
return position(value.position)
}
// Position.
if ('start' in value || 'end' in value) {
return position(value)
}
// Point.
if ('line' in value || 'column' in value) {
return point(value)
}
// ?
return ''
}
/**
* @param {Point|undefined} point
* @returns {string}
*/
function point(point) {
return index(point && point.line) + ':' + index(point && point.column)
}
/**
* @param {Position|undefined} pos
* @returns {string}
*/
function position(pos) {
return point(pos && pos.start) + '-' + point(pos && pos.end)
}
/**
* @param {number|undefined} value
* @returns {number}
*/
function index(value) {
return value && typeof value === 'number' ? value : 1
}