1.2.0 • Published 4 years ago

licofi v1.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

licofi

Micro library for converting index in a string to line/column and back

API

LineColumnFinder(sourceString, options = {})

Options

KeyDescriptionDefault
lineBreakWhat character sequence to treat as linebreak"\n"
originSet to 0 to use zero-based line/column numbering1

LineColumnFinder.fromIndex(index)

Convert index to line/column. Provided index should be zero-based.

Example return value:

{line: 1, column: 5}

LineColumnFinder.fromLineColumn({line, column})

Convert line/column to index in source string. Returned index is zero-based.

Example

import {LineColumnFinder} from "licofi";
// or
const {LineColumnFinder} = require("licofi");

const string = "Hello\nWorld\n!";
const finder = new LineColumnFinder(string);

finder.fromIndex(6)
// -> {line: 2, column: 1}

finder.fromLineColumn({line: 2, column: 1})
// -> 6

Benchmarks

Columns

ColumnDescription
libName of library
memory usageHeap memory usage
indexTime spent generating lookup indexes
queryTime spent searching
totalindex + query

Aborted means that library did not finish that benchmark within 10 seconds

very short text (10 lines), 344 queries

libmemory usageindexquerytotal
find-line-column354 kb0 ms1 ms1 ms
simple-text-buffer140 kb2 ms3 ms5 ms
char-props29 kb0 ms0 ms0 ms
vfile-location35 kb0 ms1 ms1 ms
lines-and-columns27 kb0 ms0 ms0 ms
string-pos59 kb0 ms1 ms1 ms
vscode-textbuffer109 kb1 ms0 ms1 ms
line-column25 kb0 ms1 ms1 ms
licofi23 kb0 ms0 ms0 ms

short text (100 lines), 3988 queries

libmemory usageindexquerytotal
find-line-column3,650 kb0 ms28 ms28 ms
simple-text-buffer861 kb1 ms24 ms25 ms
char-props282 kb0 ms3 ms3 ms
vfile-location220 kb0 ms2 ms2 ms
lines-and-columns180 kb0 ms2 ms2 ms
string-pos581 kb0 ms4 ms4 ms
vscode-textbuffer761 kb1 ms6 ms7 ms
line-column232 kb0 ms3 ms3 ms
licofi168 kb0 ms2 ms2 ms

medium text (1000 lines), 48598 queries

libmemory usageindexquerytotal
find-line-column10,699 kb0 ms3032 ms3032 ms
simple-text-buffer6,643 kb5 ms268 ms273 ms
char-props466 kb0 ms39 ms39 ms
vfile-location221 kb0 ms22 ms22 ms
lines-and-columns166 kb2 ms19 ms21 ms
string-pos548 kb0 ms13 ms13 ms
vscode-textbuffer2,335 kb2 ms10 ms12 ms
line-column376 kb0 ms6 ms6 ms
licofi308 kb0 ms6 ms6 ms

long text (10000 lines), 50000 queries

libmemory usageindexquerytotal
find-line-columnABORTED
simple-text-buffer14,758 kb31 ms461 ms492 ms
char-props1,346 kb2 ms406 ms408 ms
vfile-location368 kb2 ms185 ms187 ms
lines-and-columns415 kb2 ms157 ms159 ms
string-pos903 kb0 ms19 ms19 ms
vscode-textbuffer2,838 kb2 ms16 ms18 ms
line-column765 kb1 ms8 ms9 ms
licofi450 kb2 ms7 ms9 ms

very long text (100000 lines), 50000 queries

libmemory usageindexquerytotal
find-line-columnABORTED
simple-text-buffer53,572 kb194 ms647 ms841 ms
char-props10,321 kb9 ms3572 ms3581 ms
vfile-location2,998 kb5 ms1785 ms1790 ms
lines-and-columns2,959 kb7 ms1502 ms1509 ms
string-pos6,318 kb0 ms29 ms29 ms
vscode-textbuffer5,391 kb8 ms17 ms25 ms
line-column4,208 kb6 ms9 ms15 ms
licofi3,033 kb5 ms9 ms14 ms
1.2.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago