positionAt() — astro Function Reference
Architecture documentation for the positionAt() function in utils.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD b70271ae_4018_71fe_f092_f1b7ce0476d7["positionAt()"] a37e7fee_e130_2a00_6f99_81cf3cf65c83["utils.ts"] b70271ae_4018_71fe_f092_f1b7ce0476d7 -->|defined in| a37e7fee_e130_2a00_6f99_81cf3cf65c83 d8849cd9_ed6a_f4bb_959f_98a475c3e22e["getLineOffsets()"] b70271ae_4018_71fe_f092_f1b7ce0476d7 -->|calls| d8849cd9_ed6a_f4bb_959f_98a475c3e22e style b70271ae_4018_71fe_f092_f1b7ce0476d7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/core/errors/utils.ts lines 11–50
export function positionAt(
offset: number,
text: string,
): {
line: number;
column: number;
} {
const lineOffsets = getLineOffsets(text);
offset = Math.max(0, Math.min(text.length, offset));
let low = 0;
let high = lineOffsets.length;
if (high === 0) {
return {
line: 0,
column: offset,
};
}
while (low <= high) {
const mid = Math.floor((low + high) / 2);
const lineOffset = lineOffsets[mid];
if (lineOffset === offset) {
return {
line: mid,
column: 0,
};
} else if (offset > lineOffset) {
low = mid + 1;
} else {
high = mid - 1;
}
}
// low is the least x for which the line offset is larger than the current offset
// or array.length if no line offset is larger than the current offset
const line = low - 1;
return { line, column: offset - lineOffsets[line] };
}
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does positionAt() do?
positionAt() is a function in the astro codebase, defined in packages/astro/src/core/errors/utils.ts.
Where is positionAt() defined?
positionAt() is defined in packages/astro/src/core/errors/utils.ts at line 11.
What does positionAt() call?
positionAt() calls 1 function(s): getLineOffsets.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free