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 \n from 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.
LineIndexinterface no test imports it interface LineIndex The starts of the lines of one text, made once by lineIndex.
Member Type What it is startsreadonly number[]The offset at which each line begins; the first is 0. lengthnumberThe length of the text.
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.
Parameter What 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
Positioninterface no 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.
Member Type What it is linenumbercolumnnumberoffsetnumber
function positionAt (index : LineIndex , offset : number ): Position The position of an offset; an offset outside the text is placed at its nearest end.
Parameter What 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
Spaninterface no test imports it interface Span A half-open range of offsets in a text: start is in it, end is not.
Member Type What it is startnumberendnumber