string-pos

1.0.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i string-pos

Weekly Downloads

154

Version

1.0.0

License

MIT

Last publish

Collaborators

  • danielkalen