This commit is contained in:
74
node_modules/vfile-location/index.js
generated
vendored
Normal file
74
node_modules/vfile-location/index.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = factory
|
||||
|
||||
function factory(file) {
|
||||
var contents = indices(String(file))
|
||||
|
||||
return {
|
||||
toPosition: offsetToPositionFactory(contents),
|
||||
toOffset: positionToOffsetFactory(contents)
|
||||
}
|
||||
}
|
||||
|
||||
// Factory to get the line and column-based `position` for `offset` in the bound
|
||||
// indices.
|
||||
function offsetToPositionFactory(indices) {
|
||||
return offsetToPosition
|
||||
|
||||
// Get the line and column-based `position` for `offset` in the bound indices.
|
||||
function offsetToPosition(offset) {
|
||||
var index = -1
|
||||
var length = indices.length
|
||||
|
||||
if (offset < 0) {
|
||||
return {}
|
||||
}
|
||||
|
||||
while (++index < length) {
|
||||
if (indices[index] > offset) {
|
||||
return {
|
||||
line: index + 1,
|
||||
column: offset - (indices[index - 1] || 0) + 1,
|
||||
offset: offset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
// Factory to get the `offset` for a line and column-based `position` in the
|
||||
// bound indices.
|
||||
function positionToOffsetFactory(indices) {
|
||||
return positionToOffset
|
||||
|
||||
// Get the `offset` for a line and column-based `position` in the bound
|
||||
// indices.
|
||||
function positionToOffset(position) {
|
||||
var line = position && position.line
|
||||
var column = position && position.column
|
||||
|
||||
if (!isNaN(line) && !isNaN(column) && line - 1 in indices) {
|
||||
return (indices[line - 2] || 0) + column - 1 || 0
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
// Get indices of line-breaks in `value`.
|
||||
function indices(value) {
|
||||
var result = []
|
||||
var index = value.indexOf('\n')
|
||||
|
||||
while (index !== -1) {
|
||||
result.push(index + 1)
|
||||
index = value.indexOf('\n', index + 1)
|
||||
}
|
||||
|
||||
result.push(value.length + 1)
|
||||
|
||||
return result
|
||||
}
|
||||
22
node_modules/vfile-location/license
generated
vendored
Normal file
22
node_modules/vfile-location/license
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2016 Titus Wormer <tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
73
node_modules/vfile-location/package.json
generated
vendored
Normal file
73
node_modules/vfile-location/package.json
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"name": "vfile-location",
|
||||
"version": "2.0.6",
|
||||
"description": "Convert between positions (line and column-based) and offsets (range-based) locations in a virtual file",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"remark",
|
||||
"comment",
|
||||
"message",
|
||||
"marker",
|
||||
"control"
|
||||
],
|
||||
"repository": "vfile/vfile-location",
|
||||
"bugs": "https://github.com/vfile/vfile-location/issues",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"browserify": "^16.0.0",
|
||||
"nyc": "^14.0.0",
|
||||
"prettier": "^1.0.0",
|
||||
"remark-cli": "^7.0.0",
|
||||
"remark-preset-wooorm": "^6.0.0",
|
||||
"tape": "^4.0.0",
|
||||
"tinyify": "^2.0.0",
|
||||
"vfile": "^4.0.0",
|
||||
"xo": "^0.25.0"
|
||||
},
|
||||
"scripts": {
|
||||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
|
||||
"build-bundle": "browserify . -s vfileLocation > vfile-location.js",
|
||||
"build-mangle": "browserify . -s vfileLocation -p tinyify > vfile-location.min.js",
|
||||
"build": "npm run build-bundle && npm run build-mangle",
|
||||
"test-api": "node test",
|
||||
"test-coverage": "nyc --reporter lcov tape test.js",
|
||||
"test": "npm run format && npm run build && npm run test-coverage"
|
||||
},
|
||||
"nyc": {
|
||||
"check-coverage": true,
|
||||
"lines": 100,
|
||||
"functions": 100,
|
||||
"branches": 100
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"esnext": false,
|
||||
"ignores": [
|
||||
"vfile-location.js"
|
||||
]
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
}
|
||||
}
|
||||
115
node_modules/vfile-location/readme.md
generated
vendored
Normal file
115
node_modules/vfile-location/readme.md
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
# vfile-location
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
[![Sponsors][sponsors-badge]][collective]
|
||||
[![Backers][backers-badge]][collective]
|
||||
[![Chat][chat-badge]][chat]
|
||||
|
||||
Convert between positions (line and column-based) and offsets (range-based)
|
||||
locations in a [virtual file][vfile].
|
||||
|
||||
## Install
|
||||
|
||||
[npm][]:
|
||||
|
||||
```sh
|
||||
npm install vfile-location
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var vfile = require('vfile')
|
||||
var vfileLocation = require('vfile-location')
|
||||
|
||||
var location = vfileLocation(vfile('foo\nbar\nbaz'))
|
||||
|
||||
var offset = location.toOffset({line: 3, column: 3}) // => 10
|
||||
location.toPosition(offset) // => {line: 3, column: 3, offset: 10}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `location = vfileLocation(doc)`
|
||||
|
||||
Get transform functions for the given `doc` (`string`) or [`file`][vfile].
|
||||
|
||||
Returns an object with [`toOffset`][to-offset] and [`toPosition`][to-position].
|
||||
|
||||
### `location.toOffset(position)`
|
||||
|
||||
Get the `offset` (`number`) for a line and column-based [`position`][position]
|
||||
in the bound file.
|
||||
Returns `-1` when given invalid or out of bounds input.
|
||||
|
||||
### `location.toPosition(offset)`
|
||||
|
||||
Get the line and column-based [`position`][position] for `offset` in the bound
|
||||
file.
|
||||
|
||||
## Contribute
|
||||
|
||||
See [`contributing.md`][contributing] in [`vfile/.github`][health] for ways to
|
||||
get started.
|
||||
See [`support.md`][support] for ways to get help.
|
||||
|
||||
This project has a [Code of Conduct][coc].
|
||||
By interacting with this repository, organisation, or community you agree to
|
||||
abide by its terms.
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[build-badge]: https://img.shields.io/travis/vfile/vfile-location.svg
|
||||
|
||||
[build]: https://travis-ci.org/vfile/vfile-location
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/vfile/vfile-location.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/vfile/vfile-location
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/vfile-location.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/vfile-location
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/vfile-location.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=vfile-location
|
||||
|
||||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
|
||||
|
||||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
|
||||
|
||||
[collective]: https://opencollective.com/unified
|
||||
|
||||
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
|
||||
|
||||
[chat]: https://spectrum.chat/unified/vfile
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[contributing]: https://github.com/vfile/.github/blob/master/contributing.md
|
||||
|
||||
[support]: https://github.com/vfile/.github/blob/master/support.md
|
||||
|
||||
[health]: https://github.com/vfile/.github
|
||||
|
||||
[coc]: https://github.com/vfile/.github/blob/master/code-of-conduct.md
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[vfile]: https://github.com/vfile/vfile
|
||||
|
||||
[to-offset]: #locationtooffsetposition
|
||||
|
||||
[to-position]: #locationtopositionoffset
|
||||
|
||||
[position]: https://github.com/syntax-tree/unist#position
|
||||
Reference in New Issue
Block a user