Socket
Socket
Sign inDemoInstall

vfile-location

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vfile-location - npm Package Compare versions

Comparing version 3.0.1 to 3.1.0

30

index.js

@@ -7,16 +7,18 @@ 'use strict'

var contents = indices(String(file))
var toPoint = offsetToPointFactory(contents)
return {
toPosition: offsetToPositionFactory(contents),
toOffset: positionToOffsetFactory(contents)
toPoint: toPoint,
toPosition: toPoint,
toOffset: pointToOffsetFactory(contents)
}
}
// Factory to get the line and column-based `position` for `offset` in the bound
// Factory to get the line and column-based `point` for `offset` in the bound
// indices.
function offsetToPositionFactory(indices) {
return offsetToPosition
function offsetToPointFactory(indices) {
return offsetToPoint
// Get the line and column-based `position` for `offset` in the bound indices.
function offsetToPosition(offset) {
// Get the line and column-based `point` for `offset` in the bound indices.
function offsetToPoint(offset) {
var index = -1

@@ -43,12 +45,12 @@ var length = indices.length

// Factory to get the `offset` for a line and column-based `position` in the
// Factory to get the `offset` for a line and column-based `point` in the
// bound indices.
function positionToOffsetFactory(indices) {
return positionToOffset
function pointToOffsetFactory(indices) {
return pointToOffset
// Get the `offset` for a line and column-based `position` in the bound
// Get the `offset` for a line and column-based `point` in the bound
// indices.
function positionToOffset(position) {
var line = position && position.line
var column = position && position.column
function pointToOffset(point) {
var line = point && point.line
var column = point && point.column

@@ -55,0 +57,0 @@ if (!isNaN(line) && !isNaN(column) && line - 1 in indices) {

{
"name": "vfile-location",
"version": "3.0.1",
"version": "3.1.0",
"description": "vfile utility to convert between positional (line and column-based) and offset (range-based) locations",

@@ -14,2 +14,3 @@ "license": "MIT",

"location",
"point",
"position",

@@ -40,12 +41,12 @@ "offset"

"nyc": "^15.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",
"prettier": "^2.0.0",
"remark-cli": "^8.0.0",
"remark-preset-wooorm": "^7.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"vfile": "^4.0.0",
"xo": "^0.27.0"
"xo": "^0.33.0"
},
"scripts": {
"format": "remark . -qfo && prettier --write \"**/*.{js,ts}\" && xo --fix",
"format": "remark . -qfo && prettier . --write && xo --fix",
"build-bundle": "browserify . -s vfileLocation > vfile-location.js",

@@ -76,2 +77,5 @@ "build-mangle": "browserify . -s vfileLocation -p tinyify > vfile-location.min.js",

"esnext": false,
"rules": {
"unicorn/prefer-number-properties": "off"
},
"ignores": [

@@ -78,0 +82,0 @@ "vfile-location.js"

@@ -11,3 +11,3 @@ # vfile-location

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

@@ -32,3 +32,3 @@

var offset = location.toOffset({line: 3, column: 3}) // => 10
location.toPosition(offset) // => {line: 3, column: 3, offset: 10}
location.toPoint(offset) // => {line: 3, column: 3, offset: 10}
```

@@ -42,14 +42,13 @@

Returns an object with [`toOffset`][to-offset] and [`toPosition`][to-position].
Returns an object with [`toOffset`][to-offset] and [`toPoint`][to-point].
### `location.toOffset(position)`
### `location.toOffset(point)`
Get the `offset` (`number`) for a line and column-based [`position`][position]
in the bound file.
Get the `offset` (`number`) for a line and column-based [`point`][point] in the
bound file.
Returns `-1` when given invalid or out of bounds input.
### `location.toPosition(offset)`
### `location.toPoint(offset)`
Get the line and column-based [`position`][position] for `offset` in the bound
file.
Get the line and column-based [`point`][point] for `offset` in the bound file.

@@ -94,15 +93,15 @@ ## Contribute

[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://spectrum.chat/unified/vfile
[chat]: https://github.com/vfile/vfile/discussions
[npm]: https://docs.npmjs.com/cli/install
[contributing]: https://github.com/vfile/.github/blob/master/contributing.md
[contributing]: https://github.com/vfile/.github/blob/HEAD/contributing.md
[support]: https://github.com/vfile/.github/blob/master/support.md
[support]: https://github.com/vfile/.github/blob/HEAD/support.md
[health]: https://github.com/vfile/.github
[coc]: https://github.com/vfile/.github/blob/master/code-of-conduct.md
[coc]: https://github.com/vfile/.github/blob/HEAD/code-of-conduct.md

@@ -115,6 +114,6 @@ [license]: license

[to-offset]: #locationtooffsetposition
[to-offset]: #locationtooffsetpoint
[to-position]: #locationtopositionoffset
[to-point]: #locationtopointoffset
[position]: https://github.com/syntax-tree/unist#position
[point]: https://github.com/syntax-tree/unist#point

@@ -7,5 +7,7 @@ // TypeScript Version: 3.0

declare namespace vfileLocation {
type Position = Pick<Point, 'line' | 'column'>
type PositionWithOffset = Required<Point>
type PositionalPoint = Pick<Point, 'line' | 'column'>
type FullPoint = Required<Point>
type Offset = NonNullable<Point['offset']>
/** @deprecated */
type Position = PositionalPoint

@@ -17,8 +19,10 @@ interface Location {

*/
toOffset: (position: Position) => Offset
toOffset: (point: PositionalPoint) => Offset
/**
* Get the line and column-based position for offset in the bound file.
* Get the line and column-based point for offset in the bound file.
*/
toPosition: (offset: Offset) => PositionWithOffset
toPoint: (offset: Offset) => FullPoint
/** @deprecated */
toPosition: (offset: Offset) => FullPoint
}

@@ -25,0 +29,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc