vfile-location
!Buildbuild-badgebuild
!Coveragecoverage-badgecoverage
!Downloadsdownloads-badgedownloads
!Sizesize-badgesize
!Sponsorssponsors-badgecollective
!Backersbackers-badgecollective
!Chatchat-badgechatConvert between positional (line and column-based) and offsets (range-based) locations in a virtual filevfile.
Install
This package is ESM only: Node 12+ is needed to use it and it must beimport
ed instead of require
d.npm install vfile-location
## Use
```js
import {VFile} from 'vfile'
import {location} from 'vfile-location'
var place = location(new VFile('foo\nbar\nbaz'))
var offset = place.toOffset({line: 3, column: 3}) // => 10
place.toPoint(offset) // => {line: 3, column: 3, offset: 10}
API
This package exports the following identifiers:place
.
There is no default export.place = location(doc)
Get transform functions for the given doc
(string
) or file
vfile.Returns an object with
toOffset
to-offset and toPoint
to-point.place.toOffset(point)
Get the offset
(number
) for a line and column-based point
point in the
bound file.
Returns -1
when given invalid or out of bounds input.place.toPoint(offset)
Get the line and column-based point
point for offset
in the bound file.Contribute
Seecontributing.md
contributing in vfile/.github
health for ways to
get started.
See support.md
support for ways to get help.This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.