1.0.0 • Published 7 years ago
string-pos v1.0.0
string-pos
Usage
var stringPos = require('coffee-register');
var sample = "abc\n\n123\n \ndef";
stringPos(sample, 0) //-> {line:1, column:0}
stringPos(sample, 2) //-> {line:1, column:2}
stringPos(sample, 4) //-> {line:2, column:0}
stringPos(sample, 7) //-> {line:3, column:2}
stringPos.toIndex(sample, {line:1, column:0}) //-> 0
stringPos.toIndex(sample, {line:1, column:2}) //-> 2
stringPos.toIndex(sample, {line:2, column:0}) //-> 4
stringPos.toIndex(sample, {line:3, column:2}) //-> 7
Benchmarks
Notes
- Compatible with source-map positions.
- Line numbers are 1 index based.
- Column numbers are zero index based.
License
MIT © Daniel Kalen
1.0.0
7 years ago