1.0.0 • Published 7 years ago

string-pos v1.0.0

Weekly downloads
33
License
MIT
Repository
github
Last release
7 years ago

string-pos

Build Status Coverage Code Climate NPM NPM

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

Benchmarks

Notes

  • Compatible with source-map positions.
  • Line numbers are 1 index based.
  • Column numbers are zero index based.

License

MIT © Daniel Kalen