Skip to content

Commit 1c365f7

Browse files
committed
Fix errors in index.d.ts
1 parent 4aa3605 commit 1c365f7

File tree

2 files changed

+56
-32
lines changed

2 files changed

+56
-32
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ trim_trailing_whitespace = true
1010

1111
[/lib/events.js]
1212
indent_size = 2
13+
14+
[*.ts]
15+
charset = utf-8
16+
indent_style = space
17+
indent_size = 2
18+
end_of_line = lf
19+
insert_final_newline = true
20+
trim_trailing_whitespace = true

index.d.ts

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {EventEmitter} from 'events';
1+
import { EventEmitter } from 'events';
22
import fs from 'fs';
33
import pa from 'path';
44

@@ -7,9 +7,9 @@ import pa from 'path';
77
*/
88
export interface VMFS {
99
/** Implements fs.statSync */
10-
statSync: typeof fs.statSync;
10+
statSync: typeof fs.statSync;
1111
/** Implements fs.readFileSync */
12-
readFileSync: typeof fs.readFileSync;
12+
readFileSync: typeof fs.readFileSync;
1313
}
1414

1515
/**
@@ -19,40 +19,54 @@ export interface VMPath {
1919
/** Implements path.resolve */
2020
resolve: typeof pa.resolve;
2121
/** Implements path.isAbsolute */
22-
isAbsolute: typeof pa.isAbsolute;
22+
isAbsolute: typeof pa.isAbsolute;
2323
/** Implements path.join */
24-
join: typeof pa.join;
24+
join: typeof pa.join;
2525
/** Implements path.basename */
26-
basename: typeof pa.basename;
26+
basename: typeof pa.basename;
2727
/** Implements path.dirname */
28-
dirname: typeof pa.dirname;
29-
/** Implements fs.statSync */
30-
statSync: typeof fs.statSync;
31-
/** Implements fs.readFileSync */
32-
readFileSync: typeof fs.readFileSync;
28+
dirname: typeof pa.dirname;
3329
}
3430

