IF Commons GitHub

span

Spans and positions of SQL text (commons lang-sql 0001-sql-lang FR-014): a span is a half-open range of offsets, and a position is a line and a column, each from 1, with the offset, found from an offset by a binary search over the starts of the lines, made once. Offsets, columns and lengths are UTF-16 code units, as a JavaScript string and a unist position have them.

const index = lineIndex("select 1\nfrom t");
positionAt(index, 9); // { line: 2, column: 1, offset: 9 }

Spec: 0001-sql-lang FR-014

Source: commons/lang-sql/src/span.ts

2 of 5 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

LineIndexinterfaceno test imports it
interface LineIndex

The starts of the lines of one text, made once by lineIndex.

MemberTypeWhat it is
startsreadonly number[]The offset at which each line begins; the first is 0.
lengthnumberThe length of the text.
lineIndexfunction
function lineIndex(text: string): LineIndex

Makes the index of the lines of a text: a line ends at \n, \r\n or a lone \r.

ParameterWhat it is
textthe text

Returns: the offsets at which its lines begin

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

Positioninterfaceno test imports it
interface Position

A place in a text: a line and a column, each counted from 1, and the offset, counted from 0.

MemberTypeWhat it is
linenumber
columnnumber
offsetnumber
positionAtfunction
function positionAt(index: LineIndex, offset: number): Position

The position of an offset; an offset outside the text is placed at its nearest end.

ParameterWhat it is
indexthe index of the text's lines
offsetan offset in the text

Returns: its line, column and offset

Imported by 6 tests of the run (6 passed, 0 failed): the library's results

Spaninterfaceno test imports it
interface Span

A half-open range of offsets in a text: start is in it, end is not.

MemberTypeWhat it is
startnumber
endnumber

Titles, headings, exports, tables, columns and requirements. Esc closes.