line-column-path
Advanced tools
Comparing version 1.0.0 to 2.0.0
47
index.js
'use strict'; | ||
exports.parse = input => { | ||
if (typeof input === 'object') { | ||
if (!input.file) { | ||
exports.parse = path => { | ||
if (typeof path === 'object') { | ||
if (!path.file) { | ||
throw new Error('Missing required `file` property'); | ||
@@ -10,13 +10,13 @@ } | ||
return { | ||
file: input.file, | ||
line: input.line || 1, | ||
column: input.column || 1 | ||
file: path.file, | ||
line: path.line || 1, | ||
column: path.column || 1 | ||
}; | ||
} | ||
const match = /^(.*?):(\d+)(?::(\d+))?$/.exec(input); | ||
const match = /^(.*?):(\d+)(?::(\d+))?$/.exec(path); | ||
if (!match) { | ||
return { | ||
file: input, | ||
file: path, | ||
line: 1, | ||
@@ -38,32 +38,33 @@ column: 1 | ||
exports.stringify = (obj, opts) => { | ||
opts = Object.assign({ | ||
exports.stringify = (path, options) => { | ||
options = { | ||
file: true, | ||
column: true | ||
}, opts); | ||
column: true, | ||
...options | ||
}; | ||
if (!obj.file) { | ||
if (!path.file) { | ||
throw new Error('Missing required `file` property'); | ||
} | ||
let ret = ''; | ||
let result = ''; | ||
if (opts.file) { | ||
ret += obj.file; | ||
if (options.file) { | ||
result += path.file; | ||
} | ||
if (obj.line) { | ||
ret += `:${obj.line}`; | ||
if (path.line) { | ||
result += `:${path.line}`; | ||
} | ||
if (obj.line && obj.column && opts.column) { | ||
ret += `:${obj.column}`; | ||
if (path.line && path.column && options.column) { | ||
result += `:${path.column}`; | ||
} | ||
if (!opts.file) { | ||
ret = ret.replace(/^:/, ''); | ||
if (!options.file) { | ||
result = result.replace(/^:/, ''); | ||
} | ||
return ret; | ||
return result; | ||
}; | ||
{ | ||
"name": "line-column-path", | ||
"version": "1.0.0", | ||
"description": "Parse and stringify file paths with line and column like `unicorn.js:8:14`", | ||
"license": "MIT", | ||
"repository": "sindresorhus/line-column-path", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"file", | ||
"filepath", | ||
"line", | ||
"column", | ||
"path", | ||
"editor", | ||
"position", | ||
"parse", | ||
"stringify", | ||
"parsing", | ||
"decode", | ||
"encode", | ||
"format" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
"name": "line-column-path", | ||
"version": "2.0.0", | ||
"description": "Parse and stringify file paths with line and column like `unicorn.js:8:14`", | ||
"license": "MIT", | ||
"repository": "sindresorhus/line-column-path", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"file", | ||
"filepath", | ||
"line", | ||
"column", | ||
"path", | ||
"editor", | ||
"position", | ||
"parse", | ||
"stringify", | ||
"parsing", | ||
"decode", | ||
"encode", | ||
"format" | ||
], | ||
"dependencies": { | ||
"type-fest": "^0.4.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -9,3 +9,3 @@ # line-column-path [![Build Status](https://travis-ci.org/sindresorhus/line-column-path.svg?branch=master)](https://travis-ci.org/sindresorhus/line-column-path) | ||
``` | ||
$ npm install --save line-column-path | ||
$ npm install line-column-path | ||
``` | ||
@@ -33,3 +33,3 @@ | ||
Type: `string` `Object` | ||
Type: `string | object` | ||
@@ -40,7 +40,7 @@ File path to parse. | ||
### .stringify(input, [options]) | ||
### .stringify(path, [options]) | ||
#### input | ||
#### path | ||
Type: `Object` | ||
Type: `object` | ||
@@ -51,3 +51,3 @@ Object with a `.file` property and optionally a `.line` and `.column` property. | ||
Type: `Object` | ||
Type: `object` | ||
@@ -54,0 +54,0 @@ ##### file |
Sorry, the diff of this file is not supported yet
5341
5
99
1
3
+ Addedtype-fest@^0.4.1
+ Addedtype-fest@0.4.1(transitive)