3531
/**
3632
* Custom file system which abstracts functions from node's fs and path modules.
3733
*/
38-
export interface VMFileSystemInterface implements VMFS, VMPath {
34+
export interface VMFileSystemInterface extends VMFS, VMPath {
3935
/** Implements (sep) => sep === path.sep */
40-
isSeparator(char: string): boolean;
36+
isSeparator(char: string): boolean;
4137
}
4238

4339
/**
4440
* Implementation of a default file system.
4541
*/
4642
export class VMFileSystem implements VMFileSystemInterface {
47-
constructor(options?: {fs?: VMFS, path?: VMPath});
43+
constructor(options?: { fs?: VMFS, path?: VMPath });
44+
/** Implements fs.statSync */
45+
statSync: typeof fs.statSync;
46+
/** Implements fs.readFileSync */
47+
readFileSync: typeof fs.readFileSync;
48+
/** Implements path.resolve */
49+
resolve: typeof pa.resolve;
50+
/** Implements path.isAbsolute */
51+
isAbsolute: typeof pa.isAbsolute;
52+
/** Implements path.join */
53+
join: typeof pa.join;
54+
/** Implements path.basename */
55+
basename: typeof pa.basename;
56+
/** Implements path.dirname */
57+
dirname: typeof pa.dirname;
58+
/** Implements (sep) => sep === path.sep */
59+
isSeparator(char: string): boolean;
4860
}
4961

5062
/**
5163
* Require options for a VM
5264
*/
5365
export interface VMRequire {
54-
/** Array of allowed built-in modules, accepts ["*"] for all. Using "*" increases the attack surface and potential
55-
* new modules allow to escape the sandbox. (default: none) */
66+
/**
67+
* Array of allowed built-in modules, accepts ["*"] for all. Using "*" increases the attack surface and potential
68+
* new modules allow to escape the sandbox. (default: none)
69+
*/
5670
builtin?: string[];
5771
/*
5872
* `host` (default) to require modules in host and proxy them to sandbox. `sandbox` to load, compile and
@@ -81,7 +95,7 @@ export interface VMRequire {
8195
* A custom compiler function for all of the JS that comes
8296
* into the VM
8397
*/
84-
type CompilerFunction = (code: string, filename: string) => string;
98+
export type CompilerFunction = (code: string, filename: string) => string;
8599

86100
/**
87101
* Options for creating a VM
@@ -128,21 +142,23 @@ export interface NodeVMOptions extends VMOptions {
128142
console?: "inherit" | "redirect" | "off";
129143
/** `true` or an object to enable `require` options (default: `false`). */
130144
require?: boolean | VMRequire;
131-
/** **WARNING**: This should be disabled. It allows to create a NodeVM form within the sandbox which could return any host module.
132-
* `true` to enable VMs nesting (default: `false`). */
145+
/**
146+
* **WARNING**: This should be disabled. It allows to create a NodeVM form within the sandbox which could return any host module.
147+
* `true` to enable VMs nesting (default: `false`).
148+
*/
133149
nesting?: boolean;
134150
/** `commonjs` (default) to wrap script into CommonJS wrapper, `none` to retrieve value returned by the script. */
135151
wrapper?: "commonjs" | "none";
136152
/** File extensions that the internal module resolver should accept. */
137153
sourceExtensions?: string[];
138-
/**
139-
* Array of arguments passed to `process.argv`.
140-
* This object will not be copied and the script can change this object.
154+
/**
155+
* Array of arguments passed to `process.argv`.
156+
* This object will not be copied and the script can change this object.
141157
*/
142158
argv?: string[];
143-
/**
144-
* Environment map passed to `process.env`.
145-
* This object will not be copied and the script can change this object.
159+
/**
160+
* Environment map passed to `process.env`.
161+
* This object will not be copied and the script can change this object.
146162
*/
147163
env?: any;
148164
/** Run modules in strict mode. Required modules are always strict. */
@@ -161,7 +177,7 @@ export class VM {
161177
/** Timeout to use for the run methods */
162178
timeout?: number;
163179
/** Runs the code */
164-
run(script: string|VMScript, options?: string|{filename?: string}): any;
180+
run(script: string | VMScript, options?: string | { filename?: string }): any;
165181
/** Runs the code in the specific file */
166182
runFile(filename: string): any;
167183
/** Loads all the values into the global object with the same names */
@@ -187,7 +203,7 @@ export class NodeVM extends EventEmitter implements VM {
187203
/** Require a module in VM and return it's exports. */
188204
require(module: string): any;
189205

190-
/**
206+
/**
191207
* Create NodeVM and run code inside it.
192208
*
193209
* @param {string} script JavaScript code.
@@ -204,12 +220,12 @@ export class NodeVM extends EventEmitter implements VM {
204220
*/
205221
static file(filename: string, options?: NodeVMOptions): any;
206222

207-
/** Direct access to the global sandbox object */
223+
/** Direct access to the global sandbox object */
208224
readonly sandbox: any;
209225
/** Only here because of implements VM. Does nothing. */
210226
timeout?: number;
211227
/** Runs the code */
212-
run(js: string|VMScript, options?: string|{filename?: string, wrapper?: "commonjs" | "none", strict?: boolean}): any;
228+
run(js: string | VMScript, options?: string | { filename?: string, wrapper?: "commonjs" | "none", strict?: boolean }): any;
213229
/** Runs the code in the specific file */
214230
runFile(filename: string): any;
215231
/** Loads all the values into the global object with the same names */
@@ -248,8 +264,8 @@ export class VMScript {
248264
readonly lineOffset: number;
249265
readonly columnOffset: number;
250266
readonly compiler: "javascript" | "coffeescript" | CompilerFunction;
251-
/**
252-
* Wraps the code
267+
/**
268+
* Wraps the code
253269
* @deprecated
254270
*/
255271
wrap(prefix: string, postfix: string): this;
@@ -258,4 +274,4 @@ export class VMScript {
258274
}
259275

260276
/** Custom Error class */
261-
export class VMError extends Error {}
277+
export class VMError extends Error { }

0 commit comments

Comments
 (0)