Nightly Perpetrated Mischief
    Have ideas to improve npm?Join in the discussion! »

    vfile-location
    TypeScript icon, indicating that this package has built-in type declarations

    4.0.0 • Public • Published

    vfile-location

    Build Coverage Downloads Size Sponsors Backers Chat

    Convert between positional (line and column-based) and offsets (range-based) locations in a virtual file.

    Install

    This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

    npm:

    npm install vfile-location

    Use

    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.

    Returns an object with toOffset and toPoint.

    place.toOffset(point)

    Get the offset (number) for a line and column-based 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 for offset in the bound file.

    Contribute

    See contributing.md in vfile/.github for ways to get started. See support.md for ways to get help.

    This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

    License

    MIT © Titus Wormer

    Install

    npm i vfile-location

    DownloadsWeekly Downloads

    4,242,220

    Version

    4.0.0

    License

    MIT

    Unpacked Size

    9.17 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar