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 4.1.0 to 5.0.0

88

lib/index.d.ts
/**
* @typedef {import('vfile').VFile} VFile
* @typedef {import('vfile').Value} Value
*/
/**
* @typedef Point
* unist point, where `line` and `column` can be `undefined`.
* @property {number | undefined} line
* Line.
* @property {number | undefined} column
* Column.
* @property {number | undefined} [offset]
* Offset.
* Create an index of the given document to translate between line/column and
* offset based positional info.
*
* @typedef PointLike
* unist point, allowed as input.
* @property {number | null | undefined} [line]
* Line.
* @property {number | null | undefined} [column]
* Column.
* @property {number | null | undefined} [offset]
* Offset.
* Also implemented in Rust in [`wooorm/markdown-rs`][markdown-rs].
*
* @callback ToPoint
* Get a line/column-based `point` from `offset`.
* @param {number | null | undefined} [offset]
* Something that should be an `offset.
* @returns {Point}
* Point, line/column are undefined for invalid or out of bounds input.
* [markdown-rs]: https://github.com/wooorm/markdown-rs/blob/main/src/util/location.rs
*
* @callback ToOffset
* Get an offset from a line/column-based `point`.
* @param {Point | null | undefined} [point]
* Something that should be a `point.
* @returns {number}
* Offset or `-1` for invalid or out of bounds input.
*
* @typedef Location
* Accessors for index.
* @property {ToPoint} toPoint
* Get a line/column-based `point` from `offset`.
* @property {ToOffset} toOffset
* Get an offset from a line/column-based `point`.
*/
/**
* Index the given document so you can translate between line/column and offset
* based positional info.
*
* @param {VFile | Value} file

@@ -57,20 +17,4 @@ * File to index.

export type Value = import('vfile').Value
export type UnistPoint = import('unist').Point
/**
* unist point, where `line` and `column` can be `undefined`.
*/
export type Point = {
/**
* Line.
*/
line: number | undefined
/**
* Column.
*/
column: number | undefined
/**
* Offset.
*/
offset?: number | undefined
}
/**
* unist point, allowed as input.

@@ -93,9 +37,19 @@ */

/**
* Get a line/column-based `point` from `offset`.
* Get the line/column based `Point` for `offset` in the bound indices.
*
* Returns `undefined` when given out of bounds input.
*
* Also implemented in Rust in [`wooorm/markdown-rs`][markdown-rs].
*
* [markdown-rs]: https://github.com/wooorm/markdown-rs/blob/main/src/util/location.rs
*/
export type ToPoint = (offset?: number | null | undefined) => Point
export type ToPoint = (
offset?: number | null | undefined
) => UnistPoint | undefined
/**
* Get an offset from a line/column-based `point`.
* Get the `offset` from a line/column based `Point` in the bound indices.
*/
export type ToOffset = (point?: Point | null | undefined) => number
export type ToOffset = (
point?: PointLike | null | undefined
) => number | undefined
/**

@@ -106,9 +60,9 @@ * Accessors for index.

/**
* Get a line/column-based `point` from `offset`.
* Get the line/column based `Point` for `offset` in the bound indices.
*/
toPoint: ToPoint
/**
* Get an offset from a line/column-based `point`.
* Get the `offset` from a line/column based `Point` in the bound indices.
*/
toOffset: ToOffset
}
/**
* @typedef {import('vfile').VFile} VFile
* @typedef {import('vfile').Value} Value
* @typedef {import('unist').Point} UnistPoint
*/
/**
* @typedef Point
* unist point, where `line` and `column` can be `undefined`.
* @property {number | undefined} line
* Line.
* @property {number | undefined} column
* Column.
* @property {number | undefined} [offset]
* Offset.
*

@@ -26,14 +19,20 @@ * @typedef PointLike

* @callback ToPoint
* Get a line/column-based `point` from `offset`.
* Get the line/column based `Point` for `offset` in the bound indices.
*
* Returns `undefined` when given out of bounds input.
*
* Also implemented in Rust in [`wooorm/markdown-rs`][markdown-rs].
*
* [markdown-rs]: https://github.com/wooorm/markdown-rs/blob/main/src/util/location.rs
* @param {number | null | undefined} [offset]
* Something that should be an `offset.
* @returns {Point}
* Point, line/column are undefined for invalid or out of bounds input.
* @returns {UnistPoint | undefined}
* Point, if `offset` is valid and in-bounds input.
*
* @callback ToOffset
* Get an offset from a line/column-based `point`.
* @param {Point | null | undefined} [point]
* Get the `offset` from a line/column based `Point` in the bound indices.
* @param {PointLike | null | undefined} [point]
* Something that should be a `point.
* @returns {number}
* Offset or `-1` for invalid or out of bounds input.
* @returns {number | undefined}
* Offset (`number`) or `undefined` for invalid or out of bounds input.
*

@@ -43,11 +42,17 @@ * @typedef Location

* @property {ToPoint} toPoint
* Get a line/column-based `point` from `offset`.
* Get the line/column based `Point` for `offset` in the bound indices.
* @property {ToOffset} toOffset
* Get an offset from a line/column-based `point`.
* Get the `offset` from a line/column based `Point` in the bound indices.
*/
const search = /\r?\n|\r/g
/**
* Index the given document so you can translate between line/column and offset
* based positional info.
* Create an index of the given document to translate between line/column and
* offset based positional info.
*
* Also implemented in Rust in [`wooorm/markdown-rs`][markdown-rs].
*
* [markdown-rs]: https://github.com/wooorm/markdown-rs/blob/main/src/util/location.rs
*
* @param {VFile | Value} file

@@ -60,6 +65,12 @@ * File to index.

const value = String(file)
/** @type {Array<number>} */
/**
* List, where each index is a line number (0-based), and each value is the
* byte index *after* where the line ends.
*
* @type {Array<number>}
*/
const indices = []
const search = /\r?\n|\r/g
search.lastIndex = 0
while (search.test(value)) {

@@ -92,4 +103,2 @@ indices.push(search.lastIndex)

}
return {line: undefined, column: undefined, offset: undefined}
}

@@ -115,5 +124,3 @@

}
return -1
}
}
{
"name": "vfile-location",
"version": "4.1.0",
"version": "5.0.0",
"description": "vfile utility to convert between positional (line and column-based) and offset (range-based) locations",

@@ -31,4 +31,6 @@ "license": "MIT",

"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"files": [

@@ -44,3 +46,3 @@ "lib/",

"devDependencies": {
"@types/node": "^18.0.0",
"@types/node": "^20.0.0",
"c8": "^7.0.0",

@@ -51,4 +53,4 @@ "prettier": "^2.0.0",

"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.53.0"
"typescript": "^5.0.0",
"xo": "^0.54.0"
},

@@ -60,3 +62,3 @@ "scripts": {

"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"

@@ -72,5 +74,2 @@ },

},
"xo": {
"prettier": true
},
"remarkConfig": {

@@ -84,4 +83,8 @@ "plugins": [

"detail": true,
"strict": true
"strict": true,
"ignoreCatch": true
},
"xo": {
"prettier": true
}
}

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

This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
In Node.js (version 16+), install with [npm][]:

@@ -53,3 +53,3 @@ ```sh

```js
import {location} from 'https://esm.sh/vfile-location@4'
import {location} from 'https://esm.sh/vfile-location@5'
```

@@ -61,3 +61,3 @@

<script type="module">
import {location} from 'https://esm.sh/vfile-location@4?bundle'
import {location} from 'https://esm.sh/vfile-location@5?bundle'
</script>

@@ -85,8 +85,8 @@ ```

Index the given document so you can translate between line/column and offset
based positional info.
Create an index of the given document to translate between line/column and
offset based positional info.
###### Parameters
* `file` (`string`, `Buffer`, or [`VFile`][vfile])
* `file` ([`VFile`][vfile], `Buffer`, or `string`)
— file to index

@@ -104,6 +104,8 @@

* `toPoint` (`(offset?: number) => Point`)
— get a line/column-based [`Point`][point] from `offset`
* `toOffset` (`(point?: Point) => number`)
— get an offset from a line/column-based [`point`][point]
* `toPoint` (`(offset: number) => Point | undefined`)
— get the line/column based [`Point`][point] for `offset` in the bound
indices
* `toOffset` (`(point: Point) => number | undefined`)
— get the `offset` from a line/column based [`Point`][point] in the bound
indices

@@ -117,7 +119,10 @@ ## Types

Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
Projects maintained by the unified collective are compatible with maintained
versions of Node.js (as of June 2023, that is Node.js 16+).
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, `vfile-location@^5`,
compatible with Node.js 16.
## Contribute

@@ -151,5 +156,5 @@

[size-badge]: https://img.shields.io/bundlephobia/minzip/vfile-location.svg
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=vfile-location
[size]: https://bundlephobia.com/result?p=vfile-location
[size]: https://bundlejs.com/?q=vfile-location

@@ -156,0 +161,0 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

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