open-editor
Advanced tools
+58
-55
| import {PathLike} from 'line-column-path'; | ||
| declare namespace openEditor { | ||
| interface Options { | ||
| /** | ||
| Name, command, or binary path of the editor. | ||
| export interface Options { | ||
| /** | ||
| The name, command, or binary path of the editor. | ||
| Default: [Auto-detected](https://github.com/sindresorhus/env-editor). | ||
| Default: [Auto-detected](https://github.com/sindresorhus/env-editor). | ||
| __Only use this option if you really have to.__ Can be useful if you want to force a specific editor or implement your own auto-detection. | ||
| */ | ||
| readonly editor?: string; | ||
| } | ||
| __Only use this option if you really have to.__ Can be useful if you want to force a specific editor or implement your own auto-detection. | ||
| */ | ||
| readonly editor?: string; | ||
| } | ||
| interface EditorRunConfig { | ||
| /** | ||
| Editor binary name. | ||
| */ | ||
| binary: string; | ||
| export interface EditorInfo { | ||
| /** | ||
| THe editor binary name. | ||
| */ | ||
| readonly binary: string; | ||
| /** | ||
| Arguments provided to the editor binary. | ||
| */ | ||
| arguments: string[]; | ||
| /** | ||
| The arguments provided to the editor binary. | ||
| */ | ||
| readonly arguments: string[]; | ||
| /** | ||
| A flag indicating whether the editor runs in the terminal. | ||
| */ | ||
| isTerminalEditor: boolean; | ||
| } | ||
| /** | ||
| A flag indicating whether the editor runs in the terminal. | ||
| */ | ||
| readonly isTerminalEditor: boolean; | ||
| } | ||
| declare const openEditor: { | ||
| /** | ||
| Open the given files in the user's editor at specific line and column if supported by the editor. It does not wait for the editor to start or quit. | ||
| /** | ||
| Open the given files in the user's editor at specific line and column if supported by the editor. It does not wait for the editor to start or quit. | ||
| @param files - Items should be in the format `foo.js:1:5` or `{file: 'foo.js', line: 1: column: 5}`. | ||
| @param files - Items should be in the format `foo.js:1:5` or `{file: 'foo.js', line: 1: column: 5}`. | ||
| @example | ||
| ``` | ||
| import openEditor = require('open-editor'); | ||
| @example | ||
| ``` | ||
| import openEditor from 'open-editor'; | ||
| openEditor([ | ||
| 'unicorn.js:5:3', | ||
| { | ||
| file: 'readme.md', | ||
| line: 10, | ||
| column: 2 | ||
| } | ||
| ]); | ||
| ``` | ||
| */ | ||
| (files: readonly PathLike[], options?: openEditor.Options): void; | ||
| openEditor([ | ||
| { | ||
| file: 'readme.md', | ||
| line: 10, | ||
| column: 2, | ||
| } | ||
| ]); | ||
| /** | ||
| Same as `openEditor()`, but returns an object with the binary name, arguments, and a flag indicating whether the editor runs in the terminal. | ||
| openEditor([ | ||
| 'unicorn.js:5:3', | ||
| ]); | ||
| ``` | ||
| */ | ||
| export default function openEditor(files: readonly PathLike[], options?: Options): void; | ||
| Can be useful if you want to handle opening the files yourself. | ||
| /** | ||
| Same as `openEditor()`, but returns an object with the binary name, arguments, and a flag indicating whether the editor runs in the terminal. | ||
| @example | ||
| ``` | ||
| {binary: 'subl', arguments: ['foo.js:1:5'], isTerminalEditor: false} | ||
| ``` | ||
| */ | ||
| make( | ||
| files: readonly PathLike[], | ||
| options?: openEditor.Options | ||
| ): openEditor.EditorRunConfig; | ||
| }; | ||
| Can be useful if you want to handle opening the files yourself. | ||
| export = openEditor; | ||
| @example | ||
| ``` | ||
| import {getEditorInfo} from 'open-editor'; | ||
| getEditorInfo([ | ||
| { | ||
| file: 'foo.js', | ||
| line: 1, | ||
| column: 5, | ||
| } | ||
| ]); | ||
| //=> {binary: 'subl', arguments: ['foo.js:1:5'], isTerminalEditor: false} | ||
| ``` | ||
| */ | ||
| export function getEditorInfo(files: readonly PathLike[], options?: Options): EditorInfo; |
+20
-22
@@ -1,8 +0,8 @@ | ||
| 'use strict'; | ||
| const execa = require('execa'); | ||
| const envEditor = require('env-editor'); | ||
| const lineColumnPath = require('line-column-path'); | ||
| const open = require('open'); | ||
| import process from 'node:process'; | ||
| import execa from 'execa'; | ||
| import {getEditor, defaultEditor} from 'env-editor'; | ||
| import {parseLineColumnPath, stringifyLineColumnPath} from 'line-column-path'; | ||
| import open from 'open'; | ||
| const make = (files, options = {}) => { | ||
| export function getEditorInfo(files, options = {}) { | ||
| if (!Array.isArray(files)) { | ||
@@ -12,3 +12,3 @@ throw new TypeError(`Expected an \`Array\`, got ${typeof files}`); | ||
| const editor = options.editor ? envEditor.getEditor(options.editor) : envEditor.defaultEditor(); | ||
| const editor = options.editor ? getEditor(options.editor) : defaultEditor(); | ||
| const editorArguments = []; | ||
@@ -21,6 +21,6 @@ | ||
| for (const file of files) { | ||
| const parsed = lineColumnPath.parse(file); | ||
| const parsed = parseLineColumnPath(file); | ||
| if (['sublime', 'atom', 'vscode'].includes(editor.id)) { | ||
| editorArguments.push(lineColumnPath.stringify(parsed)); | ||
| editorArguments.push(stringifyLineColumnPath(parsed)); | ||
| continue; | ||
@@ -30,3 +30,3 @@ } | ||
| if (['webstorm', 'intellij'].includes(editor.id)) { | ||
| editorArguments.push(lineColumnPath.stringify(parsed, {column: false})); | ||
| editorArguments.push(stringifyLineColumnPath(parsed, {column: false})); | ||
| continue; | ||
@@ -36,4 +36,4 @@ } | ||
| if (editor.id === 'textmate') { | ||
| editorArguments.push('--line', lineColumnPath.stringify(parsed, { | ||
| file: false | ||
| editorArguments.push('--line', stringifyLineColumnPath(parsed, { | ||
| file: false, | ||
| }), parsed.file); | ||
@@ -54,8 +54,8 @@ continue; | ||
| arguments: editorArguments, | ||
| isTerminalEditor: editor.isTerminalEditor | ||
| isTerminalEditor: editor.isTerminalEditor, | ||
| }; | ||
| }; | ||
| } | ||
| module.exports = (files, options) => { | ||
| const result = make(files, options); | ||
| export default function openEditor(files, options) { | ||
| const result = getEditorInfo(files, options); | ||
| const stdio = result.isTerminalEditor ? 'inherit' : 'ignore'; | ||
@@ -65,3 +65,3 @@ | ||
| detached: true, | ||
| stdio | ||
| stdio, | ||
| }); | ||
@@ -71,5 +71,5 @@ | ||
| subprocess.on('error', () => { | ||
| const result = make(files, { | ||
| const result = getEditorInfo(files, { | ||
| ...options, | ||
| editor: '' | ||
| editor: '', | ||
| }); | ||
@@ -87,4 +87,2 @@ | ||
| } | ||
| }; | ||
| module.exports.make = make; | ||
| } |
+11
-9
| { | ||
| "name": "open-editor", | ||
| "version": "3.0.0", | ||
| "version": "4.0.0", | ||
| "description": "Open files in your editor at a specific line and column", | ||
@@ -13,4 +13,6 @@ "license": "MIT", | ||
| }, | ||
| "type": "module", | ||
| "exports": "./index.js", | ||
| "engines": { | ||
| "node": ">=10" | ||
| "node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
| }, | ||
@@ -50,12 +52,12 @@ "scripts": { | ||
| "dependencies": { | ||
| "env-editor": "^0.4.1", | ||
| "execa": "^5.0.0", | ||
| "line-column-path": "^2.0.0", | ||
| "open": "^7.3.0" | ||
| "env-editor": "^1.0.0", | ||
| "execa": "^5.1.1", | ||
| "line-column-path": "^3.0.0", | ||
| "open": "^8.4.0" | ||
| }, | ||
| "devDependencies": { | ||
| "ava": "^2.4.0", | ||
| "tsd": "^0.14.0", | ||
| "xo": "^0.36.1" | ||
| "ava": "^3.15.0", | ||
| "tsd": "^0.18.0", | ||
| "xo": "^0.45.0" | ||
| } | ||
| } |
+23
-7
@@ -20,5 +20,5 @@ # open-editor | ||
| ```sh | ||
| npm install open-editor | ||
| ``` | ||
| $ npm install open-editor | ||
| ``` | ||
@@ -28,12 +28,15 @@ ## Usage | ||
| ```js | ||
| const openEditor = require('open-editor'); | ||
| import openEditor from 'open-editor'; | ||
| openEditor([ | ||
| 'unicorn.js:5:3', | ||
| { | ||
| file: 'readme.md', | ||
| line: 10, | ||
| column: 2 | ||
| column: 2, | ||
| } | ||
| ]); | ||
| openEditor([ | ||
| 'unicorn.js:5:3', | ||
| ]); | ||
| ``` | ||
@@ -62,7 +65,7 @@ | ||
| Name, command, or binary path of the editor. | ||
| The name, command, or binary path of the editor. | ||
| **Only use this option if you really have to.** Can be useful if you want to force a specific editor or implement your own auto-detection. | ||
| ### openEditor.make(files, options?) | ||
| ### getEditorRunConfig(files, options?) | ||
@@ -75,2 +78,15 @@ Same as `openEditor()`, but returns an object with the binary name, arguments, and a flag indicating whether the editor runs in the terminal. | ||
| ```js | ||
| import {getEditorInfo} from 'open-editor'; | ||
| getEditorInfo([ | ||
| { | ||
| file: 'foo.js', | ||
| line: 1, | ||
| column: 5, | ||
| } | ||
| ]); | ||
| //=> {binary: 'subl', arguments: ['foo.js:1:5'], isTerminalEditor: false} | ||
| ``` | ||
| ## Related | ||
@@ -77,0 +93,0 @@ |
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
7646
5.45%124
0.81%92
21.05%0
-100%Yes
NaN+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated