Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

external-editor

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

external-editor - npm Package Compare versions

Comparing version 3.0.3 to 3.1.0

2

main/errors/CreateFileError.js

@@ -14,3 +14,3 @@ "use strict";

return extendStatics(d, b);
}
};
return function (d, b) {

@@ -17,0 +17,0 @@ extendStatics(d, b);

@@ -14,3 +14,3 @@ "use strict";

return extendStatics(d, b);
}
};
return function (d, b) {

@@ -17,0 +17,0 @@ extendStatics(d, b);

@@ -14,3 +14,3 @@ "use strict";

return extendStatics(d, b);
}
};
return function (d, b) {

@@ -17,0 +17,0 @@ extendStatics(d, b);

@@ -14,3 +14,3 @@ "use strict";

return extendStatics(d, b);
}
};
return function (d, b) {

@@ -17,0 +17,0 @@ extendStatics(d, b);

@@ -5,3 +5,3 @@ /***

* Kevin Gravier <kevin@mrkmg.com>
* MIT 2018
* MIT 2019
*/

@@ -16,7 +16,14 @@ import { CreateFileError } from "./errors/CreateFileError";

}
export interface IFileOptions {
prefix?: string;
postfix?: string;
mode?: number;
template?: string;
dir?: string;
}
export declare type StringCallback = (err: Error, result: string) => void;
export declare type VoidCallback = () => void;
export { CreateFileError, LaunchEditorError, ReadFileError, RemoveFileError };
export declare function edit(text?: string): string;
export declare function editAsync(text: string, callback: StringCallback): void;
export declare function edit(text?: string, fileOptions?: IFileOptions): string;
export declare function editAsync(text: string, callback: StringCallback, fileOptions?: IFileOptions): void;
export declare class ExternalEditor {

@@ -28,5 +35,6 @@ private static splitStringBySpace;

lastExitStatus: number;
private fileOptions;
readonly temp_file: string;
readonly last_exit_status: number;
constructor(text?: string);
constructor(text?: string, fileOptions?: IFileOptions);
run(): string;

@@ -33,0 +41,0 @@ runAsync(callback: StringCallback): void;

@@ -6,3 +6,3 @@ "use strict";

* Kevin Gravier <kevin@mrkmg.com>
* MIT 2018
* MIT 2019
*/

@@ -23,5 +23,5 @@ Object.defineProperty(exports, "__esModule", { value: true });

exports.RemoveFileError = RemoveFileError_1.RemoveFileError;
function edit(text) {
function edit(text, fileOptions) {
if (text === void 0) { text = ""; }
var editor = new ExternalEditor(text);
var editor = new ExternalEditor(text, fileOptions);
editor.run();

@@ -32,5 +32,5 @@ editor.cleanup();

exports.edit = edit;
function editAsync(text, callback) {
function editAsync(text, callback, fileOptions) {
if (text === void 0) { text = ""; }
var editor = new ExternalEditor(text);
var editor = new ExternalEditor(text, fileOptions);
editor.runAsync(function (err, result) {

@@ -53,6 +53,10 @@ if (err) {

var ExternalEditor = /** @class */ (function () {
function ExternalEditor(text) {
function ExternalEditor(text, fileOptions) {
if (text === void 0) { text = ""; }
this.text = "";
this.fileOptions = {};
this.text = text;
if (fileOptions) {
this.fileOptions = fileOptions;
}
this.determineEditor();

@@ -131,4 +135,8 @@ this.createTemporaryFile();

try {
this.tempFile = tmp_1.tmpNameSync({});
fs_1.writeFileSync(this.tempFile, this.text, { encoding: "utf8" });
this.tempFile = tmp_1.tmpNameSync(this.fileOptions);
var opt = { encoding: "utf8" };
if (this.fileOptions.hasOwnProperty("mode")) {
opt.mode = this.fileOptions.mode;
}
fs_1.writeFileSync(this.tempFile, this.text, opt);
}

@@ -135,0 +143,0 @@ catch (createFileError) {

{
"name": "external-editor",
"version": "3.0.3",
"version": "3.1.0",
"description": "Edit a string with the users preferred text editor using $VISUAL or $ENVIRONMENT",

@@ -8,4 +8,3 @@ "main": "main/index.js",

"scripts": {
"test": "npm run lint && npm run unit",
"unit": "mocha --recursive --require ts-node/register --timeout 10000 ./test/spec 'test/spec/**/*.ts'",
"test": "mocha --recursive --require ts-node/register --timeout 10000 ./test/spec 'test/spec/**/*.ts'",
"compile": "tsc -p tsconfig.json",

@@ -42,3 +41,3 @@ "lint": "tslint './src/**/*.ts' './test/**/*.ts'"

"@types/mocha": "^5.2.5",
"@types/node": "^10.9.4",
"@types/node": "^10.14.12",
"@types/tmp": "0.0.33",

@@ -49,4 +48,4 @@ "chai": "^4.0.0",

"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"typescript": "^3.0.3"
"tslint": "^5.18.0",
"typescript": "^3.5.2"
},

@@ -53,0 +52,0 @@ "files": [

@@ -10,3 +10,3 @@ # External Editor

Version: 3.0.3
Version: 3.1.0

@@ -67,11 +67,13 @@ As of version 3.0.0, the minimum version of node supported is 4.

- `edit(text)`
- `edit(text, config)`
- `text` (string) *Optional* Defaults to empty string
- `config` (Config) *Optional* Options for temporary file creation
- **Returns** (string) The contents of the file
- Could throw `CreateFileError`, `ReadFileError`, or `LaunchEditorError`, or `RemoveFileError`
- `editAsync(text, callback)`
- `editAsync(text, callback, config)`
- `text` (string) *Optional* Defaults to empty string
- `callback` (function (error, text))
- `error` could be of type `CreateFileError`, `ReadFileError`, or `LaunchEditorError`, or `RemoveFileError`
- `text`(string) The contents of the file
- `text`(string) The contents of the file
- `config` (Config) *Optional* Options for temporary file creation

@@ -88,4 +90,5 @@

- `new ExternalEditor(text)`
- `new ExternalEditor(text, config)`
- `text` (string) *Optional* Defaults to empty string
- `config` (Config) *Optional* Options for temporary file creation
- Could throw `CreateFileError`

@@ -111,2 +114,10 @@ - `run()` Launches the editor.

**Config Options**
- `prefix` (string) *Optional* A prefix for the file name.
- `postfix` (string; *Optional* A postfix for the file name. Useful if you want to provide an extension.
- `mode` (number) *Optional* Which mode to create the file with. e.g. 644
- `template` (string) *Optional* A template for the filename. See [tmp](https://www.npmjs.com/package/tmp).
- `dir` (string) *Optional* Which path to store the file.
## Errors

@@ -113,0 +124,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc