Socket
Socket
Sign inDemoInstall

unist-util-stringify-position

Package Overview
Dependencies
1
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.3 to 3.0.0

index.d.ts

44

index.js

@@ -1,8 +0,17 @@

'use strict'
var own = {}.hasOwnProperty
module.exports = stringify
/**
* @typedef {import('unist').Node} Node
* @typedef {import('unist').Position} Position
* @typedef {import('unist').Point} Point
*/
function stringify(value) {
/**
* Stringify one point, a position (start and end points), or a node’s
* positional information.
*
* @param {Node|Position|Point} [value]
* @returns {string}
*/
export function stringifyPosition(value) {
// Nothing.

@@ -15,2 +24,3 @@ if (!value || typeof value !== 'object') {

if (own.call(value, 'position') || own.call(value, 'type')) {
// @ts-ignore looks like a node.
return position(value.position)

@@ -21,2 +31,3 @@ }

if (own.call(value, 'start') || own.call(value, 'end')) {
// @ts-ignore looks like a position.
return position(value)

@@ -27,2 +38,3 @@ }

if (own.call(value, 'line') || own.call(value, 'column')) {
// @ts-ignore looks like a point.
return point(value)

@@ -35,20 +47,24 @@ }

/**
* @param {Point} point
* @returns {string}
*/
function point(point) {
if (!point || typeof point !== 'object') {
point = {}
}
return index(point.line) + ':' + index(point.column)
return index(point && point.line) + ':' + index(point && point.column)
}
/**
* @param {Position} pos
* @returns {string}
*/
function position(pos) {
if (!pos || typeof pos !== 'object') {
pos = {}
}
return point(pos.start) + '-' + point(pos.end)
return point(pos && pos.start) + '-' + point(pos && pos.end)
}
/**
* @param {number} value
* @returns {number}
*/
function index(value) {
return value && typeof value === 'number' ? value : 1
}
{
"name": "unist-util-stringify-position",
"version": "2.0.3",
"version": "3.0.0",
"description": "unist utility to serialize a node, position, or point as a human readable location",

@@ -28,38 +28,33 @@ "license": "MIT",

],
"types": "types/index.d.ts",
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"types/index.d.ts",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/unist": "^2.0.2"
"@types/unist": "^2.0.0"
},
"devDependencies": {
"browserify": "^16.0.0",
"dtslint": "^3.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",
"typescript": "^3.0.0",
"xo": "^0.27.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,ts}\" && xo --fix",
"build-bundle": "browserify . -s unistUtilStringifyPosition > unist-util-stringify-position.js",
"build-mangle": "browserify . -s unistUtilStringifyPosition -p tinyify > unist-util-stringify-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-types": "dtslint types",
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
"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": {

@@ -75,6 +70,6 @@ "tabWidth": 2,

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

@@ -85,3 +80,8 @@ "remarkConfig": {

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

@@ -15,2 +15,5 @@ # unist-util-stringify-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,12 +28,12 @@

```js
var stringify = require('unist-util-stringify-position')
import {stringifyPosition} from 'unist-util-stringify-position'
// Point
stringify({line: 2, column: 3}) // => '2:3'
stringifyPosition({line: 2, column: 3}) // => '2:3'
// Position
stringify({start: {line: 2}, end: {line: 3}}) // => '2:1-3:1'
stringifyPosition({start: {line: 2}, end: {line: 3}}) // => '2:1-3:1'
// Node
stringify({
stringifyPosition({
type: 'text',

@@ -47,2 +50,5 @@ value: '!',

This package exports the following identifiers: `stringifyPosition`.
There is no default export.
### `stringifyPosition(node|position|point)`

@@ -97,5 +103,5 @@

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

@@ -120,5 +126,5 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/unist-util-stringify-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

@@ -131,7 +137,7 @@ [npm]: https://docs.npmjs.com/cli/install

[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

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc