file-position

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

MIT 1 个版本
安装
npm install file-position
yarn add file-position
pnpm add file-position
bun add file-position
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.

版本列表
0.0.0 2014-03-12