版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 2.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # vfile-location
  2. [![Build][build-badge]][build]
  3. [![Coverage][coverage-badge]][coverage]
  4. [![Downloads][downloads-badge]][downloads]
  5. [![Size][size-badge]][size]
  6. [![Sponsors][sponsors-badge]][collective]
  7. [![Backers][backers-badge]][collective]
  8. [![Chat][chat-badge]][chat]
  9. Convert between positional (line and column-based) and offsets (range-based)
  10. locations in a [virtual file][vfile].
  11. ## Install
  12. [npm][]:
  13. ```sh
  14. npm install vfile-location
  15. ```
  16. ## Use
  17. ```js
  18. var vfile = require('vfile')
  19. var vfileLocation = require('vfile-location')
  20. var location = vfileLocation(vfile('foo\nbar\nbaz'))
  21. var offset = location.toOffset({line: 3, column: 3}) // => 10
  22. location.toPoint(offset) // => {line: 3, column: 3, offset: 10}
  23. ```
  24. ## API
  25. ### `location = vfileLocation(doc)`
  26. Get transform functions for the given `doc` (`string`) or [`file`][vfile].
  27. Returns an object with [`toOffset`][to-offset] and [`toPoint`][to-point].
  28. ### `location.toOffset(point)`
  29. Get the `offset` (`number`) for a line and column-based [`point`][point] in the
  30. bound file.
  31. Returns `-1` when given invalid or out of bounds input.
  32. ### `location.toPoint(offset)`
  33. Get the line and column-based [`point`][point] for `offset` in the bound file.
  34. ## Contribute
  35. See [`contributing.md`][contributing] in [`vfile/.github`][health] for ways to
  36. get started.
  37. See [`support.md`][support] for ways to get help.
  38. This project has a [code of conduct][coc].
  39. By interacting with this repository, organization, or community you agree to
  40. abide by its terms.
  41. ## License
  42. [MIT][license] © [Titus Wormer][author]
  43. <!-- Definitions -->
  44. [build-badge]: https://img.shields.io/travis/vfile/vfile-location.svg
  45. [build]: https://travis-ci.org/vfile/vfile-location
  46. [coverage-badge]: https://img.shields.io/codecov/c/github/vfile/vfile-location.svg
  47. [coverage]: https://codecov.io/github/vfile/vfile-location
  48. [downloads-badge]: https://img.shields.io/npm/dm/vfile-location.svg
  49. [downloads]: https://www.npmjs.com/package/vfile-location
  50. [size-badge]: https://img.shields.io/bundlephobia/minzip/vfile-location.svg
  51. [size]: https://bundlephobia.com/result?p=vfile-location
  52. [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
  53. [backers-badge]: https://opencollective.com/unified/backers/badge.svg
  54. [collective]: https://opencollective.com/unified
  55. [chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
  56. [chat]: https://github.com/vfile/vfile/discussions
  57. [npm]: https://docs.npmjs.com/cli/install
  58. [contributing]: https://github.com/vfile/.github/blob/HEAD/contributing.md
  59. [support]: https://github.com/vfile/.github/blob/HEAD/support.md
  60. [health]: https://github.com/vfile/.github
  61. [coc]: https://github.com/vfile/.github/blob/HEAD/code-of-conduct.md
  62. [license]: license
  63. [author]: https://wooorm.com
  64. [vfile]: https://github.com/vfile/vfile
  65. [to-offset]: #locationtooffsetpoint
  66. [to-point]: #locationtopointoffset
  67. [point]: https://github.com/syntax-tree/unist#point