MCPcopy
hub / github.com/vitejs/vite / posToNumber

Function posToNumber

packages/vite/src/node/utils.ts:460–469  ·  view source on GitHub ↗
(source: string, pos: number | Pos)

Source from the content-addressed store, hash-verified

458}
459
460export function posToNumber(source: string, pos: number | Pos): number {
461 if (typeof pos === 'number') return pos
462 const lines = source.split(splitRE)
463 const { line, column } = pos
464 let start = 0
465 for (let i = 0; i < line - 1 && i < lines.length; i++) {
466 start += lines[i].length + 1
467 }
468 return start + column
469}
470
471export function numberToPos(source: string, offset: number | Pos): Pos {
472 if (typeof offset !== 'number') return offset

Callers 2

utils.spec.tsFile · 0.90
generateCodeFrameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected