Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unist-util-position

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-position - npm Package Compare versions

Comparing version 3.1.0 to 4.0.0

index.d.ts

50

index.js

@@ -1,16 +0,34 @@

'use strict'
/**
* @typedef {import('unist').Position} Position
* @typedef {import('unist').Point} Point
*
* @typedef {Partial<Point>} PointLike
*
* @typedef {Object} PositionLike
* @property {PointLike} [start]
* @property {PointLike} [end]
*
* @typedef {Object} NodeLike
* @property {PositionLike} [position]
*/
var start = factory('start')
var end = factory('end')
export var pointStart = point('start')
export var pointEnd = point('end')
module.exports = position
position.start = start
position.end = end
function position(node) {
return {start: start(node), end: end(node)}
/**
* Get the positional info of `node`.
*
* @param {NodeLike} [node]
* @returns {Position}
*/
export function position(node) {
return {start: pointStart(node), end: pointEnd(node)}
}
function factory(type) {
/**
* Get the positional info of `node`.
*
* @param {'start'|'end'} type
*/
function point(type) {
point.displayName = type

@@ -20,3 +38,11 @@

/**
* Get the positional info of `node`.
*
* @param {NodeLike} [node]
* @returns {Point}
*/
function point(node) {
/** @type {Point} */
// @ts-ignore looks like a point
var point = (node && node.position && node.position[type]) || {}

@@ -27,5 +53,5 @@

column: point.column || null,
offset: isNaN(point.offset) ? null : point.offset
offset: point.offset > -1 ? point.offset : null
}
}
}
{
"name": "unist-util-position",
"version": "3.1.0",
"version": "4.0.0",
"description": "unist utility to get the position of a node",

@@ -25,31 +25,30 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {},
"devDependencies": {
"browserify": "^16.0.0",
"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",
"xo": "^0.26.0"
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.38.0"
},
"scripts": {
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
"build-bundle": "browserify . -s unistUtilPosition > unist-util-position.js",
"build-mangle": "browserify . -s unistUtilPosition -p tinyify > unist-util-position.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"
"prepack": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run build && npm run format && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {

@@ -65,6 +64,7 @@ "tabWidth": 2,

"prettier": true,
"esnext": false,
"ignores": [
"unist-util-position.js"
]
"rules": {
"import/no-mutable-exports": "off",
"no-var": "off",
"prefer-arrow-callback": "off"
}
},

@@ -75,3 +75,8 @@ "remarkConfig": {

]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}

@@ -15,2 +15,5 @@ # unist-util-position

This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
[npm][]:

@@ -25,4 +28,4 @@

```js
var remark = require('remark')
var position = require('unist-util-position')
import remark from 'remark'
import {position, pointStart, pointEnd} from 'unist-util-position'

@@ -32,8 +35,8 @@ var tree = remark().parse('# foo\n\n* bar\n')

console.log(position(tree))
console.log(position.start(tree))
console.log(position.end(tree))
console.log(pointStart(tree))
console.log(pointEnd(tree))
console.log(position())
console.log(position.start())
console.log(position.end())
console.log(pointStart())
console.log(pointEnd())
```

@@ -54,2 +57,6 @@

This package exports the following identifiers: `position`, `pointStart`, and
`pointEnd`.
There is no default export.
### `position(node?)`

@@ -60,5 +67,5 @@

### `position.start(node?)`
### `pointStart(node?)`
### `position.end(node?)`
### `pointEnd(node?)`

@@ -84,5 +91,5 @@ Get the start or end points in the positional info of `node` ([`Node?`][node]).

[build-badge]: https://img.shields.io/travis/syntax-tree/unist-util-position.svg
[build-badge]: https://github.com/syntax-tree/unist-util-position/workflows/main/badge.svg
[build]: https://travis-ci.org/syntax-tree/unist-util-position
[build]: https://github.com/syntax-tree/unist-util-position/actions

@@ -107,5 +114,5 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-position.svg

[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/syntax-tree
[chat]: https://github.com/syntax-tree/unist/discussions

@@ -118,7 +125,7 @@ [license]: license

[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
[support]: https://github.com/syntax-tree/.github/blob/master/support.md
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md

@@ -125,0 +132,0 @@ [unist]: https://github.com/syntax-tree/unist

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