vfile-location

vfile utility to convert between positional (line and column-based) and offset (range-based) locations

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
vfile-location
1204.0.12 years ago7 years agoMinified + gzip package size for vfile-location in KB

Readme

vfile-location
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
Convert 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 be imported instead of required.
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 filevfile.
Returns an object with toOffsetto-offset and toPointto-point.

place.toOffset(point)

Get the offset (number) for a line and column-based pointpoint in the bound file. Returns -1 when given invalid or out of bounds input.

place.toPoint(offset)

Get the line and column-based pointpoint for offset in the bound file.

Contribute

See contributing.mdcontributing in vfile/.githubhealth for ways to get started. See support.mdsupport 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.

License

MITlicense © Titus Wormerauthor