.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / vfile-location / readme.md
1 # vfile-location
2
3 [![Build][build-badge]][build]
4 [![Coverage][coverage-badge]][coverage]
5 [![Downloads][downloads-badge]][downloads]
6 [![Size][size-badge]][size]
7 [![Sponsors][sponsors-badge]][collective]
8 [![Backers][backers-badge]][collective]
9 [![Chat][chat-badge]][chat]
10
11 Convert between positions (line and column-based) and offsets (range-based)
12 locations in a [virtual file][vfile].
13
14 ## Install
15
16 [npm][]:
17
18 ```sh
19 npm install vfile-location
20 ```
21
22 ## Usage
23
24 ```js
25 var vfile = require('vfile')
26 var vfileLocation = require('vfile-location')
27
28 var location = vfileLocation(vfile('foo\nbar\nbaz'))
29
30 var offset = location.toOffset({line: 3, column: 3}) // => 10
31 location.toPosition(offset) // => {line: 3, column: 3, offset: 10}
32 ```
33
34 ## API
35
36 ### `location = vfileLocation(doc)`
37
38 Get transform functions for the given `doc` (`string`) or [`file`][vfile].
39
40 Returns an object with [`toOffset`][to-offset] and [`toPosition`][to-position].
41
42 ### `location.toOffset(position)`
43
44 Get the `offset` (`number`) for a line and column-based [`position`][position]
45 in the bound file.
46 Returns `-1` when given invalid or out of bounds input.
47
48 ### `location.toPosition(offset)`
49
50 Get the line and column-based [`position`][position] for `offset` in the bound
51 file.
52
53 ## Contribute
54
55 See [`contributing.md`][contributing] in [`vfile/.github`][health] for ways to
56 get started.
57 See [`support.md`][support] for ways to get help.
58
59 This project has a [Code of Conduct][coc].
60 By interacting with this repository, organisation, or community you agree to
61 abide by its terms.
62
63 ## License
64
65 [MIT][license] © [Titus Wormer][author]
66
67 <!-- Definitions -->
68
69 [build-badge]: https://img.shields.io/travis/vfile/vfile-location.svg
70
71 [build]: https://travis-ci.org/vfile/vfile-location
72
73 [coverage-badge]: https://img.shields.io/codecov/c/github/vfile/vfile-location.svg
74
75 [coverage]: https://codecov.io/github/vfile/vfile-location
76
77 [downloads-badge]: https://img.shields.io/npm/dm/vfile-location.svg
78
79 [downloads]: https://www.npmjs.com/package/vfile-location
80
81 [size-badge]: https://img.shields.io/bundlephobia/minzip/vfile-location.svg
82
83 [size]: https://bundlephobia.com/result?p=vfile-location
84
85 [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
86
87 [backers-badge]: https://opencollective.com/unified/backers/badge.svg
88
89 [collective]: https://opencollective.com/unified
90
91 [chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
92
93 [chat]: https://spectrum.chat/unified/vfile
94
95 [npm]: https://docs.npmjs.com/cli/install
96
97 [contributing]: https://github.com/vfile/.github/blob/master/contributing.md
98
99 [support]: https://github.com/vfile/.github/blob/master/support.md
100
101 [health]: https://github.com/vfile/.github
102
103 [coc]: https://github.com/vfile/.github/blob/master/code-of-conduct.md
104
105 [license]: license
106
107 [author]: https://wooorm.com
108
109 [vfile]: https://github.com/vfile/vfile
110
111 [to-offset]: #locationtooffsetposition
112
113 [to-position]: #locationtopositionoffset
114
115 [position]: https://github.com/syntax-tree/unist#position