Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 22-Nov-2021 | - | ||||
LICENSE | H A D | 22-Nov-2021 | 1.1 KiB | 23 | 18 | |
package.json | H A D | 22-Nov-2021 | 1.6 KiB | 62 | 61 | |
readme.md | H A D | 22-Nov-2021 | 1.6 KiB | 73 | 43 |
readme.md
1# vfile-location [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] 2 3Convert between positions (line and column-based) and offsets 4(range-based) locations in a [virtual file][vfile]. 5 6## Installation 7 8[npm][]: 9 10```bash 11npm install vfile-location 12``` 13 14## Usage 15 16```js 17var vfile = require('vfile'); 18var vfileLocation = require('vfile-location'); 19var location = vfileLocation(vfile('foo\nbar\nbaz')); 20 21location.toOffset({line: 3, column: 3}); //=> 10 22location.toPosition(offset); //=> {line: 3, column: 3, offset: 10} 23``` 24 25## API 26 27### `location = vfileLocation(doc)` 28 29Get transform functions for the given `doc` (`string`) or 30[`file`][vfile]. 31 32Returns an object with [`toOffset`][to-offset] and 33[`toPosition`][to-position]. 34 35### `location.toOffset(position)` 36 37Get the `offset` (`number`) for a line and column-based 38[`position`][position] in the bound file. Returns `-1` 39when given invalid or out of bounds input. 40 41### `location.toPosition(offset)` 42 43Get the line and column-based [`position`][position] for `offset` in 44the bound file. 45 46## License 47 48[MIT][license] © [Titus Wormer][author] 49 50<!-- Definitions --> 51 52[travis-badge]: https://img.shields.io/travis/vfile/vfile-location.svg 53 54[travis]: https://travis-ci.org/vfile/vfile-location 55 56[codecov-badge]: https://img.shields.io/codecov/c/github/vfile/vfile-location.svg 57 58[codecov]: https://codecov.io/github/vfile/vfile-location 59 60[npm]: https://docs.npmjs.com/cli/install 61 62[license]: LICENSE 63 64[author]: http://wooorm.com 65 66[vfile]: https://github.com/vfile/vfile 67 68[to-offset]: #locationtooffsetposition 69 70[to-position]: #locationtopositionoffset 71 72[position]: https://github.com/syntax-tree/unist#position 73