JSPM

file-position

0.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 115
  • Score
    100M100P100Q62202F
  • License MIT

Given a row/column number, return the index of that character within the whole string

Package Exports

  • file-position

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (file-position) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

file-position Flattr this!experimental

Given a row/column number, return the index of that character within the whole string

Usage

file-position

filePosition(src)(row, column)

Pass filePosition your source file src as a string, and it'll return a function. This function takes a row and a column parameter to look up.

In return, you'll get a single index pointing to the character's position in the entire string.

var position = require('file-position')
var fs = require('fs')

var file = fs.readFileSync(__filename, 'utf8')

var getIndex = position(src)
var column = 10
var row = 5

var index = getIndex(row, column)

License

MIT. See LICENSE.md for details.