vfile-location
Advanced tools
Comparing version 2.0.2 to 2.0.3
44
index.js
@@ -1,9 +0,9 @@ | ||
'use strict'; | ||
'use strict' | ||
/* Expose. */ | ||
module.exports = factory; | ||
module.exports = factory | ||
/* Factory. */ | ||
function factory(file) { | ||
var contents = indices(String(file)); | ||
var contents = indices(String(file)) | ||
@@ -13,3 +13,3 @@ return { | ||
toOffset: positionToOffsetFactory(contents) | ||
}; | ||
} | ||
} | ||
@@ -20,3 +20,3 @@ | ||
function offsetToPositionFactory(indices) { | ||
return offsetToPosition; | ||
return offsetToPosition | ||
@@ -26,7 +26,7 @@ /* Get the line and column-based `position` for | ||
function offsetToPosition(offset) { | ||
var index = -1; | ||
var length = indices.length; | ||
var index = -1 | ||
var length = indices.length | ||
if (offset < 0) { | ||
return {}; | ||
return {} | ||
} | ||
@@ -38,9 +38,9 @@ | ||
line: index + 1, | ||
column: (offset - (indices[index - 1] || 0)) + 1, | ||
column: offset - (indices[index - 1] || 0) + 1, | ||
offset: offset | ||
}; | ||
} | ||
} | ||
} | ||
return {}; | ||
return {} | ||
} | ||
@@ -52,3 +52,3 @@ } | ||
function positionToOffsetFactory(indices) { | ||
return positionToOffset; | ||
return positionToOffset | ||
@@ -58,10 +58,10 @@ /* Get the `offset` for a line and column-based | ||
function positionToOffset(position) { | ||
var line = position && position.line; | ||
var column = position && position.column; | ||
var line = position && position.line | ||
var column = position && position.column | ||
if (!isNaN(line) && !isNaN(column) && line - 1 in indices) { | ||
return ((indices[line - 2] || 0) + column - 1) || 0; | ||
return (indices[line - 2] || 0) + column - 1 || 0 | ||
} | ||
return -1; | ||
return -1 | ||
} | ||
@@ -72,13 +72,13 @@ } | ||
function indices(value) { | ||
var result = []; | ||
var index = value.indexOf('\n'); | ||
var result = [] | ||
var index = value.indexOf('\n') | ||
while (index !== -1) { | ||
result.push(index + 1); | ||
index = value.indexOf('\n', index + 1); | ||
result.push(index + 1) | ||
index = value.indexOf('\n', index + 1) | ||
} | ||
result.push(value.length + 1); | ||
result.push(value.length + 1) | ||
return result; | ||
return result | ||
} |
{ | ||
"name": "vfile-location", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Convert between positions (line and column-based) and offsets (range-based) locations in a virtual file", | ||
@@ -13,3 +13,3 @@ "license": "MIT", | ||
], | ||
"repository": "https://github.com/vfile/vfile-location", | ||
"repository": "vfile/vfile-location", | ||
"bugs": "https://github.com/vfile/vfile-location/issues", | ||
@@ -25,20 +25,20 @@ "author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
"devDependencies": { | ||
"browserify": "^14.0.0", | ||
"browserify": "^16.0.0", | ||
"esmangle": "^1.0.1", | ||
"nyc": "^11.0.0", | ||
"remark-cli": "^3.0.0", | ||
"remark-preset-wooorm": "^3.0.0", | ||
"prettier": "^1.12.1", | ||
"remark-cli": "^5.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"tape": "^4.0.0", | ||
"vfile": "^2.0.0", | ||
"xo": "^0.18.0" | ||
"xo": "^0.20.0" | ||
}, | ||
"scripts": { | ||
"build-md": "remark . -qfo", | ||
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", | ||
"build-bundle": "browserify index.js --bare -s vfileLocation > vfile-location.js", | ||
"build-mangle": "esmangle vfile-location.js > vfile-location.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" | ||
}, | ||
@@ -51,5 +51,18 @@ "nyc": { | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"prettier": true, | ||
"esnext": false, | ||
"rules": { | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off", | ||
"object-shorthand": "off" | ||
}, | ||
"ignores": [ | ||
@@ -56,0 +69,0 @@ "vfile-location.js" |
@@ -17,8 +17,9 @@ # vfile-location [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
```js | ||
var vfile = require('vfile'); | ||
var vfileLocation = require('vfile-location'); | ||
var location = vfileLocation(vfile('foo\nbar\nbaz')); | ||
var vfile = require('vfile') | ||
var vfileLocation = require('vfile-location') | ||
location.toOffset({line: 3, column: 3}); //=> 10 | ||
location.toPosition(offset); //=> {line: 3, column: 3, offset: 10} | ||
var location = vfileLocation(vfile('foo\nbar\nbaz')) | ||
var offset = location.toOffset({line: 3, column: 3}) // => 10 | ||
location.toPosition(offset) // => {line: 3, column: 3, offset: 10} | ||
``` | ||
@@ -47,2 +48,9 @@ | ||
## Contribute | ||
See [`contributing.md` in `vfile/vfile`][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 | ||
@@ -75,1 +83,5 @@ | ||
[position]: https://github.com/syntax-tree/unist#position | ||
[contributing]: https://github.com/vfile/vfile/blob/master/contributing.md | ||
[coc]: https://github.com/vfile/vfile/blob/master/code-of-conduct.md |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
6777
85
9