Socket
Socket
Sign inDemoInstall

unist-util-stringify-position

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.1.2

38

index.js

@@ -1,6 +0,6 @@

'use strict';
'use strict'
var own = {}.hasOwnProperty;
var own = {}.hasOwnProperty
module.exports = stringify;
module.exports = stringify

@@ -10,3 +10,3 @@ function stringify(value) {

if (!value || typeof value !== 'object') {
return null;
return null
}

@@ -16,37 +16,37 @@

if (own.call(value, 'position') || own.call(value, 'type')) {
return location(value.position);
return position(value.position)
}
/* Location. */
/* Position. */
if (own.call(value, 'start') || own.call(value, 'end')) {
return location(value);
return position(value)
}
/* Position. */
/* Point. */
if (own.call(value, 'line') || own.call(value, 'column')) {
return position(value);
return point(value)
}
/* ? */
return null;
return null
}
function position(pos) {
if (!pos || typeof pos !== 'object') {
pos = {};
function point(point) {
if (!point || typeof point !== 'object') {
point = {}
}
return index(pos.line) + ':' + index(pos.column);
return index(point.line) + ':' + index(point.column)
}
function location(loc) {
if (!loc || typeof loc !== 'object') {
loc = {};
function position(pos) {
if (!pos || typeof pos !== 'object') {
pos = {}
}
return position(loc.start) + '-' + position(loc.end);
return point(pos.start) + '-' + point(pos.end)
}
function index(value) {
return value && typeof value === 'number' ? value : 1;
return value && typeof value === 'number' ? value : 1
}
{
"name": "unist-util-stringify-position",
"version": "1.1.1",
"description": "Stringify a Unist node, location, or position",
"version": "1.1.2",
"description": "Stringify a Unist node, position, or point",
"license": "MIT",

@@ -10,2 +10,3 @@ "keywords": [

"location",
"point",
"node",

@@ -17,3 +18,3 @@ "stringify",

],
"repository": "https://github.com/syntax-tree/unist-util-stringify-position",
"repository": "syntax-tree/unist-util-stringify-position",
"bugs": "https://github.com/syntax-tree/unist-util-stringify-position/issues",

@@ -29,19 +30,19 @@ "author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",

"devDependencies": {
"browserify": "^14.1.0",
"browserify": "^16.0.0",
"esmangle": "^1.0.0",
"nyc": "^10.0.0",
"remark-cli": "^3.0.0",
"remark-preset-wooorm": "^3.0.0",
"nyc": "^11.0.0",
"prettier": "^1.12.1",
"remark-cli": "^5.0.0",
"remark-preset-wooorm": "^4.0.0",
"tape": "^4.5.1",
"xo": "^0.18.1"
"xo": "^0.20.0"
},
"scripts": {
"build-md": "remark . --quiet --frail --output",
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix",
"build-bundle": "browserify index.js --no-builtins -s unistUtilStringifyPosition > unist-util-stringify-position.js",
"build-mangle": "esmangle unist-util-stringify-position.js > unist-util-stringify-position.min.js",
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"lint": "xo",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run build && npm run lint && npm run test-coverage"
"test": "npm run format && npm run build && npm run test-coverage"
},

@@ -54,5 +55,18 @@ "nyc": {

},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"space": true,
"prettier": true,
"esnext": false,
"rules": {
"guard-for-in": "off",
"no-var": "off",
"prefer-arrow-callback": "off"
},
"ignores": [

@@ -59,0 +73,0 @@ "unist-util-stringify-position.js"

# unist-util-stringify-position [![Build Status][build-badge]][build-page] [![Coverage Status][coverage-badge]][coverage-page]
Stringify a [**Unist**][unist] [position][] or [location][].
Stringify a [**Unist**][unist] [`Position`][position] or [`Point`][point].

@@ -16,11 +16,14 @@ ## Installation

```javascript
var stringify = require('unist-util-stringify-position');
var stringify = require('unist-util-stringify-position')
stringify({line: 2, column: 3 }); //=> '2:3'
// Point
stringify({line: 2, column: 3}) // => '2:3'
// Position
stringify({
start: {line: 2},
end: {line: 3}
}); //=> '2:1-3:1'
}) // => '2:1-3:1'
// Node
stringify({

@@ -33,3 +36,3 @@ type: 'text',

}
}); //=> '5:11-5:12'
}) // => '5:11-5:12'
```

@@ -39,6 +42,6 @@

### `stringifyPosition(node|location|position)`
### `stringifyPosition(node|position|point)`
Stringify one position, a location (start and end positions), or
a node’s location.
Stringify one point, a position (start and end points), or
a node’s position.

@@ -49,6 +52,6 @@ ###### Parameters

— Node whose `'position'` property to stringify
* `location` ([`Location`][location])
— Location whose `'start'` and `'end'` positions to stringify
* `position` ([`Position`][position])
— Location whose `'line'` and `'column'` to stringify
— Position whose `'start'` and `'end'` points to stringify
* `point` ([`Point`][point])
— Point whose `'line'` and `'column'` to stringify

@@ -58,7 +61,15 @@ ###### Returns

`string?` — A range `ls:cs-le:ce` (when given `node` or
`location`) or a point `l:c` (when given `position`), where `l` stands
`position`) or a point `l:c` (when given `point`), where `l` stands
for line, `c` for column, `s` for `start`, and `e` for
end. `null` is returned if the given value is neither `node`,
`location`, nor `position`.
`position`, nor `point`.
## Contribute
See [`contributing.md` in `syntax-tree/unist`][contributing] for ways to get
started.
This organisation has a [Code of Conduct][coc]. By interacting with this
repository, organisation, or community you agree to abide by its terms.
## License

@@ -88,4 +99,8 @@

[location]: https://github.com/syntax-tree/unist#location
[position]: https://github.com/syntax-tree/unist#position
[position]: https://github.com/syntax-tree/unist#position
[point]: https://github.com/syntax-tree/unist#point
[contributing]: https://github.com/syntax-tree/unist/blob/master/contributing.md
[coc]: https://github.com/syntax-tree/unist/blob/master/code-of-conduct.md
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