diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..175354b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+./node_modules/
+./target/
\ No newline at end of file
diff --git a/.npmrc b/.npmrc
new file mode 100644
index 0000000..9cf9495
--- /dev/null
+++ b/.npmrc
@@ -0,0 +1 @@
+package-lock=false
\ No newline at end of file
diff --git a/build-lib.bat b/build-lib.bat
deleted file mode 100644
index 09a93d8..0000000
--- a/build-lib.bat
+++ /dev/null
@@ -1 +0,0 @@
-cd src && tsc-bundle ./index.ts ../bin/index.js -gns typebox --lib es2015,dom --removeComments && cd ..
\ No newline at end of file
diff --git a/build-test.bat b/build-test.bat
deleted file mode 100644
index de7b51a..0000000
--- a/build-test.bat
+++ /dev/null
@@ -1 +0,0 @@
-cd test && tsc-bundle ./index.ts ../bin/test.js --lib es2015,dom --removeComments -w && cd ..
\ No newline at end of file
diff --git a/license b/license.md
similarity index 98%
rename from license
rename to license.md
index 8dff76b..e16585c 100644
--- a/license
+++ b/license.md
@@ -24,4 +24,4 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
----------------------------------------------------------------------------*/
\ No newline at end of file
+---------------------------------------------------------------------------*/
diff --git a/node_modules/@types/mocha/LICENSE b/node_modules/@types/mocha/LICENSE
new file mode 100644
index 0000000..2107107
--- /dev/null
+++ b/node_modules/@types/mocha/LICENSE
@@ -0,0 +1,21 @@
+ MIT License
+
+ Copyright (c) Microsoft Corporation. All rights reserved.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE
diff --git a/test/typings/mocha/README.md b/node_modules/@types/mocha/README.md
similarity index 86%
rename from test/typings/mocha/README.md
rename to node_modules/@types/mocha/README.md
index 48bc1a0..e179a4e 100644
--- a/test/typings/mocha/README.md
+++ b/node_modules/@types/mocha/README.md
@@ -1,16 +1,16 @@
-# Installation
-> `npm install --save @types/mocha`
-
-# Summary
-This package contains type definitions for mocha (http://mochajs.org/).
-
-# Details
-Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/master/mocha
-
-Additional Details
- * Last updated: Sat, 11 Mar 2017 01:36:05 GMT
- * Dependencies: none
- * Global values: Mocha, after, afterEach, before, beforeEach, context, describe, it, mocha, run, setup, specify, suite, suiteSetup, suiteTeardown, teardown, test, xdescribe, xit
-
-# Credits
-These definitions were written by Kazi Manzur Rashid , otiai10 , jt000 , Vadim Macagon .
+# Installation
+> `npm install --save @types/mocha`
+
+# Summary
+This package contains type definitions for mocha (http://mochajs.org/).
+
+# Details
+Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mocha
+
+Additional Details
+ * Last updated: Mon, 17 Apr 2017 17:55:17 GMT
+ * Dependencies: none
+ * Global values: Mocha, after, afterEach, before, beforeEach, context, describe, it, mocha, run, setup, specify, suite, suiteSetup, suiteTeardown, teardown, test, xdescribe, xit
+
+# Credits
+These definitions were written by Kazi Manzur Rashid , otiai10 , jt000 , Vadim Macagon .
diff --git a/test/typings/mocha/index.d.ts b/node_modules/@types/mocha/index.d.ts
similarity index 99%
rename from test/typings/mocha/index.d.ts
rename to node_modules/@types/mocha/index.d.ts
index b87a6e7..3fd1bbe 100644
--- a/test/typings/mocha/index.d.ts
+++ b/node_modules/@types/mocha/index.d.ts
@@ -139,6 +139,7 @@ declare namespace Mocha {
async: boolean;
sync: boolean;
timedOut: boolean;
+ timeout(n: number): this;
}
/** Partial interface for Mocha's `Suite` class. */
diff --git a/node_modules/@types/mocha/package.json b/node_modules/@types/mocha/package.json
new file mode 100644
index 0000000..9e3b9e7
--- /dev/null
+++ b/node_modules/@types/mocha/package.json
@@ -0,0 +1,60 @@
+{
+ "_from": "@types/mocha@^2.2.41",
+ "_id": "@types/mocha@2.2.41",
+ "_inBundle": false,
+ "_integrity": "sha1-4nzwgXFT658nE7LT9saPHhw8pgg=",
+ "_location": "/@types/mocha",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "@types/mocha@^2.2.41",
+ "name": "@types/mocha",
+ "escapedName": "@types%2fmocha",
+ "scope": "@types",
+ "rawSpec": "^2.2.41",
+ "saveSpec": null,
+ "fetchSpec": "^2.2.41"
+ },
+ "_requiredBy": [
+ "#DEV:/"
+ ],
+ "_resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.41.tgz",
+ "_shasum": "e27cf0817153eb9f2713b2d3f6c68f1e1c3ca608",
+ "_spec": "@types/mocha@^2.2.41",
+ "_where": "/home/sinclair/Desktop/typebox-upgrade",
+ "bundleDependencies": false,
+ "contributors": [
+ {
+ "name": "Kazi Manzur Rashid",
+ "url": "https://github.com/kazimanzurrashid/"
+ },
+ {
+ "name": "otiai10",
+ "url": "https://github.com/otiai10"
+ },
+ {
+ "name": "jt000",
+ "url": "https://github.com/jt000"
+ },
+ {
+ "name": "Vadim Macagon",
+ "url": "https://github.com/enlight"
+ }
+ ],
+ "dependencies": {},
+ "deprecated": false,
+ "description": "TypeScript definitions for mocha",
+ "license": "MIT",
+ "main": "",
+ "name": "@types/mocha",
+ "peerDependencies": {},
+ "repository": {
+ "type": "git",
+ "url": "https://www.github.com/DefinitelyTyped/DefinitelyTyped.git"
+ },
+ "scripts": {},
+ "typeScriptVersion": "2.0",
+ "typesPublisherContentHash": "a807ebbfd5494dfb5f8a321185bd06e39f4b1fabbe60f26c36cf3d1d86bb9de0",
+ "version": "2.2.41"
+}
diff --git a/node_modules/@types/node/LICENSE b/node_modules/@types/node/LICENSE
new file mode 100644
index 0000000..2107107
--- /dev/null
+++ b/node_modules/@types/node/LICENSE
@@ -0,0 +1,21 @@
+ MIT License
+
+ Copyright (c) Microsoft Corporation. All rights reserved.
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE
diff --git a/node_modules/@types/node/README.md b/node_modules/@types/node/README.md
new file mode 100644
index 0000000..205d049
--- /dev/null
+++ b/node_modules/@types/node/README.md
@@ -0,0 +1,16 @@
+# Installation
+> `npm install --save @types/node`
+
+# Summary
+This package contains type definitions for Node.js (http://nodejs.org/).
+
+# Details
+Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node
+
+Additional Details
+ * Last updated: Tue, 08 Aug 2017 21:39:34 GMT
+ * Dependencies: events, net, stream, url, child_process, tls, http, readline, crypto
+ * Global values: Buffer, NodeJS, SlowBuffer, Symbol, ___dirname, ___filename, clearImmediate, clearInterval, clearTimeout, console, exports, global, module, process, require, setImmediate, setInterval, setTimeout
+
+# Credits
+These definitions were written by Microsoft TypeScript , DefinitelyTyped , Parambir Singh , Roberto Desideri , Christian Vaagland Tellnes , Wilco Bakker , Nicolas Voigt , Chigozirim C. , Flarna , Mariusz Wiktorczyk , wwwy3y3 , Daniel Imms , Deividas Bakanas .
diff --git a/test/typings/node/index.d.ts b/node_modules/@types/node/index.d.ts
similarity index 51%
rename from test/typings/node/index.d.ts
rename to node_modules/@types/node/index.d.ts
index f132b2e..f73e0ff 100644
--- a/test/typings/node/index.d.ts
+++ b/node_modules/@types/node/index.d.ts
@@ -1,11 +1,24 @@
-// Type definitions for Node.js v7.x
+// Type definitions for Node.js 8.x
// Project: http://nodejs.org/
-// Definitions by: Microsoft TypeScript , DefinitelyTyped
+// Definitions by: Microsoft TypeScript
+// DefinitelyTyped
+// Parambir Singh
+// Roberto Desideri
+// Christian Vaagland Tellnes
+// Wilco Bakker
+// Nicolas Voigt
+// Chigozirim C.
+// Flarna
+// Mariusz Wiktorczyk
+// wwwy3y3
+// Daniel Imms
+// Deividas Bakanas
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
+// TypeScript Version: 2.2
/************************************************
* *
-* Node.js v7.x API *
+* Node.js v8.x API *
* *
************************************************/
@@ -13,7 +26,7 @@
interface Console {
Console: NodeJS.ConsoleConstructor;
assert(value: any, message?: string, ...optionalParams: any[]): void;
- dir(obj: any, options?: {showHidden?: boolean, depth?: number, colors?: boolean}): void;
+ dir(obj: any, options?: NodeJS.InspectOptions): void;
error(message?: any, ...optionalParams: any[]): void;
info(message?: any, ...optionalParams: any[]): void;
log(message?: any, ...optionalParams: any[]): void;
@@ -41,11 +54,11 @@ interface SetConstructor { }
interface WeakSetConstructor { }
// Forward-declare needed types from lib.es2015.d.ts (in case users are using `--lib es5`)
-interface Iterable {}
+interface Iterable { }
interface Iterator {
next(value?: any): IteratorResult;
}
-interface IteratorResult {}
+interface IteratorResult { }
interface SymbolConstructor {
readonly iterator: symbol;
}
@@ -70,6 +83,8 @@ declare function clearInterval(intervalId: NodeJS.Timer): void;
declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any;
declare function clearImmediate(immediateId: any): void;
+// TODO: change to `type NodeRequireFunction = (id: string) => any;` in next mayor version.
+/* tslint:disable:callable-types */
interface NodeRequireFunction {
(id: string): any;
}
@@ -98,19 +113,18 @@ declare var module: NodeModule;
// Same as module.exports
declare var exports: any;
declare var SlowBuffer: {
- new (str: string, encoding?: string): Buffer;
- new (size: number): Buffer;
- new (size: Uint8Array): Buffer;
- new (array: any[]): Buffer;
+ new(str: string, encoding?: string): Buffer;
+ new(size: number): Buffer;
+ new(size: Uint8Array): Buffer;
+ new(array: any[]): Buffer;
prototype: Buffer;
isBuffer(obj: any): boolean;
byteLength(string: string, encoding?: string): number;
concat(list: Buffer[], totalLength?: number): Buffer;
};
-
// Buffer class
-type BufferEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "binary" | "hex";
+type BufferEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "base64" | "latin1" | "binary" | "hex";
interface Buffer extends NodeBuffer { }
/**
@@ -125,19 +139,19 @@ declare var Buffer: {
* @param str String to store in buffer.
* @param encoding encoding to use, optional. Default is 'utf8'
*/
- new (str: string, encoding?: string): Buffer;
+ new(str: string, encoding?: string): Buffer;
/**
* Allocates a new buffer of {size} octets.
*
* @param size count of octets to allocate.
*/
- new (size: number): Buffer;
+ new(size: number): Buffer;
/**
* Allocates a new buffer containing the given {array} of octets.
*
* @param array The octets to store.
*/
- new (array: Uint8Array): Buffer;
+ new(array: Uint8Array): Buffer;
/**
* Produces a Buffer backed by the same allocated memory as
* the given {ArrayBuffer}.
@@ -145,19 +159,19 @@ declare var Buffer: {
*
* @param arrayBuffer The ArrayBuffer with which to share memory.
*/
- new (arrayBuffer: ArrayBuffer): Buffer;
+ new(arrayBuffer: ArrayBuffer): Buffer;
/**
* Allocates a new buffer containing the given {array} of octets.
*
* @param array The octets to store.
*/
- new (array: any[]): Buffer;
+ new(array: any[]): Buffer;
/**
* Copies the passed {buffer} data onto a new {Buffer} instance.
*
* @param buffer The buffer to copy.
*/
- new (buffer: Buffer): Buffer;
+ new(buffer: Buffer): Buffer;
prototype: Buffer;
/**
* Allocates a new Buffer using an {array} of octets.
@@ -258,6 +272,16 @@ declare var Buffer: {
* *
************************************************/
declare namespace NodeJS {
+ export interface InspectOptions {
+ showHidden?: boolean;
+ depth?: number | null;
+ colors?: boolean;
+ customInspect?: boolean;
+ showProxy?: boolean;
+ maxArrayLength?: number | null;
+ breakLength?: number;
+ }
+
export interface ConsoleConstructor {
prototype: Console;
new(stdout: WritableStream, stderr?: WritableStream): Console;
@@ -272,10 +296,10 @@ declare namespace NodeJS {
}
export class EventEmitter {
- addListener(event: string | symbol, listener: Function): this;
- on(event: string | symbol, listener: Function): this;
- once(event: string | symbol, listener: Function): this;
- removeListener(event: string | symbol, listener: Function): this;
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
+ once(event: string | symbol, listener: (...args: any[]) => void): this;
+ removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
removeAllListeners(event?: string | symbol): this;
setMaxListeners(n: number): this;
getMaxListeners(): number;
@@ -283,16 +307,15 @@ declare namespace NodeJS {
emit(event: string | symbol, ...args: any[]): boolean;
listenerCount(type: string | symbol): number;
// Added in Node 6...
- prependListener(event: string | symbol, listener: Function): this;
- prependOnceListener(event: string | symbol, listener: Function): this;
- eventNames(): (string | symbol)[];
+ prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
+ eventNames(): Array;
}
export interface ReadableStream extends EventEmitter {
readable: boolean;
- isTTY?: boolean;
read(size?: number): string | Buffer;
- setEncoding(encoding: string | null): this;
+ setEncoding(encoding: string): this;
pause(): this;
resume(): this;
isPaused(): boolean;
@@ -305,7 +328,6 @@ declare namespace NodeJS {
export interface WritableStream extends EventEmitter {
writable: boolean;
- isTTY?: boolean;
write(buffer: Buffer | string, cb?: Function): boolean;
write(str: string, encoding?: string, cb?: Function): boolean;
end(): void;
@@ -326,10 +348,10 @@ declare namespace NodeJS {
intercept(cb: (data: any) => any): any;
dispose(): void;
- addListener(event: string, listener: Function): this;
- on(event: string, listener: Function): this;
- once(event: string, listener: Function): this;
- removeListener(event: string, listener: Function): this;
+ addListener(event: string, listener: (...args: any[]) => void): this;
+ on(event: string, listener: (...args: any[]) => void): this;
+ once(event: string, listener: (...args: any[]) => void): this;
+ removeListener(event: string, listener: (...args: any[]) => void): this;
removeAllListeners(event?: string): this;
}
@@ -356,18 +378,46 @@ declare namespace NodeJS {
}
type Platform = 'aix'
- | 'android'
- | 'darwin'
- | 'freebsd'
- | 'linux'
- | 'openbsd'
- | 'sunos'
- | 'win32';
+ | 'android'
+ | 'darwin'
+ | 'freebsd'
+ | 'linux'
+ | 'openbsd'
+ | 'sunos'
+ | 'win32'
+ | 'cygwin';
+
+ type Signals =
+ "SIGABRT" | "SIGALRM" | "SIGBUS" | "SIGCHLD" | "SIGCONT" | "SIGFPE" | "SIGHUP" | "SIGILL" | "SIGINT" | "SIGIO" |
+ "SIGIOT" | "SIGKILL" | "SIGPIPE" | "SIGPOLL" | "SIGPROF" | "SIGPWR" | "SIGQUIT" | "SIGSEGV" | "SIGSTKFLT" |
+ "SIGSTOP" | "SIGSYS" | "SIGTERM" | "SIGTRAP" | "SIGTSTP" | "SIGTTIN" | "SIGTTOU" | "SIGUNUSED" | "SIGURG" |
+ "SIGUSR1" | "SIGUSR2" | "SIGVTALRM" | "SIGWINCH" | "SIGXCPU" | "SIGXFSZ" | "SIGBREAK" | "SIGLOST" | "SIGINFO";
+
+ type BeforeExitListener = (code: number) => void;
+ type DisconnectListener = () => void;
+ type ExitListener = (code: number) => void;
+ type RejectionHandledListener = (promise: Promise) => void;
+ type UncaughtExceptionListener = (error: Error) => void;
+ type UnhandledRejectionListener = (reason: any, promise: Promise) => void;
+ type WarningListener = (warning: Error) => void;
+ type MessageListener = (message: any, sendHandle: any) => void;
+ type SignalsListener = () => void;
+ type NewListenerListener = (type: string | symbol, listener: (...args: any[]) => void) => void;
+ type RemoveListenerListener = (type: string | symbol, listener: (...args: any[]) => void) => void;
+
+ export interface Socket extends ReadWriteStream {
+ isTTY?: true;
+ }
+
+ export interface ProcessEnv {
+ [key: string]: string | undefined;
+ }
export interface Process extends EventEmitter {
- stdout: WritableStream;
- stderr: WritableStream;
- stdin: ReadableStream;
+ stdout: Socket;
+ stderr: Socket;
+ stdin: Socket;
+ openStdin(): Socket;
argv: string[];
argv0: string;
execArgv: string[];
@@ -375,8 +425,9 @@ declare namespace NodeJS {
abort(): void;
chdir(directory: string): void;
cwd(): string;
- env: any;
- exit(code?: number): void;
+ emitWarning(warning: string | Error, name?: string, ctor?: Function): void;
+ env: ProcessEnv;
+ exit(code?: number): never;
exitCode: number;
getgid(): number;
setgid(id: number): void;
@@ -430,6 +481,104 @@ declare namespace NodeJS {
send?(message: any, sendHandle?: any): void;
disconnect(): void;
connected: boolean;
+
+ /**
+ * EventEmitter
+ * 1. beforeExit
+ * 2. disconnect
+ * 3. exit
+ * 4. message
+ * 5. rejectionHandled
+ * 6. uncaughtException
+ * 7. unhandledRejection
+ * 8. warning
+ * 9. message
+ * 10.
+ * 11. newListener/removeListener inherited from EventEmitter
+ */
+ addListener(event: "beforeExit", listener: BeforeExitListener): this;
+ addListener(event: "disconnect", listener: DisconnectListener): this;
+ addListener(event: "exit", listener: ExitListener): this;
+ addListener(event: "rejectionHandled", listener: RejectionHandledListener): this;
+ addListener(event: "uncaughtException", listener: UncaughtExceptionListener): this;
+ addListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
+ addListener(event: "warning", listener: WarningListener): this;
+ addListener(event: "message", listener: MessageListener): this;
+ addListener(event: Signals, listener: SignalsListener): this;
+ addListener(event: "newListener", listener: NewListenerListener): this;
+ addListener(event: "removeListener", listener: RemoveListenerListener): this;
+
+ emit(event: "beforeExit", code: number): boolean;
+ emit(event: "disconnect"): boolean;
+ emit(event: "exit", code: number): boolean;
+ emit(event: "rejectionHandled", promise: Promise): boolean;
+ emit(event: "uncaughtException", error: Error): boolean;
+ emit(event: "unhandledRejection", reason: any, promise: Promise): boolean;
+ emit(event: "warning", warning: Error): boolean;
+ emit(event: "message", message: any, sendHandle: any): this;
+ emit(event: Signals): boolean;
+ emit(event: "newListener", eventName: string | symbol, listener: (...args: any[]) => void): this;
+ emit(event: "removeListener", eventName: string, listener: (...args: any[]) => void): this;
+
+ on(event: "beforeExit", listener: BeforeExitListener): this;
+ on(event: "disconnect", listener: DisconnectListener): this;
+ on(event: "exit", listener: ExitListener): this;
+ on(event: "rejectionHandled", listener: RejectionHandledListener): this;
+ on(event: "uncaughtException", listener: UncaughtExceptionListener): this;
+ on(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
+ on(event: "warning", listener: WarningListener): this;
+ on(event: "message", listener: MessageListener): this;
+ on(event: Signals, listener: SignalsListener): this;
+ on(event: "newListener", listener: NewListenerListener): this;
+ on(event: "removeListener", listener: RemoveListenerListener): this;
+
+ once(event: "beforeExit", listener: BeforeExitListener): this;
+ once(event: "disconnect", listener: DisconnectListener): this;
+ once(event: "exit", listener: ExitListener): this;
+ once(event: "rejectionHandled", listener: RejectionHandledListener): this;
+ once(event: "uncaughtException", listener: UncaughtExceptionListener): this;
+ once(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
+ once(event: "warning", listener: WarningListener): this;
+ once(event: "message", listener: MessageListener): this;
+ once(event: Signals, listener: SignalsListener): this;
+ once(event: "newListener", listener: NewListenerListener): this;
+ once(event: "removeListener", listener: RemoveListenerListener): this;
+
+ prependListener(event: "beforeExit", listener: BeforeExitListener): this;
+ prependListener(event: "disconnect", listener: DisconnectListener): this;
+ prependListener(event: "exit", listener: ExitListener): this;
+ prependListener(event: "rejectionHandled", listener: RejectionHandledListener): this;
+ prependListener(event: "uncaughtException", listener: UncaughtExceptionListener): this;
+ prependListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
+ prependListener(event: "warning", listener: WarningListener): this;
+ prependListener(event: "message", listener: MessageListener): this;
+ prependListener(event: Signals, listener: SignalsListener): this;
+ prependListener(event: "newListener", listener: NewListenerListener): this;
+ prependListener(event: "removeListener", listener: RemoveListenerListener): this;
+
+ prependOnceListener(event: "beforeExit", listener: BeforeExitListener): this;
+ prependOnceListener(event: "disconnect", listener: DisconnectListener): this;
+ prependOnceListener(event: "exit", listener: ExitListener): this;
+ prependOnceListener(event: "rejectionHandled", listener: RejectionHandledListener): this;
+ prependOnceListener(event: "uncaughtException", listener: UncaughtExceptionListener): this;
+ prependOnceListener(event: "unhandledRejection", listener: UnhandledRejectionListener): this;
+ prependOnceListener(event: "warning", listener: WarningListener): this;
+ prependOnceListener(event: "message", listener: MessageListener): this;
+ prependOnceListener(event: Signals, listener: SignalsListener): this;
+ prependOnceListener(event: "newListener", listener: NewListenerListener): this;
+ prependOnceListener(event: "removeListener", listener: RemoveListenerListener): this;
+
+ listeners(event: "beforeExit"): BeforeExitListener[];
+ listeners(event: "disconnect"): DisconnectListener[];
+ listeners(event: "exit"): ExitListener[];
+ listeners(event: "rejectionHandled"): RejectionHandledListener[];
+ listeners(event: "uncaughtException"): UncaughtExceptionListener[];
+ listeners(event: "unhandledRejection"): UnhandledRejectionListener[];
+ listeners(event: "warning"): WarningListener[];
+ listeners(event: "message"): MessageListener[];
+ listeners(event: Signals): SignalsListener[];
+ listeners(event: "newListener"): NewListenerListener[];
+ listeners(event: "removeListener"): RemoveListenerListener[];
}
export interface Global {
@@ -602,18 +751,18 @@ declare module "events" {
static listenerCount(emitter: EventEmitter, event: string | symbol): number; // deprecated
static defaultMaxListeners: number;
- addListener(event: string | symbol, listener: Function): this;
- on(event: string | symbol, listener: Function): this;
- once(event: string | symbol, listener: Function): this;
- prependListener(event: string | symbol, listener: Function): this;
- prependOnceListener(event: string | symbol, listener: Function): this;
- removeListener(event: string | symbol, listener: Function): this;
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
+ once(event: string | symbol, listener: (...args: any[]) => void): this;
+ prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
+ removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
removeAllListeners(event?: string | symbol): this;
setMaxListeners(n: number): this;
getMaxListeners(): number;
listeners(event: string | symbol): Function[];
emit(event: string | symbol, ...args: any[]): boolean;
- eventNames(): (string | symbol)[];
+ eventNames(): Array;
listenerCount(type: string | symbol): number;
}
}
@@ -625,101 +774,122 @@ declare module "http" {
import * as events from "events";
import * as net from "net";
import * as stream from "stream";
+ import { URL } from "url";
- export interface RequestOptions {
+ // incoming headers will never contain number
+ export interface IncomingHttpHeaders {
+ [header: string]: string | string[];
+ }
+
+ // outgoing headers allows numbers (as they are converted internally to strings)
+ export interface OutgoingHttpHeaders {
+ [header: string]: number | string | string[] | undefined;
+ }
+
+ export interface ClientRequestArgs {
protocol?: string;
host?: string;
hostname?: string;
family?: number;
- port?: number;
+ port?: number | string;
+ defaultPort?: number | string;
localAddress?: string;
socketPath?: string;
method?: string;
path?: string;
- headers?: { [key: string]: any };
+ headers?: OutgoingHttpHeaders;
auth?: string;
agent?: Agent | boolean;
+ _defaultAgent?: Agent;
timeout?: number;
+ // https://github.com/nodejs/node/blob/master/lib/_http_client.js#L278
+ createConnection?: (options: ClientRequestArgs, oncreate: (err: Error, socket: net.Socket) => void) => net.Socket;
}
- export interface Server extends net.Server {
- setTimeout(msecs: number, callback: Function): void;
+ export class Server extends net.Server {
+ constructor(requestListener?: (req: IncomingMessage, res: ServerResponse) => void);
+
+ setTimeout(msecs: number, callback: () => void): this;
maxHeadersCount: number;
timeout: number;
listening: boolean;
+ keepAliveTimeout: number;
}
/**
* @deprecated Use IncomingMessage
*/
- export interface ServerRequest extends IncomingMessage {
+ export class ServerRequest extends IncomingMessage {
connection: net.Socket;
}
- export interface ServerResponse extends stream.Writable {
- // Extended base methods
- write(buffer: Buffer): boolean;
- write(buffer: Buffer, cb?: Function): boolean;
- write(str: string, cb?: Function): boolean;
- write(str: string, encoding?: string, cb?: Function): boolean;
- write(str: string, encoding?: string, fd?: string): boolean;
- writeContinue(): void;
- writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void;
- writeHead(statusCode: number, headers?: any): void;
+ // https://github.com/nodejs/node/blob/master/lib/_http_outgoing.js
+ export class OutgoingMessage extends stream.Writable {
+ upgrading: boolean;
+ chunkedEncoding: boolean;
+ shouldKeepAlive: boolean;
+ useChunkedEncodingByDefault: boolean;
+ sendDate: boolean;
+ finished: boolean;
+ headersSent: boolean;
+ connection: net.Socket;
+
+ constructor();
+
+ setTimeout(msecs: number, callback?: () => void): this;
+ destroy(error: Error): void;
+ setHeader(name: string, value: number | string | string[]): void;
+ getHeader(name: string): number | string | string[] | undefined;
+ getHeaders(): OutgoingHttpHeaders;
+ getHeaderNames(): string[];
+ hasHeader(name: string): boolean;
+ removeHeader(name: string): void;
+ addTrailers(headers: OutgoingHttpHeaders | Array<[string, string]>): void;
+ flushHeaders(): void;
+ }
+
+ // https://github.com/nodejs/node/blob/master/lib/_http_server.js#L108-L256
+ export class ServerResponse extends OutgoingMessage {
statusCode: number;
statusMessage: string;
- headersSent: boolean;
- setHeader(name: string, value: string | string[]): void;
- setTimeout(msecs: number, callback: Function): ServerResponse;
- sendDate: boolean;
- getHeader(name: string): string;
- removeHeader(name: string): void;
- write(chunk: any, encoding?: string): any;
- addTrailers(headers: any): void;
- finished: boolean;
- // Extended base methods
- end(): void;
- end(buffer: Buffer, cb?: Function): void;
- end(str: string, cb?: Function): void;
- end(str: string, encoding?: string, cb?: Function): void;
- end(data?: any, encoding?: string): void;
+ constructor(req: IncomingMessage);
+
+ assignSocket(socket: net.Socket): void;
+ detachSocket(socket: net.Socket): void;
+ // https://github.com/nodejs/node/blob/master/test/parallel/test-http-write-callbacks.js#L53
+ // no args in writeContinue callback
+ writeContinue(callback?: () => void): void;
+ writeHead(statusCode: number, reasonPhrase?: string, headers?: OutgoingHttpHeaders): void;
+ writeHead(statusCode: number, headers?: OutgoingHttpHeaders): void;
}
- export interface ClientRequest extends stream.Writable {
- // Extended base methods
- write(buffer: Buffer): boolean;
- write(buffer: Buffer, cb?: Function): boolean;
- write(str: string, cb?: Function): boolean;
- write(str: string, encoding?: string, cb?: Function): boolean;
- write(str: string, encoding?: string, fd?: string): boolean;
- write(chunk: any, encoding?: string): void;
+ // https://github.com/nodejs/node/blob/master/lib/_http_client.js#L77
+ export class ClientRequest extends OutgoingMessage {
+ connection: net.Socket;
+ socket: net.Socket;
+ aborted: number;
+
+ constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void);
+
abort(): void;
- setTimeout(timeout: number, callback?: Function): void;
+ onSocket(socket: net.Socket): void;
+ setTimeout(timeout: number, callback?: () => void): this;
setNoDelay(noDelay?: boolean): void;
setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
-
- setHeader(name: string, value: string | string[]): void;
- getHeader(name: string): string;
- removeHeader(name: string): void;
- addTrailers(headers: any): void;
-
- // Extended base methods
- end(): void;
- end(buffer: Buffer, cb?: Function): void;
- end(str: string, cb?: Function): void;
- end(str: string, encoding?: string, cb?: Function): void;
- end(data?: any, encoding?: string): void;
}
- export interface IncomingMessage extends stream.Readable {
+
+ export class IncomingMessage extends stream.Readable {
+ constructor(socket: net.Socket);
+
httpVersion: string;
httpVersionMajor: number;
httpVersionMinor: number;
connection: net.Socket;
- headers: any;
+ headers: IncomingHttpHeaders;
rawHeaders: string[];
- trailers: any;
- rawTrailers: any;
- setTimeout(msecs: number, callback: Function): NodeJS.Timer;
+ trailers: { [key: string]: string | undefined };
+ rawTrailers: string[];
+ setTimeout(msecs: number, callback: () => void): this;
/**
* Only valid for request obtained from http.Server.
*/
@@ -739,10 +909,11 @@ declare module "http" {
socket: net.Socket;
destroy(error?: Error): void;
}
+
/**
* @deprecated Use IncomingMessage
*/
- export interface ClientResponse extends IncomingMessage { }
+ export class ClientResponse extends IncomingMessage { }
export interface AgentOptions {
/**
@@ -783,13 +954,18 @@ declare module "http" {
export var METHODS: string[];
export var STATUS_CODES: {
- [errorCode: number]: string;
- [errorCode: string]: string;
+ [errorCode: number]: string | undefined;
+ [errorCode: string]: string | undefined;
};
+
export function createServer(requestListener?: (request: IncomingMessage, response: ServerResponse) => void): Server;
export function createClient(port?: number, host?: string): any;
- export function request(options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
- export function get(options: any, callback?: (res: IncomingMessage) => void): ClientRequest;
+
+ // although RequestOptions are passed as ClientRequestArgs to ClientRequest directly,
+ // create interface RequestOptions would make the naming more clear to developers
+ export interface RequestOptions extends ClientRequestArgs { }
+ export function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
+ export function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
export var globalAgent: Agent;
}
@@ -843,7 +1019,7 @@ declare module "cluster" {
* 5. message
* 6. online
*/
- addListener(event: string, listener: Function): this;
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "disconnect", listener: () => void): this;
addListener(event: "error", listener: (code: number, signal: string) => void): this;
addListener(event: "exit", listener: (code: number, signal: string) => void): this;
@@ -851,15 +1027,15 @@ declare module "cluster" {
addListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
addListener(event: "online", listener: () => void): this;
- emit(event: string, listener: Function): boolean
- emit(event: "disconnect", listener: () => void): boolean
- emit(event: "error", listener: (code: number, signal: string) => void): boolean
- emit(event: "exit", listener: (code: number, signal: string) => void): boolean
- emit(event: "listening", listener: (address: Address) => void): boolean
- emit(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): boolean
- emit(event: "online", listener: () => void): boolean
+ emit(event: string | symbol, ...args: any[]): boolean;
+ emit(event: "disconnect"): boolean;
+ emit(event: "error", code: number, signal: string): boolean;
+ emit(event: "exit", code: number, signal: string): boolean;
+ emit(event: "listening", address: Address): boolean;
+ emit(event: "message", message: any, handle: net.Socket | net.Server): boolean;
+ emit(event: "online"): boolean;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "disconnect", listener: () => void): this;
on(event: "error", listener: (code: number, signal: string) => void): this;
on(event: "exit", listener: (code: number, signal: string) => void): this;
@@ -867,7 +1043,7 @@ declare module "cluster" {
on(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
on(event: "online", listener: () => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "disconnect", listener: () => void): this;
once(event: "error", listener: (code: number, signal: string) => void): this;
once(event: "exit", listener: (code: number, signal: string) => void): this;
@@ -875,7 +1051,7 @@ declare module "cluster" {
once(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
once(event: "online", listener: () => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "disconnect", listener: () => void): this;
prependListener(event: "error", listener: (code: number, signal: string) => void): this;
prependListener(event: "exit", listener: (code: number, signal: string) => void): this;
@@ -883,7 +1059,7 @@ declare module "cluster" {
prependListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
prependListener(event: "online", listener: () => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "disconnect", listener: () => void): this;
prependOnceListener(event: "error", listener: (code: number, signal: string) => void): this;
prependOnceListener(event: "exit", listener: (code: number, signal: string) => void): this;
@@ -901,9 +1077,9 @@ declare module "cluster" {
// TODO: cluster.schedulingPolicy
settings: ClusterSettings;
setupMaster(settings?: ClusterSetupMasterSettings): void;
- worker: Worker;
- workers: {
- [index: string]: Worker
+ worker?: Worker;
+ workers?: {
+ [index: string]: Worker | undefined
};
/**
@@ -916,7 +1092,7 @@ declare module "cluster" {
* 6. online
* 7. setup
*/
- addListener(event: string, listener: Function): this;
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "disconnect", listener: (worker: Worker) => void): this;
addListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
addListener(event: "fork", listener: (worker: Worker) => void): this;
@@ -925,16 +1101,16 @@ declare module "cluster" {
addListener(event: "online", listener: (worker: Worker) => void): this;
addListener(event: "setup", listener: (settings: any) => void): this;
- emit(event: string, listener: Function): boolean;
- emit(event: "disconnect", listener: (worker: Worker) => void): boolean;
- emit(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): boolean;
- emit(event: "fork", listener: (worker: Worker) => void): boolean;
- emit(event: "listening", listener: (worker: Worker, address: Address) => void): boolean;
- emit(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): boolean;
- emit(event: "online", listener: (worker: Worker) => void): boolean;
- emit(event: "setup", listener: (settings: any) => void): boolean;
+ emit(event: string | symbol, ...args: any[]): boolean;
+ emit(event: "disconnect", worker: Worker): boolean;
+ emit(event: "exit", worker: Worker, code: number, signal: string): boolean;
+ emit(event: "fork", worker: Worker): boolean;
+ emit(event: "listening", worker: Worker, address: Address): boolean;
+ emit(event: "message", worker: Worker, message: any, handle: net.Socket | net.Server): boolean;
+ emit(event: "online", worker: Worker): boolean;
+ emit(event: "setup", settings: any): boolean;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "disconnect", listener: (worker: Worker) => void): this;
on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
on(event: "fork", listener: (worker: Worker) => void): this;
@@ -943,7 +1119,7 @@ declare module "cluster" {
on(event: "online", listener: (worker: Worker) => void): this;
on(event: "setup", listener: (settings: any) => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "disconnect", listener: (worker: Worker) => void): this;
once(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
once(event: "fork", listener: (worker: Worker) => void): this;
@@ -952,7 +1128,7 @@ declare module "cluster" {
once(event: "online", listener: (worker: Worker) => void): this;
once(event: "setup", listener: (settings: any) => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "disconnect", listener: (worker: Worker) => void): this;
prependListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
prependListener(event: "fork", listener: (worker: Worker) => void): this;
@@ -961,7 +1137,7 @@ declare module "cluster" {
prependListener(event: "online", listener: (worker: Worker) => void): this;
prependListener(event: "setup", listener: (settings: any) => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "disconnect", listener: (worker: Worker) => void): this;
prependOnceListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this;
prependOnceListener(event: "fork", listener: (worker: Worker) => void): this;
@@ -969,7 +1145,6 @@ declare module "cluster" {
prependOnceListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined.
prependOnceListener(event: "online", listener: (worker: Worker) => void): this;
prependOnceListener(event: "setup", listener: (settings: any) => void): this;
-
}
export function disconnect(callback?: Function): void;
@@ -981,7 +1156,7 @@ declare module "cluster" {
export function setupMaster(settings?: ClusterSetupMasterSettings): void;
export var worker: Worker;
export var workers: {
- [index: string]: Worker
+ [index: string]: Worker | undefined
};
/**
@@ -994,7 +1169,7 @@ declare module "cluster" {
* 6. online
* 7. setup
*/
- export function addListener(event: string, listener: Function): Cluster;
+ export function addListener(event: string, listener: (...args: any[]) => void): Cluster;
export function addListener(event: "disconnect", listener: (worker: Worker) => void): Cluster;
export function addListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster;
export function addListener(event: "fork", listener: (worker: Worker) => void): Cluster;
@@ -1003,16 +1178,16 @@ declare module "cluster" {
export function addListener(event: "online", listener: (worker: Worker) => void): Cluster;
export function addListener(event: "setup", listener: (settings: any) => void): Cluster;
- export function emit(event: string, listener: Function): boolean;
- export function emit(event: "disconnect", listener: (worker: Worker) => void): boolean;
- export function emit(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): boolean;
- export function emit(event: "fork", listener: (worker: Worker) => void): boolean;
- export function emit(event: "listening", listener: (worker: Worker, address: Address) => void): boolean;
- export function emit(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): boolean;
- export function emit(event: "online", listener: (worker: Worker) => void): boolean;
- export function emit(event: "setup", listener: (settings: any) => void): boolean;
+ export function emit(event: string | symbol, ...args: any[]): boolean;
+ export function emit(event: "disconnect", worker: Worker): boolean;
+ export function emit(event: "exit", worker: Worker, code: number, signal: string): boolean;
+ export function emit(event: "fork", worker: Worker): boolean;
+ export function emit(event: "listening", worker: Worker, address: Address): boolean;
+ export function emit(event: "message", worker: Worker, message: any, handle: net.Socket | net.Server): boolean;
+ export function emit(event: "online", worker: Worker): boolean;
+ export function emit(event: "setup", settings: any): boolean;
- export function on(event: string, listener: Function): Cluster;
+ export function on(event: string, listener: (...args: any[]) => void): Cluster;
export function on(event: "disconnect", listener: (worker: Worker) => void): Cluster;
export function on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster;
export function on(event: "fork", listener: (worker: Worker) => void): Cluster;
@@ -1021,7 +1196,7 @@ declare module "cluster" {
export function on(event: "online", listener: (worker: Worker) => void): Cluster;
export function on(event: "setup", listener: (settings: any) => void): Cluster;
- export function once(event: string, listener: Function): Cluster;
+ export function once(event: string, listener: (...args: any[]) => void): Cluster;
export function once(event: "disconnect", listener: (worker: Worker) => void): Cluster;
export function once(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster;
export function once(event: "fork", listener: (worker: Worker) => void): Cluster;
@@ -1030,14 +1205,14 @@ declare module "cluster" {
export function once(event: "online", listener: (worker: Worker) => void): Cluster;
export function once(event: "setup", listener: (settings: any) => void): Cluster;
- export function removeListener(event: string, listener: Function): Cluster;
+ export function removeListener(event: string, listener: (...args: any[]) => void): Cluster;
export function removeAllListeners(event?: string): Cluster;
export function setMaxListeners(n: number): Cluster;
export function getMaxListeners(): number;
export function listeners(event: string): Function[];
export function listenerCount(type: string): number;
- export function prependListener(event: string, listener: Function): Cluster;
+ export function prependListener(event: string, listener: (...args: any[]) => void): Cluster;
export function prependListener(event: "disconnect", listener: (worker: Worker) => void): Cluster;
export function prependListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster;
export function prependListener(event: "fork", listener: (worker: Worker) => void): Cluster;
@@ -1046,7 +1221,7 @@ declare module "cluster" {
export function prependListener(event: "online", listener: (worker: Worker) => void): Cluster;
export function prependListener(event: "setup", listener: (settings: any) => void): Cluster;
- export function prependOnceListener(event: string, listener: Function): Cluster;
+ export function prependOnceListener(event: string, listener: (...args: any[]) => void): Cluster;
export function prependOnceListener(event: "disconnect", listener: (worker: Worker) => void): Cluster;
export function prependOnceListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster;
export function prependOnceListener(event: "fork", listener: (worker: Worker) => void): Cluster;
@@ -1062,14 +1237,14 @@ declare module "zlib" {
import * as stream from "stream";
export interface ZlibOptions {
- flush?: number; // default: zlib.constants.Z_NO_FLUSH
- finishFlush?: number; // default: zlib.constants.Z_FINISH
- chunkSize?: number; // default: 16*1024
- windowBits?: number;
- level?: number; // compression only
- memLevel?: number; // compression only
- strategy?: number; // compression only
- dictionary?: any; // deflate/inflate only, empty dictionary by default
+ flush?: number; // default: zlib.constants.Z_NO_FLUSH
+ finishFlush?: number; // default: zlib.constants.Z_FINISH
+ chunkSize?: number; // default: 16*1024
+ windowBits?: number;
+ level?: number; // compression only
+ memLevel?: number; // compression only
+ strategy?: number; // compression only
+ dictionary?: any; // deflate/inflate only, empty dictionary by default
}
export interface Gzip extends stream.Transform { }
@@ -1089,18 +1264,25 @@ declare module "zlib" {
export function createUnzip(options?: ZlibOptions): Unzip;
export function deflate(buf: Buffer | string, callback: (error: Error, result: Buffer) => void): void;
+ export function deflate(buf: Buffer | string, options: ZlibOptions, callback: (error: Error, result: Buffer) => void): void;
export function deflateSync(buf: Buffer | string, options?: ZlibOptions): Buffer;
export function deflateRaw(buf: Buffer | string, callback: (error: Error, result: Buffer) => void): void;
+ export function deflateRaw(buf: Buffer | string, options: ZlibOptions, callback: (error: Error, result: Buffer) => void): void;
export function deflateRawSync(buf: Buffer | string, options?: ZlibOptions): Buffer;
export function gzip(buf: Buffer, callback: (error: Error, result: Buffer) => void): void;
+ export function gzip(buf: Buffer, options: ZlibOptions, callback: (error: Error, result: Buffer) => void): void;
export function gzipSync(buf: Buffer, options?: ZlibOptions): Buffer;
export function gunzip(buf: Buffer, callback: (error: Error, result: Buffer) => void): void;
+ export function gunzip(buf: Buffer, options: ZlibOptions, callback: (error: Error, result: Buffer) => void): void;
export function gunzipSync(buf: Buffer, options?: ZlibOptions): Buffer;
export function inflate(buf: Buffer, callback: (error: Error, result: Buffer) => void): void;
+ export function inflate(buf: Buffer, options: ZlibOptions, callback: (error: Error, result: Buffer) => void): void;
export function inflateSync(buf: Buffer, options?: ZlibOptions): Buffer;
export function inflateRaw(buf: Buffer, callback: (error: Error, result: Buffer) => void): void;
+ export function inflateRaw(buf: Buffer, options: ZlibOptions, callback: (error: Error, result: Buffer) => void): void;
export function inflateRawSync(buf: Buffer, options?: ZlibOptions): Buffer;
export function unzip(buf: Buffer, callback: (error: Error, result: Buffer) => void): void;
+ export function unzip(buf: Buffer, options: ZlibOptions, callback: (error: Error, result: Buffer) => void): void;
export function unzipSync(buf: Buffer, options?: ZlibOptions): Buffer;
export namespace constants {
@@ -1206,7 +1388,7 @@ declare module "os" {
export function release(): string;
export function networkInterfaces(): { [index: string]: NetworkInterfaceInfo[] };
export function homedir(): string;
- export function userInfo(options?: { encoding: string }): { username: string, uid: number, gid: number, shell: any, homedir: string }
+ export function userInfo(options?: { encoding: string }): { username: string, uid: number, gid: number, shell: any, homedir: string };
export var constants: {
UV_UDP_REUSEADDR: number,
signals: {
@@ -1338,6 +1520,7 @@ declare module "https" {
import * as tls from "tls";
import * as events from "events";
import * as http from "http";
+ import { URL } from "url";
export interface ServerOptions {
pfx?: any;
@@ -1365,6 +1548,12 @@ declare module "https" {
secureProtocol?: string;
}
+ export interface ClientRequest extends http.ClientRequest { }
+
+ export interface IncomingMessage extends http.IncomingMessage { }
+
+ export interface ServerResponse extends http.ServerResponse { }
+
export interface Agent extends http.Agent { }
export interface AgentOptions extends http.AgentOptions {
@@ -1380,12 +1569,12 @@ declare module "https" {
}
export var Agent: {
- new (options?: AgentOptions): Agent;
+ new(options?: AgentOptions): Agent;
};
export interface Server extends tls.Server { }
- export function createServer(options: ServerOptions, requestListener?: Function): Server;
- export function request(options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
- export function get(options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
+ export function createServer(options: ServerOptions, requestListener?: (req: IncomingMessage, res: ServerResponse) => void): Server;
+ export function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
+ export function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
export var globalAgent: Agent;
}
@@ -1422,6 +1611,7 @@ declare module "repl" {
}
export interface REPLServer extends readline.ReadLine {
+ context: any;
defineCommand(keyword: string, cmd: Function | { help: string, action: Function }): void;
displayPrompt(preserveCursor?: boolean): void;
@@ -1429,34 +1619,34 @@ declare module "repl" {
* events.EventEmitter
* 1. exit
* 2. reset
- **/
+ */
- addListener(event: string, listener: Function): this;
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "exit", listener: () => void): this;
- addListener(event: "reset", listener: Function): this;
+ addListener(event: "reset", listener: (...args: any[]) => void): this;
- emit(event: string, ...args: any[]): boolean;
+ emit(event: string | symbol, ...args: any[]): boolean;
emit(event: "exit"): boolean;
emit(event: "reset", context: any): boolean;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "exit", listener: () => void): this;
- on(event: "reset", listener: Function): this;
+ on(event: "reset", listener: (...args: any[]) => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "exit", listener: () => void): this;
- once(event: "reset", listener: Function): this;
+ once(event: "reset", listener: (...args: any[]) => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "exit", listener: () => void): this;
- prependListener(event: "reset", listener: Function): this;
+ prependListener(event: "reset", listener: (...args: any[]) => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "exit", listener: () => void): this;
- prependOnceListener(event: "reset", listener: Function): this;
+ prependOnceListener(event: "reset", listener: (...args: any[]) => void): this;
}
- export function start(options: ReplOptions): REPLServer;
+ export function start(options?: string | ReplOptions): REPLServer;
}
declare module "readline" {
@@ -1489,9 +1679,9 @@ declare module "readline" {
* 5. SIGCONT
* 6. SIGINT
* 7. SIGTSTP
- **/
+ */
- addListener(event: string, listener: Function): this;
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "close", listener: () => void): this;
addListener(event: "line", listener: (input: any) => void): this;
addListener(event: "pause", listener: () => void): this;
@@ -1500,7 +1690,7 @@ declare module "readline" {
addListener(event: "SIGINT", listener: () => void): this;
addListener(event: "SIGTSTP", listener: () => void): this;
- emit(event: string, ...args: any[]): boolean;
+ emit(event: string | symbol, ...args: any[]): boolean;
emit(event: "close"): boolean;
emit(event: "line", input: any): boolean;
emit(event: "pause"): boolean;
@@ -1509,7 +1699,7 @@ declare module "readline" {
emit(event: "SIGINT"): boolean;
emit(event: "SIGTSTP"): boolean;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "close", listener: () => void): this;
on(event: "line", listener: (input: any) => void): this;
on(event: "pause", listener: () => void): this;
@@ -1518,7 +1708,7 @@ declare module "readline" {
on(event: "SIGINT", listener: () => void): this;
on(event: "SIGTSTP", listener: () => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "close", listener: () => void): this;
once(event: "line", listener: (input: any) => void): this;
once(event: "pause", listener: () => void): this;
@@ -1527,7 +1717,7 @@ declare module "readline" {
once(event: "SIGINT", listener: () => void): this;
once(event: "SIGTSTP", listener: () => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "close", listener: () => void): this;
prependListener(event: "line", listener: (input: any) => void): this;
prependListener(event: "pause", listener: () => void): this;
@@ -1536,7 +1726,7 @@ declare module "readline" {
prependListener(event: "SIGINT", listener: () => void): this;
prependListener(event: "SIGTSTP", listener: () => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "close", listener: () => void): this;
prependOnceListener(event: "line", listener: (input: any) => void): this;
prependOnceListener(event: "pause", listener: () => void): this;
@@ -1562,7 +1752,7 @@ declare module "readline" {
export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean): ReadLine;
export function createInterface(options: ReadLineOptions): ReadLine;
- export function cursorTo(stream: NodeJS.WritableStream, x: number, y: number): void;
+ export function cursorTo(stream: NodeJS.WritableStream, x: number, y?: number): void;
export function moveCursor(stream: NodeJS.WritableStream, dx: number | string, dy: number | string): void;
export function clearLine(stream: NodeJS.WritableStream, dir: number): void;
export function clearScreenDown(stream: NodeJS.WritableStream): void;
@@ -1612,7 +1802,9 @@ declare module "child_process" {
stdio: [stream.Writable, stream.Readable, stream.Readable];
pid: number;
kill(signal?: string): void;
- send(message: any, sendHandle?: any): boolean;
+ send(message: any, callback?: (error: Error) => void): boolean;
+ send(message: any, sendHandle?: net.Socket | net.Server, callback?: (error: Error) => void): boolean;
+ send(message: any, sendHandle?: net.Socket | net.Server, options?: MessageOptions, callback?: (error: Error) => void): boolean;
connected: boolean;
disconnect(): void;
unref(): void;
@@ -1625,44 +1817,44 @@ declare module "child_process" {
* 3. error
* 4. exit
* 5. message
- **/
+ */
- addListener(event: string, listener: Function): this;
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "close", listener: (code: number, signal: string) => void): this;
addListener(event: "disconnect", listener: () => void): this;
addListener(event: "error", listener: (err: Error) => void): this;
addListener(event: "exit", listener: (code: number, signal: string) => void): this;
addListener(event: "message", listener: (message: any, sendHandle: net.Socket | net.Server) => void): this;
- emit(event: string, ...args: any[]): boolean;
+ emit(event: string | symbol, ...args: any[]): boolean;
emit(event: "close", code: number, signal: string): boolean;
emit(event: "disconnect"): boolean;
emit(event: "error", err: Error): boolean;
emit(event: "exit", code: number, signal: string): boolean;
emit(event: "message", message: any, sendHandle: net.Socket | net.Server): boolean;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "close", listener: (code: number, signal: string) => void): this;
on(event: "disconnect", listener: () => void): this;
on(event: "error", listener: (err: Error) => void): this;
on(event: "exit", listener: (code: number, signal: string) => void): this;
on(event: "message", listener: (message: any, sendHandle: net.Socket | net.Server) => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "close", listener: (code: number, signal: string) => void): this;
once(event: "disconnect", listener: () => void): this;
once(event: "error", listener: (err: Error) => void): this;
once(event: "exit", listener: (code: number, signal: string) => void): this;
once(event: "message", listener: (message: any, sendHandle: net.Socket | net.Server) => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "close", listener: (code: number, signal: string) => void): this;
prependListener(event: "disconnect", listener: () => void): this;
prependListener(event: "error", listener: (err: Error) => void): this;
prependListener(event: "exit", listener: (code: number, signal: string) => void): this;
prependListener(event: "message", listener: (message: any, sendHandle: net.Socket | net.Server) => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "close", listener: (code: number, signal: string) => void): this;
prependOnceListener(event: "disconnect", listener: () => void): this;
prependOnceListener(event: "error", listener: (err: Error) => void): this;
@@ -1670,6 +1862,10 @@ declare module "child_process" {
prependOnceListener(event: "message", listener: (message: any, sendHandle: net.Socket | net.Server) => void): this;
}
+ export interface MessageOptions {
+ keepOpen?: boolean;
+ }
+
export interface SpawnOptions {
cwd?: string;
env?: any;
@@ -1679,6 +1875,7 @@ declare module "child_process" {
gid?: number;
shell?: boolean | string;
}
+
export function spawn(command: string, args?: string[], options?: SpawnOptions): ChildProcess;
export interface ExecOptions {
@@ -1691,18 +1888,43 @@ declare module "child_process" {
uid?: number;
gid?: number;
}
+
export interface ExecOptionsWithStringEncoding extends ExecOptions {
encoding: BufferEncoding;
}
+
export interface ExecOptionsWithBufferEncoding extends ExecOptions {
- encoding: string; // specify `null`.
+ encoding: string | null; // specify `null`.
}
+
+ // no `options` definitely means stdout/stderr are `string`.
export function exec(command: string, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
- export function exec(command: string, options: ExecOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
- // usage. child_process.exec("tsc", {encoding: null as string}, (err, stdout, stderr) => {});
- export function exec(command: string, options: ExecOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess;
+
+ // `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
+ export function exec(command: string, options: { encoding: "buffer" | null } & ExecOptions, callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess;
+
+ // `options` with well known `encoding` means stdout/stderr are definitely `string`.
+ export function exec(command: string, options: { encoding: BufferEncoding } & ExecOptions, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
+
+ // `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
+ // There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
+ export function exec(command: string, options: { encoding: string } & ExecOptions, callback?: (error: Error, stdout: string | Buffer, stderr: string | Buffer) => void): ChildProcess;
+
+ // `options` without an `encoding` means stdout/stderr are definitely `string`.
export function exec(command: string, options: ExecOptions, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
+ // fallback if nothing else matches. Worst case is always `string | Buffer`.
+ export function exec(command: string, options: ({ encoding?: string | null } & ExecOptions) | undefined | null, callback?: (error: Error, stdout: string | Buffer, stderr: string | Buffer) => void): ChildProcess;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace exec {
+ export function __promisify__(command: string): Promise<{ stdout: string, stderr: string }>;
+ export function __promisify__(command: string, options: { encoding: "buffer" | null } & ExecOptions): Promise<{ stdout: Buffer, stderr: Buffer }>;
+ export function __promisify__(command: string, options: { encoding: BufferEncoding } & ExecOptions): Promise<{ stdout: string, stderr: string }>;
+ export function __promisify__(command: string, options: ExecOptions): Promise<{ stdout: string, stderr: string }>;
+ export function __promisify__(command: string, options?: ({ encoding?: string | null } & ExecOptions) | null): Promise<{ stdout: string | Buffer, stderr: string | Buffer }>;
+ }
+
export interface ExecFileOptions {
cwd?: string;
env?: any;
@@ -1716,18 +1938,52 @@ declare module "child_process" {
encoding: BufferEncoding;
}
export interface ExecFileOptionsWithBufferEncoding extends ExecFileOptions {
- encoding: string; // specify `null`.
+ encoding: string | null; // specify `null`.
+ }
+
+ export function execFile(file: string): ChildProcess;
+ export function execFile(file: string, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null): ChildProcess;
+ export function execFile(file: string, args: string[] | undefined | null): ChildProcess;
+ export function execFile(file: string, args: string[] | undefined | null, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null): ChildProcess;
+
+ // no `options` definitely means stdout/stderr are `string`.
+ export function execFile(file: string, callback: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
+
+ // `options` with `"buffer"` or `null` for `encoding` means stdout/stderr are definitely `Buffer`.
+ export function execFile(file: string, options: { encoding: "buffer" | null } & ExecFileOptions, callback: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
+ export function execFile(file: string, args: string[] | undefined | null, options: { encoding: "buffer" | null } & ExecFileOptions, callback: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
+
+ // `options` with well known `encoding` means stdout/stderr are definitely `string`.
+ export function execFile(file: string, options: { encoding: BufferEncoding } & ExecFileOptions, callback: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess;
+ export function execFile(file: string, args: string[] | undefined | null, options: { encoding: BufferEncoding } & ExecFileOptions, callback: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess;
+
+ // `options` with an `encoding` whose type is `string` means stdout/stderr could either be `Buffer` or `string`.
+ // There is no guarantee the `encoding` is unknown as `string` is a superset of `BufferEncoding`.
+ export function execFile(file: string, options: { encoding: string } & ExecFileOptions, callback: (error: Error, stdout: string | Buffer, stderr: string | Buffer) => void): ChildProcess;
+ export function execFile(file: string, args: string[] | undefined | null, options: { encoding: string } & ExecFileOptions, callback: (error: Error, stdout: string | Buffer, stderr: string | Buffer) => void): ChildProcess;
+
+ // `options` without an `encoding` means stdout/stderr are definitely `string`.
+ export function execFile(file: string, options: ExecFileOptions, callback: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
+ export function execFile(file: string, args: string[] | undefined | null, options: ExecFileOptions, callback: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
+
+ // fallback if nothing else matches. Worst case is always `string | Buffer`.
+ export function execFile(file: string, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null, callback: ((error: Error, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null): ChildProcess;
+ export function execFile(file: string, args: string[] | undefined | null, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null, callback: ((error: Error, stdout: string | Buffer, stderr: string | Buffer) => void) | undefined | null): ChildProcess;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace execFile {
+ export function __promisify__(file: string): Promise<{ stdout: string, stderr: string }>;
+ export function __promisify__(file: string, options: { encoding: "buffer" | null } & ExecFileOptions): Promise<{ stdout: string, stderr: string }>;
+ export function __promisify__(file: string, args: string[] | undefined | null, options: { encoding: "buffer" | null } & ExecFileOptions): Promise<{ stdout: string, stderr: string }>;
+ export function __promisify__(file: string, options: { encoding: BufferEncoding } & ExecFileOptions): Promise<{ stdout: Buffer, stderr: Buffer }>;
+ export function __promisify__(file: string, args: string[] | undefined | null, options: { encoding: BufferEncoding } & ExecFileOptions): Promise<{ stdout: Buffer, stderr: Buffer }>;
+ export function __promisify__(file: string, options: { encoding: string } & ExecFileOptions): Promise<{ stdout: string | Buffer, stderr: string | Buffer }>;
+ export function __promisify__(file: string, args: string[] | undefined | null, options: { encoding: string } & ExecFileOptions): Promise<{ stdout: string | Buffer, stderr: string | Buffer }>;
+ export function __promisify__(file: string, options: ExecFileOptions): Promise<{ stdout: string, stderr: string }>;
+ export function __promisify__(file: string, args: string[] | undefined | null, options: ExecFileOptions): Promise<{ stdout: string, stderr: string }>;
+ export function __promisify__(file: string, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null): Promise<{ stdout: string | Buffer, stderr: string | Buffer }>;
+ export function __promisify__(file: string, args: string[] | undefined | null, options: ({ encoding?: string | null } & ExecFileOptions) | undefined | null): Promise<{ stdout: string | Buffer, stderr: string | Buffer }>;
}
- export function execFile(file: string, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
- export function execFile(file: string, options?: ExecFileOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
- // usage. child_process.execFile("file.sh", {encoding: null as string}, (err, stdout, stderr) => {});
- export function execFile(file: string, options?: ExecFileOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess;
- export function execFile(file: string, options?: ExecFileOptions, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
- export function execFile(file: string, args?: string[], callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
- export function execFile(file: string, args?: string[], options?: ExecFileOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
- // usage. child_process.execFile("file.sh", ["foo"], {encoding: null as string}, (err, stdout, stderr) => {});
- export function execFile(file: string, args?: string[], options?: ExecFileOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess;
- export function execFile(file: string, args?: string[], options?: ExecFileOptions, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess;
export interface ForkOptions {
cwd?: string;
@@ -1735,6 +1991,7 @@ declare module "child_process" {
execPath?: string;
execArgv?: string[];
silent?: boolean;
+ stdio?: any[];
uid?: number;
gid?: number;
}
@@ -1843,12 +2100,33 @@ declare module "url" {
path?: string;
}
+ export interface UrlObject {
+ protocol?: string;
+ slashes?: boolean;
+ auth?: string;
+ host?: string;
+ hostname?: string;
+ port?: string | number;
+ pathname?: string;
+ search?: string;
+ query?: { [key: string]: any; };
+ hash?: string;
+ }
+
export function parse(urlStr: string, parseQueryString?: boolean, slashesDenoteHost?: boolean): Url;
- export function format(url: Url): string;
+ export function format(URL: URL, options?: URLFormatOptions): string;
+ export function format(urlObject: UrlObject): string;
export function resolve(from: string, to: string): string;
+ export interface URLFormatOptions {
+ auth?: boolean;
+ fragment?: boolean;
+ search?: boolean;
+ unicode?: boolean;
+ }
+
export class URLSearchParams implements Iterable {
- constructor(init?: URLSearchParams | string);
+ constructor(init?: URLSearchParams | string | { [key: string]: string | string[] | undefined } | Iterable);
append(name: string, value: string): void;
delete(name: string): void;
entries(): Iterator;
@@ -1884,26 +2162,145 @@ declare module "url" {
}
declare module "dns" {
- export interface MxRecord {
- exchange: string,
- priority: number
+ // Supported getaddrinfo flags.
+ export const ADDRCONFIG: number;
+ export const V4MAPPED: number;
+
+ export interface LookupOptions {
+ family?: number;
+ hints?: number;
+ all?: boolean;
}
- export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) => void): string;
- export function lookup(domain: string, callback: (err: Error, address: string, family: number) => void): string;
- export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) => void): string[];
- export function resolve(domain: string, callback: (err: Error, addresses: string[]) => void): string[];
- export function resolve4(domain: string, callback: (err: Error, addresses: string[]) => void): string[];
- export function resolve6(domain: string, callback: (err: Error, addresses: string[]) => void): string[];
- export function resolveMx(domain: string, callback: (err: Error, addresses: MxRecord[]) => void): string[];
- export function resolveTxt(domain: string, callback: (err: Error, addresses: string[][]) => void): string[][];
- export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) => void): string[];
- export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) => void): string[];
- export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) => void): string[];
- export function reverse(ip: string, callback: (err: Error, domains: string[]) => void): string[];
+ export interface LookupOneOptions extends LookupOptions {
+ all?: false;
+ }
+
+ export interface LookupAllOptions extends LookupOptions {
+ all: true;
+ }
+
+ export interface LookupAddress {
+ address: string;
+ family: number;
+ }
+
+ export function lookup(hostname: string, family: number, callback: (err: NodeJS.ErrnoException, address: string, family: number) => void): void;
+ export function lookup(hostname: string, options: LookupOneOptions, callback: (err: NodeJS.ErrnoException, address: string, family: number) => void): void;
+ export function lookup(hostname: string, options: LookupAllOptions, callback: (err: NodeJS.ErrnoException, addresses: LookupAddress[]) => void): void;
+ export function lookup(hostname: string, options: LookupOptions, callback: (err: NodeJS.ErrnoException, address: string | LookupAddress[], family: number) => void): void;
+ export function lookup(hostname: string, callback: (err: NodeJS.ErrnoException, address: string, family: number) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace lookup {
+ export function __promisify__(hostname: string, options: LookupAllOptions): Promise<{ address: LookupAddress[] }>;
+ export function __promisify__(hostname: string, options?: LookupOneOptions | number): Promise<{ address: string, family: number }>;
+ export function __promisify__(hostname: string, options?: LookupOptions | number): Promise<{ address: string | LookupAddress[], family?: number }>;
+ }
+
+ export interface ResolveOptions {
+ ttl: boolean;
+ }
+
+ export interface ResolveWithTtlOptions extends ResolveOptions {
+ ttl: true;
+ }
+
+ export interface RecordWithTtl {
+ address: string;
+ ttl: number;
+ }
+
+ export interface MxRecord {
+ priority: number;
+ exchange: string;
+ }
+
+ export interface NaptrRecord {
+ flags: string;
+ service: string;
+ regexp: string;
+ replacement: string;
+ order: number;
+ preference: number;
+ }
+
+ export interface SoaRecord {
+ nsname: string;
+ hostmaster: string;
+ serial: number;
+ refresh: number;
+ retry: number;
+ expire: number;
+ minttl: number;
+ }
+
+ export interface SrvRecord {
+ priority: number;
+ weight: number;
+ port: number;
+ name: string;
+ }
+
+ export function resolve(hostname: string, callback: (err: NodeJS.ErrnoException, addresses: string[]) => void): void;
+ export function resolve(hostname: string, rrtype: "A", callback: (err: NodeJS.ErrnoException, addresses: string[]) => void): void;
+ export function resolve(hostname: string, rrtype: "AAAA", callback: (err: NodeJS.ErrnoException, addresses: string[]) => void): void;
+ export function resolve(hostname: string, rrtype: "CNAME", callback: (err: NodeJS.ErrnoException, addresses: string[]) => void): void;
+ export function resolve(hostname: string, rrtype: "MX", callback: (err: NodeJS.ErrnoException, addresses: MxRecord[]) => void): void;
+ export function resolve(hostname: string, rrtype: "NAPTR", callback: (err: NodeJS.ErrnoException, addresses: NaptrRecord[]) => void): void;
+ export function resolve(hostname: string, rrtype: "NS", callback: (err: NodeJS.ErrnoException, addresses: string[]) => void): void;
+ export function resolve(hostname: string, rrtype: "PTR", callback: (err: NodeJS.ErrnoException, addresses: string[]) => void): void;
+ export function resolve(hostname: string, rrtype: "SOA", callback: (err: NodeJS.ErrnoException, addresses: SoaRecord) => void): void;
+ export function resolve(hostname: string, rrtype: "SRV", callback: (err: NodeJS.ErrnoException, addresses: SrvRecord[]) => void): void;
+ export function resolve(hostname: string, rrtype: "TXT", callback: (err: NodeJS.ErrnoException, addresses: string[][]) => void): void;
+ export function resolve(hostname: string, rrtype: string, callback: (err: NodeJS.ErrnoException, addresses: string[] | MxRecord[] | NaptrRecord[] | SoaRecord | SrvRecord[] | string[][]) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace resolve {
+ export function __promisify__(hostname: string, rrtype?: "A" | "AAAA" | "CNAME" | "NS" | "PTR"): Promise;
+ export function __promisify__(hostname: string, rrtype: "MX"): Promise;
+ export function __promisify__(hostname: string, rrtype: "NAPTR"): Promise;
+ export function __promisify__(hostname: string, rrtype: "SOA"): Promise;
+ export function __promisify__(hostname: string, rrtype: "SRV"): Promise;
+ export function __promisify__(hostname: string, rrtype: "TXT"): Promise;
+ export function __promisify__(hostname: string, rrtype?: string): Promise;
+ }
+
+ export function resolve4(hostname: string, callback: (err: NodeJS.ErrnoException, addresses: string[]) => void): void;
+ export function resolve4(hostname: string, options: ResolveWithTtlOptions, callback: (err: NodeJS.ErrnoException, addresses: RecordWithTtl[]) => void): void;
+ export function resolve4(hostname: string, options: ResolveOptions, callback: (err: NodeJS.ErrnoException, addresses: string[] | RecordWithTtl[]) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace resolve4 {
+ export function __promisify__(hostname: string): Promise;
+ export function __promisify__(hostname: string, options: ResolveWithTtlOptions): Promise;
+ export function __promisify__(hostname: string, options?: ResolveOptions): Promise;
+ }
+
+ export function resolve6(hostname: string, callback: (err: NodeJS.ErrnoException, addresses: string[]) => void): void;
+ export function resolve6(hostname: string, options: ResolveWithTtlOptions, callback: (err: NodeJS.ErrnoException, addresses: RecordWithTtl[]) => void): void;
+ export function resolve6(hostname: string, options: ResolveOptions, callback: (err: NodeJS.ErrnoException, addresses: string[] | RecordWithTtl[]) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace resolve6 {
+ export function __promisify__(hostname: string): Promise;
+ export function __promisify__(hostname: string, options: ResolveWithTtlOptions): Promise;
+ export function __promisify__(hostname: string, options?: ResolveOptions): Promise;
+ }
+
+ export function resolveCname(hostname: string, callback: (err: NodeJS.ErrnoException, addresses: string[]) => void): void;
+ export function resolveMx(hostname: string, callback: (err: NodeJS.ErrnoException, addresses: MxRecord[]) => void): void;
+ export function resolveNaptr(hostname: string, callback: (err: NodeJS.ErrnoException, addresses: NaptrRecord[]) => void): void;
+ export function resolveNs(hostname: string, callback: (err: NodeJS.ErrnoException, addresses: string[]) => void): void;
+ export function resolvePtr(hostname: string, callback: (err: NodeJS.ErrnoException, addresses: string[]) => void): void;
+ export function resolveSoa(hostname: string, callback: (err: NodeJS.ErrnoException, address: SoaRecord) => void): void;
+ export function resolveSrv(hostname: string, callback: (err: NodeJS.ErrnoException, addresses: SrvRecord[]) => void): void;
+ export function resolveTxt(hostname: string, callback: (err: NodeJS.ErrnoException, addresses: string[][]) => void): void;
+
+ export function reverse(ip: string, callback: (err: NodeJS.ErrnoException, hostnames: string[]) => void): void;
export function setServers(servers: string[]): void;
- //Error codes
+ // Error codes
export var NODATA: string;
export var FORMERR: string;
export var SERVFAIL: string;
@@ -1941,12 +2338,12 @@ declare module "net" {
write(str: string, cb?: Function): boolean;
write(str: string, encoding?: string, cb?: Function): boolean;
write(str: string, encoding?: string, fd?: string): boolean;
+ write(data: any, encoding?: string, callback?: Function): void;
connect(port: number, host?: string, connectionListener?: Function): void;
connect(path: string, connectionListener?: Function): void;
bufferSize: number;
setEncoding(encoding?: string): this;
- write(data: any, encoding?: string, callback?: Function): void;
destroy(err?: any): void;
pause(): this;
resume(): this;
@@ -1957,13 +2354,14 @@ declare module "net" {
unref(): void;
ref(): void;
- remoteAddress: string;
- remoteFamily: string;
- remotePort: number;
+ remoteAddress?: string;
+ remoteFamily?: string;
+ remotePort?: number;
localAddress: string;
localPort: number;
bytesRead: number;
bytesWritten: number;
+ connecting: boolean;
destroyed: boolean;
// Extended base methods
@@ -1984,7 +2382,7 @@ declare module "net" {
* 7. lookup
* 8. timeout
*/
- addListener(event: string, listener: Function): this;
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "close", listener: (had_error: boolean) => void): this;
addListener(event: "connect", listener: () => void): this;
addListener(event: "data", listener: (data: Buffer) => void): this;
@@ -1994,7 +2392,7 @@ declare module "net" {
addListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this;
addListener(event: "timeout", listener: () => void): this;
- emit(event: string, ...args: any[]): boolean;
+ emit(event: string | symbol, ...args: any[]): boolean;
emit(event: "close", had_error: boolean): boolean;
emit(event: "connect"): boolean;
emit(event: "data", data: Buffer): boolean;
@@ -2004,7 +2402,7 @@ declare module "net" {
emit(event: "lookup", err: Error, address: string, family: string | number, host: string): boolean;
emit(event: "timeout"): boolean;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "close", listener: (had_error: boolean) => void): this;
on(event: "connect", listener: () => void): this;
on(event: "data", listener: (data: Buffer) => void): this;
@@ -2014,7 +2412,7 @@ declare module "net" {
on(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this;
on(event: "timeout", listener: () => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "close", listener: (had_error: boolean) => void): this;
once(event: "connect", listener: () => void): this;
once(event: "data", listener: (data: Buffer) => void): this;
@@ -2024,7 +2422,7 @@ declare module "net" {
once(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this;
once(event: "timeout", listener: () => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "close", listener: (had_error: boolean) => void): this;
prependListener(event: "connect", listener: () => void): this;
prependListener(event: "data", listener: (data: Buffer) => void): this;
@@ -2034,7 +2432,7 @@ declare module "net" {
prependListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this;
prependListener(event: "timeout", listener: () => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "close", listener: (had_error: boolean) => void): this;
prependOnceListener(event: "connect", listener: () => void): this;
prependOnceListener(event: "data", listener: (data: Buffer) => void): this;
@@ -2046,7 +2444,7 @@ declare module "net" {
}
export var Socket: {
- new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket;
+ new(options?: { fd?: number; allowHalfOpen?: boolean; readable?: boolean; writable?: boolean; }): Socket;
};
export interface ListenOptions {
@@ -2057,11 +2455,15 @@ declare module "net" {
exclusive?: boolean;
}
- export interface Server extends events.EventEmitter {
- listen(port: number, hostname?: string, backlog?: number, listeningListener?: Function): Server;
- listen(port: number, hostname?: string, listeningListener?: Function): Server;
- listen(port: number, backlog?: number, listeningListener?: Function): Server;
- listen(port: number, listeningListener?: Function): Server;
+ // https://github.com/nodejs/node/blob/master/lib/net.js
+ export class Server extends events.EventEmitter {
+ constructor(connectionListener?: (socket: Socket) => void);
+ constructor(options?: { allowHalfOpen?: boolean, pauseOnConnect?: boolean }, connectionListener?: (socket: Socket) => void);
+
+ listen(port?: number, hostname?: string, backlog?: number, listeningListener?: Function): Server;
+ listen(port?: number, hostname?: string, listeningListener?: Function): Server;
+ listen(port?: number, backlog?: number, listeningListener?: Function): Server;
+ listen(port?: number, listeningListener?: Function): Server;
listen(path: string, backlog?: number, listeningListener?: Function): Server;
listen(path: string, listeningListener?: Function): Server;
listen(options: ListenOptions, listeningListener?: Function): Server;
@@ -2083,45 +2485,45 @@ declare module "net" {
* 3. error
* 4. listening
*/
- addListener(event: string, listener: Function): this;
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "close", listener: () => void): this;
addListener(event: "connection", listener: (socket: Socket) => void): this;
addListener(event: "error", listener: (err: Error) => void): this;
addListener(event: "listening", listener: () => void): this;
- emit(event: string, ...args: any[]): boolean;
+ emit(event: string | symbol, ...args: any[]): boolean;
emit(event: "close"): boolean;
emit(event: "connection", socket: Socket): boolean;
emit(event: "error", err: Error): boolean;
emit(event: "listening"): boolean;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "close", listener: () => void): this;
on(event: "connection", listener: (socket: Socket) => void): this;
on(event: "error", listener: (err: Error) => void): this;
on(event: "listening", listener: () => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "close", listener: () => void): this;
once(event: "connection", listener: (socket: Socket) => void): this;
once(event: "error", listener: (err: Error) => void): this;
once(event: "listening", listener: () => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "close", listener: () => void): this;
prependListener(event: "connection", listener: (socket: Socket) => void): this;
prependListener(event: "error", listener: (err: Error) => void): this;
prependListener(event: "listening", listener: () => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "close", listener: () => void): this;
prependOnceListener(event: "connection", listener: (socket: Socket) => void): this;
prependOnceListener(event: "error", listener: (err: Error) => void): this;
prependOnceListener(event: "listening", listener: () => void): this;
}
export function createServer(connectionListener?: (socket: Socket) => void): Server;
- export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) => void): Server;
- export function connect(options: { port: number, host?: string, localAddress?: string, localPort?: string, family?: number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket;
+ export function createServer(options?: { allowHalfOpen?: boolean, pauseOnConnect?: boolean }, connectionListener?: (socket: Socket) => void): Server;
+ export function connect(options: { port: number, host?: string, localAddress?: string, localPort?: number, family?: number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket;
export function connect(port: number, host?: string, connectionListener?: Function): Socket;
export function connect(path: string, connectionListener?: Function): Socket;
export function createConnection(options: { port: number, host?: string, localAddress?: string, localPort?: string, family?: number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket;
@@ -2153,18 +2555,22 @@ declare module "dgram" {
exclusive?: boolean;
}
+ type SocketType = "udp4" | "udp6";
+
interface SocketOptions {
- type: "udp4" | "udp6";
+ type: SocketType;
reuseAddr?: boolean;
}
- export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket;
+ export function createSocket(type: SocketType, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket;
export function createSocket(options: SocketOptions, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket;
export interface Socket extends events.EventEmitter {
send(msg: Buffer | String | any[], port: number, address: string, callback?: (error: Error, bytes: number) => void): void;
send(msg: Buffer | String | any[], offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void;
bind(port?: number, address?: string, callback?: () => void): void;
+ bind(port?: number, callback?: () => void): void;
+ bind(callback?: () => void): void;
bind(options: BindOptions, callback?: Function): void;
close(callback?: () => void): void;
address(): AddressInfo;
@@ -2183,38 +2589,38 @@ declare module "dgram" {
* 2. error
* 3. listening
* 4. message
- **/
- addListener(event: string, listener: Function): this;
+ */
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "close", listener: () => void): this;
addListener(event: "error", listener: (err: Error) => void): this;
addListener(event: "listening", listener: () => void): this;
addListener(event: "message", listener: (msg: Buffer, rinfo: AddressInfo) => void): this;
- emit(event: string, ...args: any[]): boolean;
+ emit(event: string | symbol, ...args: any[]): boolean;
emit(event: "close"): boolean;
emit(event: "error", err: Error): boolean;
emit(event: "listening"): boolean;
emit(event: "message", msg: Buffer, rinfo: AddressInfo): boolean;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "close", listener: () => void): this;
on(event: "error", listener: (err: Error) => void): this;
on(event: "listening", listener: () => void): this;
on(event: "message", listener: (msg: Buffer, rinfo: AddressInfo) => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "close", listener: () => void): this;
once(event: "error", listener: (err: Error) => void): this;
once(event: "listening", listener: () => void): this;
once(event: "message", listener: (msg: Buffer, rinfo: AddressInfo) => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "close", listener: () => void): this;
prependListener(event: "error", listener: (err: Error) => void): this;
prependListener(event: "listening", listener: () => void): this;
prependListener(event: "message", listener: (msg: Buffer, rinfo: AddressInfo) => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "close", listener: () => void): this;
prependOnceListener(event: "error", listener: (err: Error) => void): this;
prependOnceListener(event: "listening", listener: () => void): this;
@@ -2225,8 +2631,14 @@ declare module "dgram" {
declare module "fs" {
import * as stream from "stream";
import * as events from "events";
+ import { URL } from "url";
- interface Stats {
+ /**
+ * Valid types for path values in "fs".
+ */
+ export type PathLike = string | Buffer | URL;
+
+ export interface Stats {
isFile(): boolean;
isDirectory(): boolean;
isBlockDevice(): boolean;
@@ -2250,7 +2662,7 @@ declare module "fs" {
birthtime: Date;
}
- interface FSWatcher extends events.EventEmitter {
+ export interface FSWatcher extends events.EventEmitter {
close(): void;
/**
@@ -2258,23 +2670,23 @@ declare module "fs" {
* 1. change
* 2. error
*/
- addListener(event: string, listener: Function): this;
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
addListener(event: "error", listener: (code: number, signal: string) => void): this;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
on(event: "error", listener: (code: number, signal: string) => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
once(event: "error", listener: (code: number, signal: string) => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
prependListener(event: "error", listener: (code: number, signal: string) => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this;
prependOnceListener(event: "error", listener: (code: number, signal: string) => void): this;
}
@@ -2290,23 +2702,23 @@ declare module "fs" {
* 1. open
* 2. close
*/
- addListener(event: string, listener: Function): this;
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "open", listener: (fd: number) => void): this;
addListener(event: "close", listener: () => void): this;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "open", listener: (fd: number) => void): this;
on(event: "close", listener: () => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "open", listener: (fd: number) => void): this;
once(event: "close", listener: () => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "open", listener: (fd: number) => void): this;
prependListener(event: "close", listener: () => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "open", listener: (fd: number) => void): this;
prependOnceListener(event: "close", listener: () => void): this;
}
@@ -2321,254 +2733,1275 @@ declare module "fs" {
* 1. open
* 2. close
*/
- addListener(event: string, listener: Function): this;
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "open", listener: (fd: number) => void): this;
addListener(event: "close", listener: () => void): this;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "open", listener: (fd: number) => void): this;
on(event: "close", listener: () => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "open", listener: (fd: number) => void): this;
once(event: "close", listener: () => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "open", listener: (fd: number) => void): this;
prependListener(event: "close", listener: () => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "open", listener: (fd: number) => void): this;
prependOnceListener(event: "close", listener: () => void): this;
}
/**
- * Asynchronous rename.
- * @param oldPath
- * @param newPath
- * @param callback No arguments other than a possible exception are given to the completion callback.
+ * Asynchronous rename(2) - Change the name or location of a file or directory.
+ * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
*/
- export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
+ export function rename(oldPath: PathLike, newPath: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace rename {
+ /**
+ * Asynchronous rename(2) - Change the name or location of a file or directory.
+ * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function __promisify__(oldPath: PathLike, newPath: PathLike): Promise;
+ }
+
/**
- * Synchronous rename
- * @param oldPath
- * @param newPath
+ * Synchronous rename(2) - Change the name or location of a file or directory.
+ * @param oldPath A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function renameSync(oldPath: PathLike, newPath: PathLike): void;
+
+ /**
+ * Asynchronous truncate(2) - Truncate a file to a specified length.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param len If not specified, defaults to `0`.
+ */
+ export function truncate(path: PathLike, len: number | undefined | null, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ /**
+ * Asynchronous truncate(2) - Truncate a file to a specified length.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function truncate(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace truncate {
+ /**
+ * Asynchronous truncate(2) - Truncate a file to a specified length.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param len If not specified, defaults to `0`.
+ */
+ export function __promisify__(path: PathLike, len?: number | null): Promise;
+ }
+
+ /**
+ * Synchronous truncate(2) - Truncate a file to a specified length.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param len If not specified, defaults to `0`.
+ */
+ export function truncateSync(path: PathLike, len?: number | null): void;
+
+ /**
+ * Asynchronous ftruncate(2) - Truncate a file to a specified length.
+ * @param fd A file descriptor.
+ * @param len If not specified, defaults to `0`.
+ */
+ export function ftruncate(fd: number, len: number | undefined | null, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ /**
+ * Asynchronous ftruncate(2) - Truncate a file to a specified length.
+ * @param fd A file descriptor.
+ */
+ export function ftruncate(fd: number, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace ftruncate {
+ /**
+ * Asynchronous ftruncate(2) - Truncate a file to a specified length.
+ * @param fd A file descriptor.
+ * @param len If not specified, defaults to `0`.
+ */
+ export function __promisify__(fd: number, len?: number | null): Promise;
+ }
+
+ /**
+ * Synchronous ftruncate(2) - Truncate a file to a specified length.
+ * @param fd A file descriptor.
+ * @param len If not specified, defaults to `0`.
+ */
+ export function ftruncateSync(fd: number, len?: number | null): void;
+
+ /**
+ * Asynchronous chown(2) - Change ownership of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function chown(path: PathLike, uid: number, gid: number, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace chown {
+ /**
+ * Asynchronous chown(2) - Change ownership of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function __promisify__(path: PathLike, uid: number, gid: number): Promise;
+ }
+
+ /**
+ * Synchronous chown(2) - Change ownership of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function chownSync(path: PathLike, uid: number, gid: number): void;
+
+ /**
+ * Asynchronous fchown(2) - Change ownership of a file.
+ * @param fd A file descriptor.
+ */
+ export function fchown(fd: number, uid: number, gid: number, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace fchown {
+ /**
+ * Asynchronous fchown(2) - Change ownership of a file.
+ * @param fd A file descriptor.
+ */
+ export function __promisify__(fd: number, uid: number, gid: number): Promise;
+ }
+
+ /**
+ * Synchronous fchown(2) - Change ownership of a file.
+ * @param fd A file descriptor.
*/
- export function renameSync(oldPath: string, newPath: string): void;
- export function truncate(path: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function truncate(path: string | Buffer, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function truncateSync(path: string | Buffer, len?: number): void;
- export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function ftruncateSync(fd: number, len?: number): void;
- export function chown(path: string | Buffer, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function chownSync(path: string | Buffer, uid: number, gid: number): void;
- export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
export function fchownSync(fd: number, uid: number, gid: number): void;
- export function lchown(path: string | Buffer, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function lchownSync(path: string | Buffer, uid: number, gid: number): void;
- export function chmod(path: string | Buffer, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function chmod(path: string | Buffer, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function chmodSync(path: string | Buffer, mode: number): void;
- export function chmodSync(path: string | Buffer, mode: string): void;
- export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function fchmodSync(fd: number, mode: number): void;
- export function fchmodSync(fd: number, mode: string): void;
- export function lchmod(path: string | Buffer, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function lchmod(path: string | Buffer, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function lchmodSync(path: string | Buffer, mode: number): void;
- export function lchmodSync(path: string | Buffer, mode: string): void;
- export function stat(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
- export function lstat(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
- export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
- export function statSync(path: string | Buffer): Stats;
- export function lstatSync(path: string | Buffer): Stats;
+
+ /**
+ * Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function lchown(path: PathLike, uid: number, gid: number, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace lchown {
+ /**
+ * Asynchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function __promisify__(path: PathLike, uid: number, gid: number): Promise;
+ }
+
+ /**
+ * Synchronous lchown(2) - Change ownership of a file. Does not dereference symbolic links.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function lchownSync(path: PathLike, uid: number, gid: number): void;
+
+ /**
+ * Asynchronous chmod(2) - Change permissions of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
+ */
+ export function chmod(path: PathLike, mode: string | number, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace chmod {
+ /**
+ * Asynchronous chmod(2) - Change permissions of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
+ */
+ export function __promisify__(path: PathLike, mode: string | number): Promise;
+ }
+
+ /**
+ * Synchronous chmod(2) - Change permissions of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
+ */
+ export function chmodSync(path: PathLike, mode: string | number): void;
+
+ /**
+ * Asynchronous fchmod(2) - Change permissions of a file.
+ * @param fd A file descriptor.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
+ */
+ export function fchmod(fd: number, mode: string | number, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace fchmod {
+ /**
+ * Asynchronous fchmod(2) - Change permissions of a file.
+ * @param fd A file descriptor.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
+ */
+ export function __promisify__(fd: number, mode: string | number): Promise;
+ }
+
+ /**
+ * Synchronous fchmod(2) - Change permissions of a file.
+ * @param fd A file descriptor.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
+ */
+ export function fchmodSync(fd: number, mode: string | number): void;
+
+ /**
+ * Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
+ */
+ export function lchmod(path: PathLike, mode: string | number, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace lchmod {
+ /**
+ * Asynchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
+ */
+ export function __promisify__(path: PathLike, mode: string | number): Promise;
+ }
+
+ /**
+ * Synchronous lchmod(2) - Change permissions of a file. Does not dereference symbolic links.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer.
+ */
+ export function lchmodSync(path: PathLike, mode: string | number): void;
+
+ /**
+ * Asynchronous stat(2) - Get file status.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function stat(path: PathLike, callback: (err: NodeJS.ErrnoException, stats: Stats) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace stat {
+ /**
+ * Asynchronous stat(2) - Get file status.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function __promisify__(path: PathLike): Promise;
+ }
+
+ /**
+ * Synchronous stat(2) - Get file status.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function statSync(path: PathLike): Stats;
+
+ /**
+ * Asynchronous fstat(2) - Get file status.
+ * @param fd A file descriptor.
+ */
+ export function fstat(fd: number, callback: (err: NodeJS.ErrnoException, stats: Stats) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace fstat {
+ /**
+ * Asynchronous fstat(2) - Get file status.
+ * @param fd A file descriptor.
+ */
+ export function __promisify__(fd: number): Promise;
+ }
+
+ /**
+ * Synchronous fstat(2) - Get file status.
+ * @param fd A file descriptor.
+ */
export function fstatSync(fd: number): Stats;
- export function link(srcpath: string | Buffer, dstpath: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function linkSync(srcpath: string | Buffer, dstpath: string | Buffer): void;
- export function symlink(srcpath: string | Buffer, dstpath: string | Buffer, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function symlinkSync(srcpath: string | Buffer, dstpath: string | Buffer, type?: string): void;
- export function readlink(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void;
- export function readlinkSync(path: string | Buffer): string;
- export function realpath(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void;
- export function realpath(path: string | Buffer, cache: { [path: string]: string }, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void;
- export function realpathSync(path: string | Buffer, cache?: { [path: string]: string }): string;
+
/**
- * Asynchronous unlink - deletes the file specified in {path}
- *
- * @param path
- * @param callback No arguments other than a possible exception are given to the completion callback.
+ * Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
*/
- export function unlink(path: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void;
+ export function lstat(path: PathLike, callback: (err: NodeJS.ErrnoException, stats: Stats) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace lstat {
+ /**
+ * Asynchronous lstat(2) - Get file status. Does not dereference symbolic links.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function __promisify__(path: PathLike): Promise;
+ }
+
/**
- * Synchronous unlink - deletes the file specified in {path}
- *
- * @param path
+ * Synchronous lstat(2) - Get file status. Does not dereference symbolic links.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
*/
- export function unlinkSync(path: string | Buffer): void;
+ export function lstatSync(path: PathLike): Stats;
+
/**
- * Asynchronous rmdir - removes the directory specified in {path}
- *
- * @param path
- * @param callback No arguments other than a possible exception are given to the completion callback.
+ * Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
+ * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
*/
- export function rmdir(path: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void;
+ export function link(existingPath: PathLike, newPath: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace link {
+ /**
+ * Asynchronous link(2) - Create a new link (also known as a hard link) to an existing file.
+ * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function link(existingPath: PathLike, newPath: PathLike): Promise;
+ }
+
/**
- * Synchronous rmdir - removes the directory specified in {path}
- *
- * @param path
+ * Synchronous link(2) - Create a new link (also known as a hard link) to an existing file.
+ * @param existingPath A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param newPath A path to a file. If a URL is provided, it must use the `file:` protocol.
*/
- export function rmdirSync(path: string | Buffer): void;
+ export function linkSync(existingPath: PathLike, newPath: PathLike): void;
+
/**
- * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777.
- *
- * @param path
- * @param callback No arguments other than a possible exception are given to the completion callback.
+ * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
+ * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
+ * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
+ * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
+ * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
*/
- export function mkdir(path: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void;
+ export function symlink(target: PathLike, path: PathLike, type: string | undefined | null, callback: (err: NodeJS.ErrnoException) => void): void;
+
/**
- * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777.
- *
- * @param path
- * @param mode
- * @param callback No arguments other than a possible exception are given to the completion callback.
+ * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
+ * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
+ * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
*/
- export function mkdir(path: string | Buffer, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
+ export function symlink(target: PathLike, path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace symlink {
+ /**
+ * Asynchronous symlink(2) - Create a new symbolic link to an existing file.
+ * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
+ * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
+ * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
+ * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
+ */
+ export function __promisify__(target: PathLike, path: PathLike, type?: string | null): Promise;
+ }
+
/**
- * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777.
- *
- * @param path
- * @param mode
- * @param callback No arguments other than a possible exception are given to the completion callback.
+ * Synchronous symlink(2) - Create a new symbolic link to an existing file.
+ * @param target A path to an existing file. If a URL is provided, it must use the `file:` protocol.
+ * @param path A path to the new symlink. If a URL is provided, it must use the `file:` protocol.
+ * @param type May be set to `'dir'`, `'file'`, or `'junction'` (default is `'file'`) and is only available on Windows (ignored on other platforms).
+ * When using `'junction'`, the `target` argument will automatically be normalized to an absolute path.
*/
- export function mkdir(path: string | Buffer, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void;
+ export function symlinkSync(target: PathLike, path: PathLike, type?: string | null): void;
+
/**
- * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777.
- *
- * @param path
- * @param mode
- * @param callback No arguments other than a possible exception are given to the completion callback.
+ * Asynchronous readlink(2) - read value of a symbolic link.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
- export function mkdirSync(path: string | Buffer, mode?: number): void;
+ export function readlink(path: PathLike, options: { encoding?: BufferEncoding | null } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException, linkString: string) => void): void;
+
/**
- * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777.
- *
- * @param path
- * @param mode
- * @param callback No arguments other than a possible exception are given to the completion callback.
+ * Asynchronous readlink(2) - read value of a symbolic link.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
- export function mkdirSync(path: string | Buffer, mode?: string): void;
+ export function readlink(path: PathLike, options: { encoding: "buffer" } | "buffer", callback: (err: NodeJS.ErrnoException, linkString: Buffer) => void): void;
+
/**
- * Asynchronous mkdtemp - Creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
- *
- * @param prefix
- * @param callback The created folder path is passed as a string to the callback's second parameter.
+ * Asynchronous readlink(2) - read value of a symbolic link.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
*/
- export function mkdtemp(prefix: string, callback?: (err: NodeJS.ErrnoException, folder: string) => void): void;
+ export function readlink(path: PathLike, options: { encoding?: string | null } | string | undefined | null, callback: (err: NodeJS.ErrnoException, linkString: string | Buffer) => void): void;
+
/**
- * Synchronous mkdtemp - Creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
- *
- * @param prefix
- * @returns Returns the created folder path.
+ * Asynchronous readlink(2) - read value of a symbolic link.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function readlink(path: PathLike, callback: (err: NodeJS.ErrnoException, linkString: string) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace readlink {
+ /**
+ * Asynchronous readlink(2) - read value of a symbolic link.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function __promisify__(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise;
+
+ /**
+ * Asynchronous readlink(2) - read value of a symbolic link.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function __promisify__(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise;
+
+ /**
+ * Asynchronous readlink(2) - read value of a symbolic link.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function __promisify__(path: PathLike, options?: { encoding?: string | null } | string | null): Promise;
+ }
+
+ /**
+ * Synchronous readlink(2) - read value of a symbolic link.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function readlinkSync(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): string;
+
+ /**
+ * Synchronous readlink(2) - read value of a symbolic link.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function readlinkSync(path: PathLike, options: { encoding: "buffer" } | "buffer"): Buffer;
+
+ /**
+ * Synchronous readlink(2) - read value of a symbolic link.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function readlinkSync(path: PathLike, options?: { encoding?: string | null } | string | null): string | Buffer;
+
+ /**
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function realpath(path: PathLike, options: { encoding?: BufferEncoding | null } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => void): void;
+
+ /**
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function realpath(path: PathLike, options: { encoding: "buffer" } | "buffer", callback: (err: NodeJS.ErrnoException, resolvedPath: Buffer) => void): void;
+
+ /**
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function realpath(path: PathLike, options: { encoding?: string | null } | string | undefined | null, callback: (err: NodeJS.ErrnoException, resolvedPath: string | Buffer) => void): void;
+
+ /**
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function realpath(path: PathLike, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace realpath {
+ /**
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function __promisify__(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise;
+
+ /**
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function __promisify__(path: PathLike, options: { encoding: "buffer" } | "buffer"): Promise;
+
+ /**
+ * Asynchronous realpath(3) - return the canonicalized absolute pathname.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function __promisify__(path: PathLike, options?: { encoding?: string | null } | string | null): Promise;
+ }
+
+ /**
+ * Synchronous realpath(3) - return the canonicalized absolute pathname.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function realpathSync(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): string;
+
+ /**
+ * Synchronous realpath(3) - return the canonicalized absolute pathname.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function realpathSync(path: PathLike, options: { encoding: "buffer" } | "buffer"): Buffer;
+
+ /**
+ * Synchronous realpath(3) - return the canonicalized absolute pathname.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function realpathSync(path: PathLike, options?: { encoding?: string | null } | string | null): string | Buffer;
+
+ /**
+ * Asynchronous unlink(2) - delete a name and possibly the file it refers to.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function unlink(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace unlink {
+ /**
+ * Asynchronous unlink(2) - delete a name and possibly the file it refers to.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function __promisify__(path: PathLike): Promise;
+ }
+
+ /**
+ * Synchronous unlink(2) - delete a name and possibly the file it refers to.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function unlinkSync(path: PathLike): void;
+
+ /**
+ * Asynchronous rmdir(2) - delete a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function rmdir(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace rmdir {
+ /**
+ * Asynchronous rmdir(2) - delete a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function __promisify__(path: PathLike): Promise;
+ }
+
+ /**
+ * Synchronous rmdir(2) - delete a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function rmdirSync(path: PathLike): void;
+
+ /**
+ * Asynchronous mkdir(2) - create a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
+ */
+ export function mkdir(path: PathLike, mode: number | string | undefined | null, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ /**
+ * Asynchronous mkdir(2) - create a directory with a mode of `0o777`.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function mkdir(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace mkdir {
+ /**
+ * Asynchronous mkdir(2) - create a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
+ */
+ export function __promisify__(path: PathLike, mode?: number | string | null): Promise;
+ }
+
+ /**
+ * Synchronous mkdir(2) - create a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not specified, defaults to `0o777`.
+ */
+ export function mkdirSync(path: PathLike, mode?: number | string | null): void;
+
+ /**
+ * Asynchronously creates a unique temporary directory.
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function mkdtemp(prefix: string, options: { encoding?: BufferEncoding | null } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException, folder: string) => void): void;
+
+ /**
+ * Asynchronously creates a unique temporary directory.
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function mkdtemp(prefix: string, options: "buffer" | { encoding: "buffer" }, callback: (err: NodeJS.ErrnoException, folder: Buffer) => void): void;
+
+ /**
+ * Asynchronously creates a unique temporary directory.
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function mkdtemp(prefix: string, options: { encoding?: string | null } | string | undefined | null, callback: (err: NodeJS.ErrnoException, folder: string | Buffer) => void): void;
+
+ /**
+ * Asynchronously creates a unique temporary directory.
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
+ */
+ export function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException, folder: string) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace mkdtemp {
+ /**
+ * Asynchronously creates a unique temporary directory.
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function __promisify__(prefix: string, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise;
+
+ /**
+ * Asynchronously creates a unique temporary directory.
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function __promisify__(prefix: string, options: { encoding: "buffer" } | "buffer"): Promise;
+
+ /**
+ * Asynchronously creates a unique temporary directory.
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function __promisify__(prefix: string, options?: { encoding?: string | null } | string | null): Promise;
+ }
+
+ /**
+ * Synchronously creates a unique temporary directory.
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function mkdtempSync(prefix: string, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): string;
+
+ /**
+ * Synchronously creates a unique temporary directory.
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function mkdtempSync(prefix: string, options: { encoding: "buffer" } | "buffer"): Buffer;
+
+ /**
+ * Synchronously creates a unique temporary directory.
+ * Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function mkdtempSync(prefix: string, options?: { encoding?: string | null } | string | null): string | Buffer;
+
+ /**
+ * Asynchronous readdir(3) - read a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function readdir(path: PathLike, options: { encoding: BufferEncoding | null } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException, files: string[]) => void): void;
+
+ /**
+ * Asynchronous readdir(3) - read a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function readdir(path: PathLike, options: { encoding: "buffer" } | "buffer", callback: (err: NodeJS.ErrnoException, files: Buffer[]) => void): void;
+
+ /**
+ * Asynchronous readdir(3) - read a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function readdir(path: PathLike, options: { encoding?: string | null } | string | undefined | null, callback: (err: NodeJS.ErrnoException, files: Array) => void): void;
+
+ /**
+ * Asynchronous readdir(3) - read a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function readdir(path: PathLike, callback: (err: NodeJS.ErrnoException, files: string[]) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace readdir {
+ /**
+ * Asynchronous readdir(3) - read a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function __promisify__(path: PathLike, options?: { encoding: BufferEncoding | null } | BufferEncoding | null): Promise;
+
+ /**
+ * Asynchronous readdir(3) - read a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function __promisify__(path: PathLike, options: "buffer" | { encoding: "buffer" }): Promise;
+
+ /**
+ * Asynchronous readdir(3) - read a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function __promisify__(path: PathLike, options?: { encoding?: string | null } | string | null): Promise>;
+ }
+
+ /**
+ * Synchronous readdir(3) - read a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function readdirSync(path: PathLike, options?: { encoding: BufferEncoding | null } | BufferEncoding | null): string[];
+
+ /**
+ * Synchronous readdir(3) - read a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function readdirSync(path: PathLike, options: { encoding: "buffer" } | "buffer"): Buffer[];
+
+ /**
+ * Synchronous readdir(3) - read a directory.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param options The encoding (or an object specifying the encoding), used as the encoding of the result. If not provided, `'utf8'` is used.
+ */
+ export function readdirSync(path: PathLike, options?: { encoding?: string | null } | string | null): Array;
+
+ /**
+ * Asynchronous close(2) - close a file descriptor.
+ * @param fd A file descriptor.
+ */
+ export function close(fd: number, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace close {
+ /**
+ * Asynchronous close(2) - close a file descriptor.
+ * @param fd A file descriptor.
+ */
+ export function __promisify__(fd: number): Promise;
+ }
+
+ /**
+ * Synchronous close(2) - close a file descriptor.
+ * @param fd A file descriptor.
*/
- export function mkdtempSync(prefix: string): string;
- export function readdir(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void;
- export function readdirSync(path: string | Buffer): string[];
- export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
export function closeSync(fd: number): void;
- export function open(path: string | Buffer, flags: string | number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void;
- export function open(path: string | Buffer, flags: string | number, mode: number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void;
- export function openSync(path: string | Buffer, flags: string | number, mode?: number): number;
- export function utimes(path: string | Buffer, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function utimes(path: string | Buffer, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function utimesSync(path: string | Buffer, atime: number, mtime: number): void;
- export function utimesSync(path: string | Buffer, atime: Date, mtime: Date): void;
- export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void;
- export function futimesSync(fd: number, atime: number, mtime: number): void;
- export function futimesSync(fd: number, atime: Date, mtime: Date): void;
- export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void;
+
+ /**
+ * Asynchronous open(2) - open and possibly create a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
+ */
+ export function open(path: PathLike, flags: string | number, mode: string | number | undefined | null, callback: (err: NodeJS.ErrnoException, fd: number) => void): void;
+
+ /**
+ * Asynchronous open(2) - open and possibly create a file. If the file is created, its mode will be `0o666`.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ */
+ export function open(path: PathLike, flags: string | number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace open {
+ /**
+ * Asynchronous open(2) - open and possibly create a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
+ */
+ export function __promisify__(path: PathLike, flags: string | number, mode?: string | number | null): Promise;
+ }
+
+ /**
+ * Synchronous open(2) - open and possibly create a file, returning a file descriptor..
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param mode A file mode. If a string is passed, it is parsed as an octal integer. If not supplied, defaults to `0o666`.
+ */
+ export function openSync(path: PathLike, flags: string | number, mode?: string | number | null): number;
+
+ /**
+ * Asynchronously change file timestamps of the file referenced by the supplied path.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param atime The last access time. If a string is provided, it will be coerced to number.
+ * @param mtime The last modified time. If a string is provided, it will be coerced to number.
+ */
+ export function utimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace utimes {
+ /**
+ * Asynchronously change file timestamps of the file referenced by the supplied path.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param atime The last access time. If a string is provided, it will be coerced to number.
+ * @param mtime The last modified time. If a string is provided, it will be coerced to number.
+ */
+ export function __promisify__(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise;
+ }
+
+ /**
+ * Synchronously change file timestamps of the file referenced by the supplied path.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * @param atime The last access time. If a string is provided, it will be coerced to number.
+ * @param mtime The last modified time. If a string is provided, it will be coerced to number.
+ */
+ export function utimesSync(path: PathLike, atime: string | number | Date, mtime: string | number | Date): void;
+
+ /**
+ * Asynchronously change file timestamps of the file referenced by the supplied file descriptor.
+ * @param fd A file descriptor.
+ * @param atime The last access time. If a string is provided, it will be coerced to number.
+ * @param mtime The last modified time. If a string is provided, it will be coerced to number.
+ */
+ export function futimes(fd: number, atime: string | number | Date, mtime: string | number | Date, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace futimes {
+ /**
+ * Asynchronously change file timestamps of the file referenced by the supplied file descriptor.
+ * @param fd A file descriptor.
+ * @param atime The last access time. If a string is provided, it will be coerced to number.
+ * @param mtime The last modified time. If a string is provided, it will be coerced to number.
+ */
+ export function __promisify__(fd: number, atime: string | number | Date, mtime: string | number | Date): Promise;
+ }
+
+ /**
+ * Synchronously change file timestamps of the file referenced by the supplied file descriptor.
+ * @param fd A file descriptor.
+ * @param atime The last access time. If a string is provided, it will be coerced to number.
+ * @param mtime The last modified time. If a string is provided, it will be coerced to number.
+ */
+ export function futimesSync(fd: number, atime: string | number | Date, mtime: string | number | Date): void;
+
+ /**
+ * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
+ * @param fd A file descriptor.
+ */
+ export function fsync(fd: number, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace fsync {
+ /**
+ * Asynchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
+ * @param fd A file descriptor.
+ */
+ export function __promisify__(fd: number): Promise;
+ }
+
+ /**
+ * Synchronous fsync(2) - synchronize a file's in-core state with the underlying storage device.
+ * @param fd A file descriptor.
+ */
export function fsyncSync(fd: number): void;
- export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void;
- export function write(fd: number, buffer: Buffer, offset: number, length: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void;
- export function write(fd: number, data: any, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void;
- export function write(fd: number, data: any, offset: number, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void;
- export function write(fd: number, data: any, offset: number, encoding: string, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void;
- export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position?: number): number;
- export function writeSync(fd: number, data: any, position?: number, enconding?: string): number;
- export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void;
- export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number;
+
/**
- * Asynchronous readFile - Asynchronously reads the entire contents of a file.
- *
- * @param fileName
- * @param encoding
- * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file.
+ * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
+ * @param fd A file descriptor.
+ * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
+ * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
+ * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
*/
- export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void;
+ export function write(fd: number, buffer: TBuffer, offset: number | undefined | null, length: number | undefined | null, position: number | undefined | null, callback: (err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void): void;
+
/**
- * Asynchronous readFile - Asynchronously reads the entire contents of a file.
- *
- * @param fileName
- * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer.
- * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file.
+ * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
+ * @param fd A file descriptor.
+ * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
+ * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
*/
- export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void;
+ export function write(fd: number, buffer: TBuffer, offset: number | undefined | null, length: number | undefined | null, callback: (err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void): void;
+
/**
- * Asynchronous readFile - Asynchronously reads the entire contents of a file.
- *
- * @param fileName
- * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer.
- * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file.
+ * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
+ * @param fd A file descriptor.
+ * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
*/
- export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void;
+ export function write(fd: number, buffer: TBuffer, offset: number | undefined | null, callback: (err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void): void;
+
/**
- * Asynchronous readFile - Asynchronously reads the entire contents of a file.
- *
- * @param fileName
- * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file.
+ * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
+ * @param fd A file descriptor.
*/
- export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void;
+ export function write(fd: number, buffer: TBuffer, callback: (err: NodeJS.ErrnoException, written: number, buffer: TBuffer) => void): void;
+
/**
- * Synchronous readFile - Synchronously reads the entire contents of a file.
- *
- * @param fileName
- * @param encoding
+ * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
+ * @param fd A file descriptor.
+ * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
+ * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
+ * @param encoding The expected string encoding.
*/
- export function readFileSync(filename: string, encoding: string): string;
+ export function write(fd: number, string: any, position: number | undefined | null, encoding: string | undefined | null, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void;
+
/**
- * Synchronous readFile - Synchronously reads the entire contents of a file.
- *
- * @param fileName
- * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer.
+ * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
+ * @param fd A file descriptor.
+ * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
+ * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
*/
- export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string;
+ export function write(fd: number, string: any, position: number | undefined | null, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void;
+
/**
- * Synchronous readFile - Synchronously reads the entire contents of a file.
- *
- * @param fileName
- * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer.
+ * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
+ * @param fd A file descriptor.
+ * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
*/
- export function readFileSync(filename: string, options?: { flag?: string; }): Buffer;
- export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void;
- export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void;
- export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void;
- export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void;
- export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void;
- export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void;
- export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void;
- export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void;
- export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void;
- export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void;
- export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void;
- export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void;
- export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void;
- export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher;
- export function watch(filename: string, encoding: string, listener?: (event: string, filename: string | Buffer) => any): FSWatcher;
- export function watch(filename: string, options: { persistent?: boolean; recursive?: boolean; encoding?: string }, listener?: (event: string, filename: string | Buffer) => any): FSWatcher;
- export function exists(path: string | Buffer, callback?: (exists: boolean) => void): void;
- export function existsSync(path: string | Buffer): boolean;
+ export function write(fd: number, string: any, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace write {
+ /**
+ * Asynchronously writes `buffer` to the file referenced by the supplied file descriptor.
+ * @param fd A file descriptor.
+ * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
+ * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
+ * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
+ */
+ export function __promisify__(fd: number, buffer?: TBuffer, offset?: number, length?: number, position?: number | null): Promise<{ bytesWritten: number, buffer: TBuffer }>;
+
+ /**
+ * Asynchronously writes `string` to the file referenced by the supplied file descriptor.
+ * @param fd A file descriptor.
+ * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
+ * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
+ * @param encoding The expected string encoding.
+ */
+ export function __promisify__(fd: number, string: any, position?: number | null, encoding?: string | null): Promise<{ bytesWritten: number, buffer: string }>;
+ }
+
+ /**
+ * Synchronously writes `buffer` to the file referenced by the supplied file descriptor, returning the number of bytes written.
+ * @param fd A file descriptor.
+ * @param offset The part of the buffer to be written. If not supplied, defaults to `0`.
+ * @param length The number of bytes to write. If not supplied, defaults to `buffer.length - offset`.
+ * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
+ */
+ export function writeSync(fd: number, buffer: Buffer | Uint8Array, offset?: number | null, length?: number | null, position?: number | null): number;
+
+ /**
+ * Synchronously writes `string` to the file referenced by the supplied file descriptor, returning the number of bytes written.
+ * @param fd A file descriptor.
+ * @param string A string to write. If something other than a string is supplied it will be coerced to a string.
+ * @param position The offset from the beginning of the file where this data should be written. If not supplied, defaults to the current position.
+ * @param encoding The expected string encoding.
+ */
+ export function writeSync(fd: number, string: any, position?: number | null, encoding?: string | null): number;
+
+ /**
+ * Asynchronously reads data from the file referenced by the supplied file descriptor.
+ * @param fd A file descriptor.
+ * @param buffer The buffer that the data will be written to.
+ * @param offset The offset in the buffer at which to start writing.
+ * @param length The number of bytes to read.
+ * @param position The offset from the beginning of the file from which data should be read. If `null`, data will be read from the current position.
+ */
+ export function read(fd: number, buffer: TBuffer, offset: number, length: number, position: number | null, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: TBuffer) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace read {
+ /**
+ * @param fd A file descriptor.
+ * @param buffer The buffer that the data will be written to.
+ * @param offset The offset in the buffer at which to start writing.
+ * @param length The number of bytes to read.
+ * @param position The offset from the beginning of the file from which data should be read. If `null`, data will be read from the current position.
+ */
+ export function __promisify__(fd: number, buffer: TBuffer, offset: number, length: number, position: number | null): Promise<{ bytesRead: number, buffer: TBuffer }>;
+ }
+
+ /**
+ * Synchronously reads data from the file referenced by the supplied file descriptor, returning the number of bytes read.
+ * @param fd A file descriptor.
+ * @param buffer The buffer that the data will be written to.
+ * @param offset The offset in the buffer at which to start writing.
+ * @param length The number of bytes to read.
+ * @param position The offset from the beginning of the file from which data should be read. If `null`, data will be read from the current position.
+ */
+ export function readSync(fd: number, buffer: Buffer | Uint8Array, offset: number, length: number, position: number | null): number;
+
+ /**
+ * Asynchronously reads the entire contents of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param options An object that may contain an optional flag.
+ * If a flag is not provided, it defaults to `'r'`.
+ */
+ export function readFile(path: PathLike | number, options: { encoding?: null; flag?: string; } | undefined | null, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void;
+
+ /**
+ * Asynchronously reads the entire contents of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
+ * If a flag is not provided, it defaults to `'r'`.
+ */
+ export function readFile(path: PathLike | number, options: { encoding: string; flag?: string; } | string, callback: (err: NodeJS.ErrnoException, data: string) => void): void;
+
+ /**
+ * Asynchronously reads the entire contents of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
+ * If a flag is not provided, it defaults to `'r'`.
+ */
+ export function readFile(path: PathLike | number, options: { encoding?: string | null; flag?: string; } | string | undefined | null, callback: (err: NodeJS.ErrnoException, data: string | Buffer) => void): void;
+
+ /**
+ * Asynchronously reads the entire contents of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ */
+ export function readFile(path: PathLike | number, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace readFile {
+ /**
+ * Asynchronously reads the entire contents of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param options An object that may contain an optional flag.
+ * If a flag is not provided, it defaults to `'r'`.
+ */
+ export function __promisify__(path: PathLike | number, options?: { encoding?: null; flag?: string; } | null): Promise;
+
+ /**
+ * Asynchronously reads the entire contents of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
+ * If a flag is not provided, it defaults to `'r'`.
+ */
+ export function __promisify__(path: PathLike | number, options: { encoding: string; flag?: string; } | string): Promise;
+
+ /**
+ * Asynchronously reads the entire contents of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
+ * If a flag is not provided, it defaults to `'r'`.
+ */
+ export function __promisify__(path: PathLike | number, options?: { encoding?: string | null; flag?: string; } | string | null): Promise;
+ }
+
+ /**
+ * Synchronously reads the entire contents of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param options An object that may contain an optional flag. If a flag is not provided, it defaults to `'r'`.
+ */
+ export function readFileSync(path: PathLike | number, options?: { encoding?: null; flag?: string; } | null): Buffer;
+
+ /**
+ * Synchronously reads the entire contents of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
+ * If a flag is not provided, it defaults to `'r'`.
+ */
+ export function readFileSync(path: PathLike | number, options: { encoding: string; flag?: string; } | string): string;
+
+ /**
+ * Synchronously reads the entire contents of a file.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
+ * If a flag is not provided, it defaults to `'r'`.
+ */
+ export function readFileSync(path: PathLike | number, options?: { encoding?: string | null; flag?: string; } | string | null): string | Buffer;
+
+ /**
+ * Asynchronously writes data to a file, replacing the file if it already exists.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
+ * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
+ * If `encoding` is not supplied, the default of `'utf8'` is used.
+ * If `mode` is not supplied, the default of `0o666` is used.
+ * If `mode` is a string, it is parsed as an octal integer.
+ * If `flag` is not supplied, the default of `'w'` is used.
+ */
+ export function writeFile(path: PathLike | number, data: any, options: { encoding?: string | null; mode?: number | string; flag?: string; } | string | undefined | null, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ /**
+ * Asynchronously writes data to a file, replacing the file if it already exists.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
+ */
+ export function writeFile(path: PathLike | number, data: any, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace writeFile {
+ /**
+ * Asynchronously writes data to a file, replacing the file if it already exists.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
+ * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
+ * If `encoding` is not supplied, the default of `'utf8'` is used.
+ * If `mode` is not supplied, the default of `0o666` is used.
+ * If `mode` is a string, it is parsed as an octal integer.
+ * If `flag` is not supplied, the default of `'w'` is used.
+ */
+ export function __promisify__(path: PathLike | number, data: any, options?: { encoding?: string | null; mode?: number | string; flag?: string; } | string | null): Promise;
+ }
+
+ /**
+ * Synchronously writes data to a file, replacing the file if it already exists.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
+ * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
+ * If `encoding` is not supplied, the default of `'utf8'` is used.
+ * If `mode` is not supplied, the default of `0o666` is used.
+ * If `mode` is a string, it is parsed as an octal integer.
+ * If `flag` is not supplied, the default of `'w'` is used.
+ */
+ export function writeFileSync(path: PathLike | number, data: any, options?: { encoding?: string | null; mode?: number | string; flag?: string; } | string | null): void;
+
+ /**
+ * Asynchronously append data to a file, creating the file if it does not exist.
+ * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
+ * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
+ * If `encoding` is not supplied, the default of `'utf8'` is used.
+ * If `mode` is not supplied, the default of `0o666` is used.
+ * If `mode` is a string, it is parsed as an octal integer.
+ * If `flag` is not supplied, the default of `'a'` is used.
+ */
+ export function appendFile(file: PathLike | number, data: any, options: { encoding?: string | null, mode?: string | number, flag?: string } | string | undefined | null, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ /**
+ * Asynchronously append data to a file, creating the file if it does not exist.
+ * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
+ */
+ export function appendFile(file: PathLike | number, data: any, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace appendFile {
+ /**
+ * Asynchronously append data to a file, creating the file if it does not exist.
+ * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
+ * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
+ * If `encoding` is not supplied, the default of `'utf8'` is used.
+ * If `mode` is not supplied, the default of `0o666` is used.
+ * If `mode` is a string, it is parsed as an octal integer.
+ * If `flag` is not supplied, the default of `'a'` is used.
+ */
+ export function __promisify__(file: PathLike | number, data: any, options?: { encoding?: string | null, mode?: string | number, flag?: string } | string | null): Promise;
+ }
+
+ /**
+ * Synchronously append data to a file, creating the file if it does not exist.
+ * @param file A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * If a file descriptor is provided, the underlying file will _not_ be closed automatically.
+ * @param data The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.
+ * @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
+ * If `encoding` is not supplied, the default of `'utf8'` is used.
+ * If `mode` is not supplied, the default of `0o666` is used.
+ * If `mode` is a string, it is parsed as an octal integer.
+ * If `flag` is not supplied, the default of `'a'` is used.
+ */
+ export function appendFileSync(file: PathLike | number, data: any, options?: { encoding?: string | null; mode?: number | string; flag?: string; } | string | null): void;
+
+ /**
+ * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
+ */
+ export function watchFile(filename: PathLike, options: { persistent?: boolean; interval?: number; } | undefined, listener: (curr: Stats, prev: Stats) => void): void;
+
+ /**
+ * Watch for changes on `filename`. The callback `listener` will be called each time the file is accessed.
+ * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function watchFile(filename: PathLike, listener: (curr: Stats, prev: Stats) => void): void;
+
+ /**
+ * Stop watching for changes on `filename`.
+ * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function unwatchFile(filename: PathLike, listener?: (curr: Stats, prev: Stats) => void): void;
+
+ /**
+ * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
+ * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
+ * If `encoding` is not supplied, the default of `'utf8'` is used.
+ * If `persistent` is not supplied, the default of `true` is used.
+ * If `recursive` is not supplied, the default of `false` is used.
+ */
+ export function watch(filename: PathLike, options: { encoding?: BufferEncoding | null, persistent?: boolean, recursive?: boolean } | BufferEncoding | undefined | null, listener?: (event: string, filename: string) => void): FSWatcher;
+
+ /**
+ * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
+ * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
+ * If `encoding` is not supplied, the default of `'utf8'` is used.
+ * If `persistent` is not supplied, the default of `true` is used.
+ * If `recursive` is not supplied, the default of `false` is used.
+ */
+ export function watch(filename: PathLike, options: { encoding: "buffer", persistent?: boolean, recursive?: boolean } | "buffer", listener?: (event: string, filename: Buffer) => void): FSWatcher;
+
+ /**
+ * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
+ * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ * @param options Either the encoding for the filename provided to the listener, or an object optionally specifying encoding, persistent, and recursive options.
+ * If `encoding` is not supplied, the default of `'utf8'` is used.
+ * If `persistent` is not supplied, the default of `true` is used.
+ * If `recursive` is not supplied, the default of `false` is used.
+ */
+ export function watch(filename: PathLike, options: { encoding?: string | null, persistent?: boolean, recursive?: boolean } | string | null, listener?: (event: string, filename: string | Buffer) => void): FSWatcher;
+
+ /**
+ * Watch for changes on `filename`, where `filename` is either a file or a directory, returning an `FSWatcher`.
+ * @param filename A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function watch(filename: PathLike, listener?: (event: string, filename: string) => any): FSWatcher;
+
+ /**
+ * Asynchronously tests whether or not the given path exists by checking with the file system.
+ * @deprecated
+ * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function exists(path: PathLike, callback: (exists: boolean) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace exists {
+ /**
+ * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ function __promisify__(path: PathLike): Promise;
+ }
+
+ /**
+ * Synchronously tests whether or not the given path exists by checking with the file system.
+ * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function existsSync(path: PathLike): boolean;
export namespace constants {
// File Access Constants
@@ -2697,12 +4130,43 @@ declare module "fs" {
export const S_IXOTH: number;
}
- /** Tests a user's permissions for the file specified by path. */
- export function access(path: string | Buffer, callback: (err: NodeJS.ErrnoException) => void): void;
- export function access(path: string | Buffer, mode: number, callback: (err: NodeJS.ErrnoException) => void): void;
- /** Synchronous version of fs.access. This throws if any accessibility checks fail, and does nothing otherwise. */
- export function accessSync(path: string | Buffer, mode?: number): void;
- export function createReadStream(path: string | Buffer, options?: {
+ /**
+ * Asynchronously tests a user's permissions for the file specified by path.
+ * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function access(path: PathLike, mode: number | undefined, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ /**
+ * Asynchronously tests a user's permissions for the file specified by path.
+ * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function access(path: PathLike, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace access {
+ /**
+ * Asynchronously tests a user's permissions for the file specified by path.
+ * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function __promisify__(path: PathLike, mode?: number): Promise;
+ }
+
+ /**
+ * Synchronously tests a user's permissions for the file specified by path.
+ * @param path A path to a file or directory. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function accessSync(path: PathLike, mode?: number): void;
+
+ /**
+ * Returns a new `ReadStream` object.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function createReadStream(path: PathLike, options?: string | {
flags?: string;
encoding?: string;
fd?: number;
@@ -2711,20 +4175,44 @@ declare module "fs" {
start?: number;
end?: number;
}): ReadStream;
- export function createWriteStream(path: string | Buffer, options?: {
+
+ /**
+ * Returns a new `WriteStream` object.
+ * @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
+ * URL support is _experimental_.
+ */
+ export function createWriteStream(path: PathLike, options?: string | {
flags?: string;
- encoding?: string;
+ defaultEncoding?: string;
fd?: number;
mode?: number;
autoClose?: boolean;
start?: number;
}): WriteStream;
- export function fdatasync(fd: number, callback: Function): void;
+
+ /**
+ * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
+ * @param fd A file descriptor.
+ */
+ export function fdatasync(fd: number, callback: (err: NodeJS.ErrnoException) => void): void;
+
+ // NOTE: This namespace provides design-time support for util.promisify. Exported members do not exist at runtime.
+ export namespace fdatasync {
+ /**
+ * Asynchronous fdatasync(2) - synchronize a file's in-core state with storage device.
+ * @param fd A file descriptor.
+ */
+ export function __promisify__(fd: number): Promise;
+ }
+
+ /**
+ * Synchronous fdatasync(2) - synchronize a file's in-core state with storage device.
+ * @param fd A file descriptor.
+ */
export function fdatasyncSync(fd: number): void;
}
declare module "path" {
-
/**
* A parsed path object generated by path.parse() or consumed by path.format().
*/
@@ -2868,7 +4356,7 @@ declare module "string_decoder" {
end(buffer?: Buffer): string;
}
export var StringDecoder: {
- new (encoding?: string): NodeStringDecoder;
+ new(encoding?: string): NodeStringDecoder;
};
}
@@ -2907,6 +4395,25 @@ declare module "tls" {
CN: string;
}
+ export interface PeerCertificate {
+ subject: Certificate;
+ issuer: Certificate;
+ subjectaltname: string;
+ infoAccess: { [index: string]: string[] | undefined };
+ modulus: string;
+ exponent: string;
+ valid_from: string;
+ valid_to: string;
+ fingerprint: string;
+ ext_key_usage: string[];
+ serialNumber: string;
+ raw: Buffer;
+ }
+
+ export interface DetailedPeerCertificate extends PeerCertificate {
+ issuerCertificate: DetailedPeerCertificate;
+ }
+
export interface CipherNameAndProtocol {
/**
* The cipher name.
@@ -2922,65 +4429,65 @@ declare module "tls" {
/**
* Construct a new tls.TLSSocket object from an existing TCP socket.
*/
- constructor(socket:net.Socket, options?: {
- /**
- * An optional TLS context object from tls.createSecureContext()
- */
- secureContext?: SecureContext,
- /**
- * If true the TLS socket will be instantiated in server-mode.
- * Defaults to false.
- */
- isServer?: boolean,
- /**
- * An optional net.Server instance.
- */
- server?: net.Server,
- /**
- * If true the server will request a certificate from clients that
- * connect and attempt to verify that certificate. Defaults to
- * false.
- */
- requestCert?: boolean,
- /**
- * If true the server will reject any connection which is not
- * authorized with the list of supplied CAs. This option only has an
- * effect if requestCert is true. Defaults to false.
- */
- rejectUnauthorized?: boolean,
- /**
- * An array of strings or a Buffer naming possible NPN protocols.
- * (Protocols should be ordered by their priority.)
- */
- NPNProtocols?: string[] | Buffer,
- /**
- * An array of strings or a Buffer naming possible ALPN protocols.
- * (Protocols should be ordered by their priority.) When the server
- * receives both NPN and ALPN extensions from the client, ALPN takes
- * precedence over NPN and the server does not send an NPN extension
- * to the client.
- */
- ALPNProtocols?: string[] | Buffer,
- /**
- * SNICallback(servername, cb) A function that will be
- * called if the client supports SNI TLS extension. Two arguments
- * will be passed when called: servername and cb. SNICallback should
- * invoke cb(null, ctx), where ctx is a SecureContext instance.
- * (tls.createSecureContext(...) can be used to get a proper
- * SecureContext.) If SNICallback wasn't provided the default callback
- * with high-level API will be used (see below).
- */
- SNICallback?: Function,
- /**
- * An optional Buffer instance containing a TLS session.
- */
- session?: Buffer,
- /**
- * If true, specifies that the OCSP status request extension will be
- * added to the client hello and an 'OCSPResponse' event will be
- * emitted on the socket before establishing a secure communication
- */
- requestOCSP?: boolean
+ constructor(socket: net.Socket, options?: {
+ /**
+ * An optional TLS context object from tls.createSecureContext()
+ */
+ secureContext?: SecureContext,
+ /**
+ * If true the TLS socket will be instantiated in server-mode.
+ * Defaults to false.
+ */
+ isServer?: boolean,
+ /**
+ * An optional net.Server instance.
+ */
+ server?: net.Server,
+ /**
+ * If true the server will request a certificate from clients that
+ * connect and attempt to verify that certificate. Defaults to
+ * false.
+ */
+ requestCert?: boolean,
+ /**
+ * If true the server will reject any connection which is not
+ * authorized with the list of supplied CAs. This option only has an
+ * effect if requestCert is true. Defaults to false.
+ */
+ rejectUnauthorized?: boolean,
+ /**
+ * An array of strings or a Buffer naming possible NPN protocols.
+ * (Protocols should be ordered by their priority.)
+ */
+ NPNProtocols?: string[] | Buffer,
+ /**
+ * An array of strings or a Buffer naming possible ALPN protocols.
+ * (Protocols should be ordered by their priority.) When the server
+ * receives both NPN and ALPN extensions from the client, ALPN takes
+ * precedence over NPN and the server does not send an NPN extension
+ * to the client.
+ */
+ ALPNProtocols?: string[] | Buffer,
+ /**
+ * SNICallback(servername, cb) A function that will be
+ * called if the client supports SNI TLS extension. Two arguments
+ * will be passed when called: servername and cb. SNICallback should
+ * invoke cb(null, ctx), where ctx is a SecureContext instance.
+ * (tls.createSecureContext(...) can be used to get a proper
+ * SecureContext.) If SNICallback wasn't provided the default callback
+ * with high-level API will be used (see below).
+ */
+ SNICallback?: Function,
+ /**
+ * An optional Buffer instance containing a TLS session.
+ */
+ session?: Buffer,
+ /**
+ * If true, specifies that the OCSP status request extension will be
+ * added to the client hello and an 'OCSPResponse' event will be
+ * emitted on the socket before establishing a secure communication
+ */
+ requestOCSP?: boolean
});
/**
* Returns the bound address, the address family name and port of the underlying socket as reported by
@@ -3015,18 +4522,11 @@ declare module "tls" {
* if false only the top certificate without issuer property.
* If the peer does not provide a certificate, it returns null or an empty object.
* @param {boolean} detailed - If true; the full chain with issuer property will be returned.
- * @returns {any} - An object representing the peer's certificate.
+ * @returns {PeerCertificate | DetailedPeerCertificate} - An object representing the peer's certificate.
*/
- getPeerCertificate(detailed?: boolean): {
- subject: Certificate;
- issuerInfo: Certificate;
- issuer: Certificate;
- raw: any;
- valid_from: string;
- valid_to: string;
- fingerprint: string;
- serialNumber: string;
- };
+ getPeerCertificate(detailed: true): DetailedPeerCertificate;
+ getPeerCertificate(detailed?: false): PeerCertificate;
+ getPeerCertificate(detailed?: boolean): PeerCertificate | DetailedPeerCertificate;
/**
* Could be used to speed up handshake establishment when reconnecting to the server.
* @returns {any} - ASN.1 encoded TLS session or undefined if none was negotiated.
@@ -3086,28 +4586,28 @@ declare module "tls" {
* events.EventEmitter
* 1. OCSPResponse
* 2. secureConnect
- **/
- addListener(event: string, listener: Function): this;
+ */
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "OCSPResponse", listener: (response: Buffer) => void): this;
addListener(event: "secureConnect", listener: () => void): this;
- emit(event: string, ...args: any[]): boolean;
+ emit(event: string | symbol, ...args: any[]): boolean;
emit(event: "OCSPResponse", response: Buffer): boolean;
emit(event: "secureConnect"): boolean;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "OCSPResponse", listener: (response: Buffer) => void): this;
on(event: "secureConnect", listener: () => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "OCSPResponse", listener: (response: Buffer) => void): this;
once(event: "secureConnect", listener: () => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "OCSPResponse", listener: (response: Buffer) => void): this;
prependListener(event: "secureConnect", listener: () => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "OCSPResponse", listener: (response: Buffer) => void): this;
prependOnceListener(event: "secureConnect", listener: () => void): this;
}
@@ -3141,17 +4641,17 @@ declare module "tls" {
host?: string;
port?: number;
socket?: net.Socket;
- pfx?: string | Buffer
+ pfx?: string | Buffer;
key?: string | string[] | Buffer | Buffer[];
passphrase?: string;
cert?: string | string[] | Buffer | Buffer[];
- ca?: string | Buffer | (string | Buffer)[];
+ ca?: string | Buffer | Array;
rejectUnauthorized?: boolean;
- NPNProtocols?: (string | Buffer)[];
+ NPNProtocols?: Array;
servername?: string;
path?: string;
- ALPNProtocols?: (string | Buffer)[];
- checkServerIdentity?: (servername: string, cert: string | Buffer | (string | Buffer)[]) => any;
+ ALPNProtocols?: Array;
+ checkServerIdentity?: (servername: string, cert: string | Buffer | Array) => any;
secureProtocol?: string;
secureContext?: Object;
session?: Buffer;
@@ -3176,43 +4676,43 @@ declare module "tls" {
* 3. OCSPRequest
* 4. resumeSession
* 5. secureConnection
- **/
- addListener(event: string, listener: Function): this;
+ */
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
addListener(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this;
addListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this;
addListener(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this;
addListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
- emit(event: string, ...args: any[]): boolean;
+ emit(event: string | symbol, ...args: any[]): boolean;
emit(event: "tlsClientError", err: Error, tlsSocket: TLSSocket): boolean;
emit(event: "newSession", sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void): boolean;
emit(event: "OCSPRequest", certificate: Buffer, issuer: Buffer, callback: Function): boolean;
emit(event: "resumeSession", sessionId: any, callback: (err: Error, sessionData: any) => void): boolean;
emit(event: "secureConnection", tlsSocket: TLSSocket): boolean;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
on(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this;
on(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this;
on(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this;
on(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
once(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this;
once(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this;
once(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this;
once(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
prependListener(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this;
prependListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this;
prependListener(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this;
prependListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this;
prependOnceListener(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this;
prependOnceListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this;
@@ -3248,7 +4748,7 @@ declare module "tls" {
passphrase?: string;
cert?: string | Buffer;
ca?: string | Buffer;
- crl?: string | string[]
+ crl?: string | string[];
ciphers?: string;
honorCipherOrder?: boolean;
}
@@ -3272,9 +4772,9 @@ declare module "crypto" {
verifySpkac(spkac: Buffer): boolean;
}
export var Certificate: {
- new (): Certificate;
+ new(): Certificate;
(): Certificate;
- }
+ };
export var fips: boolean;
@@ -3347,8 +4847,10 @@ declare module "crypto" {
export interface Verify extends NodeJS.WritableStream {
update(data: string | Buffer): Verify;
update(data: string | Buffer, input_encoding: Utf8AsciiLatin1Encoding): Verify;
- verify(object: string, signature: Buffer): boolean;
- verify(object: string, signature: string, signature_format: HexBase64Latin1Encoding): boolean;
+ verify(object: string | Object, signature: Buffer | DataView): boolean;
+ verify(object: string | Object, signature: string, signature_format: HexBase64Latin1Encoding): boolean;
+ // https://nodejs.org/api/crypto.html#crypto_verifier_verify_object_signature_signature_format
+ // The signature field accepts a TypedArray type, but it is only available starting ES2017
}
export function createDiffieHellman(prime_length: number, generator?: number): DiffieHellman;
export function createDiffieHellman(prime: Buffer): DiffieHellman;
@@ -3382,19 +4884,26 @@ declare module "crypto" {
export function randomBytes(size: number, callback: (err: Error, buf: Buffer) => void): void;
export function pseudoRandomBytes(size: number): Buffer;
export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) => void): void;
+ export function randomFillSync(buffer: Buffer | Uint8Array, offset?: number, size?: number): Buffer;
+ export function randomFill(buffer: Buffer, callback: (err: Error, buf: Buffer) => void): void;
+ export function randomFill(buffer: Uint8Array, callback: (err: Error, buf: Uint8Array) => void): void;
+ export function randomFill(buffer: Buffer, offset: number, callback: (err: Error, buf: Buffer) => void): void;
+ export function randomFill(buffer: Uint8Array, offset: number, callback: (err: Error, buf: Uint8Array) => void): void;
+ export function randomFill(buffer: Buffer, offset: number, size: number, callback: (err: Error, buf: Buffer) => void): void;
+ export function randomFill(buffer: Uint8Array, offset: number, size: number, callback: (err: Error, buf: Uint8Array) => void): void;
export interface RsaPublicKey {
key: string;
padding?: number;
}
export interface RsaPrivateKey {
key: string;
- passphrase?: string,
+ passphrase?: string;
padding?: number;
}
- export function publicEncrypt(public_key: string | RsaPublicKey, buffer: Buffer): Buffer
- export function privateDecrypt(private_key: string | RsaPrivateKey, buffer: Buffer): Buffer
- export function privateEncrypt(private_key: string | RsaPrivateKey, buffer: Buffer): Buffer
- export function publicDecrypt(public_key: string | RsaPublicKey, buffer: Buffer): Buffer
+ export function publicEncrypt(public_key: string | RsaPublicKey, buffer: Buffer): Buffer;
+ export function privateDecrypt(private_key: string | RsaPrivateKey, buffer: Buffer): Buffer;
+ export function privateEncrypt(private_key: string | RsaPrivateKey, buffer: Buffer): Buffer;
+ export function publicDecrypt(public_key: string | RsaPublicKey, buffer: Buffer): Buffer;
export function getCiphers(): string[];
export function getCurves(): string[];
export function getHashes(): string[];
@@ -3424,21 +4933,22 @@ declare module "stream" {
class internal extends events.EventEmitter {
pipe(destination: T, options?: { end?: boolean; }): T;
}
- namespace internal {
+ namespace internal {
export class Stream extends internal { }
export interface ReadableOptions {
highWaterMark?: number;
encoding?: string;
objectMode?: boolean;
- read?: (size?: number) => any;
+ read?: (this: Readable, size?: number) => any;
+ destroy?: (error?: Error) => any;
}
- export class Readable extends events.EventEmitter implements NodeJS.ReadableStream {
+ export class Readable extends Stream implements NodeJS.ReadableStream {
readable: boolean;
constructor(opts?: ReadableOptions);
- protected _read(size: number): void;
+ _read(size: number): void;
read(size?: number): any;
setEncoding(encoding: string): this;
pause(): this;
@@ -3447,62 +4957,63 @@ declare module "stream" {
pipe(destination: T, options?: { end?: boolean; }): T;
unpipe(destination?: T): this;
unshift(chunk: any): void;
- wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
+ wrap(oldStream: NodeJS.ReadableStream): Readable;
push(chunk: any, encoding?: string): boolean;
+ destroy(error?: Error): void;
/**
* Event emitter
* The defined events on documents including:
- * 1. close
- * 2. data
- * 3. end
- * 4. readable
- * 5. error
- **/
- addListener(event: string, listener: Function): this;
- addListener(event: string, listener: Function): this;
+ * 1. close
+ * 2. data
+ * 3. end
+ * 4. readable
+ * 5. error
+ */
+ addListener(event: string, listener: (...args: any[]) => void): this;
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "close", listener: () => void): this;
addListener(event: "data", listener: (chunk: Buffer | string) => void): this;
addListener(event: "end", listener: () => void): this;
addListener(event: "readable", listener: () => void): this;
addListener(event: "error", listener: (err: Error) => void): this;
- emit(event: string, ...args: any[]): boolean;
+ emit(event: string | symbol, ...args: any[]): boolean;
emit(event: "close"): boolean;
emit(event: "data", chunk: Buffer | string): boolean;
emit(event: "end"): boolean;
emit(event: "readable"): boolean;
emit(event: "error", err: Error): boolean;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "close", listener: () => void): this;
on(event: "data", listener: (chunk: Buffer | string) => void): this;
on(event: "end", listener: () => void): this;
on(event: "readable", listener: () => void): this;
on(event: "error", listener: (err: Error) => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "close", listener: () => void): this;
once(event: "data", listener: (chunk: Buffer | string) => void): this;
once(event: "end", listener: () => void): this;
once(event: "readable", listener: () => void): this;
once(event: "error", listener: (err: Error) => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "close", listener: () => void): this;
prependListener(event: "data", listener: (chunk: Buffer | string) => void): this;
prependListener(event: "end", listener: () => void): this;
prependListener(event: "readable", listener: () => void): this;
prependListener(event: "error", listener: (err: Error) => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "close", listener: () => void): this;
prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this;
prependOnceListener(event: "end", listener: () => void): this;
prependOnceListener(event: "readable", listener: () => void): this;
prependOnceListener(event: "error", listener: (err: Error) => void): this;
- removeListener(event: string, listener: Function): this;
+ removeListener(event: string, listener: (...args: any[]) => void): this;
removeListener(event: "close", listener: () => void): this;
removeListener(event: "data", listener: (chunk: Buffer | string) => void): this;
removeListener(event: "end", listener: () => void): this;
@@ -3515,30 +5026,37 @@ declare module "stream" {
decodeStrings?: boolean;
objectMode?: boolean;
write?: (chunk: string | Buffer, encoding: string, callback: Function) => any;
- writev?: (chunks: { chunk: string | Buffer, encoding: string }[], callback: Function) => any;
+ writev?: (chunks: Array<{ chunk: string | Buffer, encoding: string }>, callback: Function) => any;
+ destroy?: (error?: Error) => any;
}
- export class Writable extends events.EventEmitter implements NodeJS.WritableStream {
+ export class Writable extends Stream implements NodeJS.WritableStream {
writable: boolean;
constructor(opts?: WritableOptions);
- protected _write(chunk: any, encoding: string, callback: Function): void;
+ _write(chunk: any, encoding: string, callback: Function): void;
+ _destroy(err: Error, callback: Function): void;
+ _final(callback: Function): void;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
+ setDefaultEncoding(encoding: string): this;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
+ cork(): void;
+ uncork(): void;
+ destroy(error?: Error): void;
/**
* Event emitter
* The defined events on documents including:
- * 1. close
- * 2. drain
- * 3. error
- * 4. finish
- * 5. pipe
- * 6. unpipe
- **/
- addListener(event: string, listener: Function): this;
+ * 1. close
+ * 2. drain
+ * 3. error
+ * 4. finish
+ * 5. pipe
+ * 6. unpipe
+ */
+ addListener(event: string, listener: (...args: any[]) => void): this;
addListener(event: "close", listener: () => void): this;
addListener(event: "drain", listener: () => void): this;
addListener(event: "error", listener: (err: Error) => void): this;
@@ -3546,7 +5064,7 @@ declare module "stream" {
addListener(event: "pipe", listener: (src: Readable) => void): this;
addListener(event: "unpipe", listener: (src: Readable) => void): this;
- emit(event: string, ...args: any[]): boolean;
+ emit(event: string | symbol, ...args: any[]): boolean;
emit(event: "close"): boolean;
emit(event: "drain", chunk: Buffer | string): boolean;
emit(event: "error", err: Error): boolean;
@@ -3554,7 +5072,7 @@ declare module "stream" {
emit(event: "pipe", src: Readable): boolean;
emit(event: "unpipe", src: Readable): boolean;
- on(event: string, listener: Function): this;
+ on(event: string, listener: (...args: any[]) => void): this;
on(event: "close", listener: () => void): this;
on(event: "drain", listener: () => void): this;
on(event: "error", listener: (err: Error) => void): this;
@@ -3562,7 +5080,7 @@ declare module "stream" {
on(event: "pipe", listener: (src: Readable) => void): this;
on(event: "unpipe", listener: (src: Readable) => void): this;
- once(event: string, listener: Function): this;
+ once(event: string, listener: (...args: any[]) => void): this;
once(event: "close", listener: () => void): this;
once(event: "drain", listener: () => void): this;
once(event: "error", listener: (err: Error) => void): this;
@@ -3570,7 +5088,7 @@ declare module "stream" {
once(event: "pipe", listener: (src: Readable) => void): this;
once(event: "unpipe", listener: (src: Readable) => void): this;
- prependListener(event: string, listener: Function): this;
+ prependListener(event: string, listener: (...args: any[]) => void): this;
prependListener(event: "close", listener: () => void): this;
prependListener(event: "drain", listener: () => void): this;
prependListener(event: "error", listener: (err: Error) => void): this;
@@ -3578,7 +5096,7 @@ declare module "stream" {
prependListener(event: "pipe", listener: (src: Readable) => void): this;
prependListener(event: "unpipe", listener: (src: Readable) => void): this;
- prependOnceListener(event: string, listener: Function): this;
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
prependOnceListener(event: "close", listener: () => void): this;
prependOnceListener(event: "drain", listener: () => void): this;
prependOnceListener(event: "error", listener: (err: Error) => void): this;
@@ -3586,7 +5104,7 @@ declare module "stream" {
prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
- removeListener(event: string, listener: Function): this;
+ removeListener(event: string, listener: (...args: any[]) => void): this;
removeListener(event: "close", listener: () => void): this;
removeListener(event: "drain", listener: () => void): this;
removeListener(event: "error", listener: (err: Error) => void): this;
@@ -3602,19 +5120,20 @@ declare module "stream" {
}
// Note: Duplex extends both Readable and Writable.
- export class Duplex extends Readable implements NodeJS.ReadWriteStream {
- // Readable
- pause(): this;
- resume(): this;
- // Writeable
+ export class Duplex extends Readable implements Writable {
writable: boolean;
constructor(opts?: DuplexOptions);
- protected _write(chunk: any, encoding: string, callback: Function): void;
+ _write(chunk: any, encoding: string, callback: Function): void;
+ _destroy(err: Error, callback: Function): void;
+ _final(callback: Function): void;
write(chunk: any, cb?: Function): boolean;
write(chunk: any, encoding?: string, cb?: Function): boolean;
+ setDefaultEncoding(encoding: string): this;
end(): void;
end(chunk: any, cb?: Function): void;
end(chunk: any, encoding?: string, cb?: Function): void;
+ cork(): void;
+ uncork(): void;
}
export interface TransformOptions extends DuplexOptions {
@@ -3622,28 +5141,10 @@ declare module "stream" {
flush?: (callback: Function) => any;
}
- // Note: Transform lacks the _read and _write methods of Readable/Writable.
- export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream {
- readable: boolean;
- writable: boolean;
+ export class Transform extends Duplex {
constructor(opts?: TransformOptions);
- protected _transform(chunk: any, encoding: string, callback: Function): void;
- protected _flush(callback: Function): void;
- read(size?: number): any;
- setEncoding(encoding: string): this;
- pause(): this;
- resume(): this;
- isPaused(): boolean;
- pipe(destination: T, options?: { end?: boolean; }): T;
- unpipe(destination?: T): this;
- unshift(chunk: any): void;
- wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream;
- push(chunk: any, encoding?: string): boolean;
- write(chunk: any, cb?: Function): boolean;
- write(chunk: any, encoding?: string, cb?: Function): boolean;
- end(): void;
- end(chunk: any, cb?: Function): void;
- end(chunk: any, encoding?: string, cb?: Function): void;
+ _transform(chunk: any, encoding: string, callback: Function): void;
+ destroy(error?: Error): void;
}
export class PassThrough extends Transform { }
@@ -3653,39 +5154,63 @@ declare module "stream" {
}
declare module "util" {
- export interface InspectOptions {
- showHidden?: boolean;
- depth?: number;
- colors?: boolean;
- customInspect?: boolean;
- }
-
+ export interface InspectOptions extends NodeJS.InspectOptions { }
export function format(format: any, ...param: any[]): string;
export function debug(string: string): void;
export function error(...param: any[]): void;
export function puts(...param: any[]): void;
export function print(...param: any[]): void;
export function log(string: string): void;
- export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string;
- export function inspect(object: any, options: InspectOptions): string;
- export function isArray(object: any): boolean;
- export function isRegExp(object: any): boolean;
- export function isDate(object: any): boolean;
- export function isError(object: any): boolean;
+ export var inspect: {
+ (object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string;
+ (object: any, options: InspectOptions): string;
+ colors: {
+ [color: string]: [number, number] | undefined
+ }
+ styles: {
+ [style: string]: string | undefined
+ }
+ defaultOptions: InspectOptions;
+ custom: symbol;
+ };
+ export function isArray(object: any): object is any[];
+ export function isRegExp(object: any): object is RegExp;
+ export function isDate(object: any): object is Date;
+ export function isError(object: any): object is Error;
export function inherits(constructor: any, superConstructor: any): void;
export function debuglog(key: string): (msg: string, ...param: any[]) => void;
- export function isBoolean(object: any): boolean;
- export function isBuffer(object: any): boolean;
+ export function isBoolean(object: any): object is boolean;
+ export function isBuffer(object: any): object is Buffer;
export function isFunction(object: any): boolean;
- export function isNull(object: any): boolean;
- export function isNullOrUndefined(object: any): boolean;
- export function isNumber(object: any): boolean;
+ export function isNull(object: any): object is null;
+ export function isNullOrUndefined(object: any): object is null | undefined;
+ export function isNumber(object: any): object is number;
export function isObject(object: any): boolean;
export function isPrimitive(object: any): boolean;
- export function isString(object: any): boolean;
- export function isSymbol(object: any): boolean;
- export function isUndefined(object: any): boolean;
+ export function isString(object: any): object is string;
+ export function isSymbol(object: any): object is symbol;
+ export function isUndefined(object: any): object is undefined;
export function deprecate(fn: Function, message: string): Function;
+
+ export interface CustomPromisify extends Function {
+ __promisify__: TCustom;
+ }
+
+ export function promisify(fn: CustomPromisify): TCustom;
+ export function promisify(fn: (arg1: T1, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void): (arg1: T1) => Promise;
+ export function promisify(fn: (arg1: T1, callback: (err: NodeJS.ErrnoException) => void) => void): (arg1: T1) => Promise;
+ export function promisify(fn: (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void): (arg1: T1, arg2: T2) => Promise;
+ export function promisify(fn: (arg1: T1, arg2: T2, callback: (err: NodeJS.ErrnoException) => void) => void): (arg1: T1, arg2: T2) => Promise;
+ export function promisify(fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void): (arg1: T1, arg2: T2, arg3: T3) => Promise;
+ export function promisify(fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err: NodeJS.ErrnoException) => void) => void): (arg1: T1, arg2: T2, arg3: T3) => Promise;
+ export function promisify(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise;
+ export function promisify(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: NodeJS.ErrnoException) => void) => void): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise;
+ export function promisify(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException, result: TResult) => void) => void): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise;
+ export function promisify(fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: NodeJS.ErrnoException) => void) => void): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise;
+ export function promisify(fn: Function): Function;
+ export namespace promisify {
+ const custom: symbol;
+ }
}
declare module "assert" {
@@ -3705,7 +5230,8 @@ declare module "assert" {
});
}
- export function fail(actual: any, expected: any, message: string, operator: string): void;
+ export function fail(message: string): void;
+ export function fail(actual: any, expected: any, message?: string, operator?: string): void;
export function ok(value: any, message?: string): void;
export function equal(actual: any, expected: any, message?: string): void;
export function notEqual(actual: any, expected: any, message?: string): void;
@@ -3715,19 +5241,16 @@ declare module "assert" {
export function notStrictEqual(actual: any, expected: any, message?: string): void;
export function deepStrictEqual(actual: any, expected: any, message?: string): void;
export function notDeepStrictEqual(actual: any, expected: any, message?: string): void;
- export var throws: {
- (block: Function, message?: string): void;
- (block: Function, error: Function, message?: string): void;
- (block: Function, error: RegExp, message?: string): void;
- (block: Function, error: (err: any) => boolean, message?: string): void;
- };
- export var doesNotThrow: {
- (block: Function, message?: string): void;
- (block: Function, error: Function, message?: string): void;
- (block: Function, error: RegExp, message?: string): void;
- (block: Function, error: (err: any) => boolean, message?: string): void;
- };
+ export function throws(block: Function, message?: string): void;
+ export function throws(block: Function, error: Function, message?: string): void;
+ export function throws(block: Function, error: RegExp, message?: string): void;
+ export function throws(block: Function, error: (err: any) => boolean, message?: string): void;
+
+ export function doesNotThrow(block: Function, message?: string): void;
+ export function doesNotThrow(block: Function, error: Function, message?: string): void;
+ export function doesNotThrow(block: Function, error: RegExp, message?: string): void;
+ export function doesNotThrow(block: Function, error: (err: any) => boolean, message?: string): void;
export function ifError(value: any): void;
}
@@ -4058,7 +5581,7 @@ declare module "v8" {
physical_space_size: number;
}
- //** Signifies if the --zap_code_space option is enabled or not. 1 == enabled, 0 == disabled. */
+ // ** Signifies if the --zap_code_space option is enabled or not. 1 == enabled, 0 == disabled. */
type DoesZapCodeSpaceFlag = 0 | 1;
interface HeapInfo {
@@ -4213,7 +5736,75 @@ declare module "_debugger" {
reqContinue(cb: RequestHandler): void;
}
- export var Client : {
- new (): ClientInstance
- }
+ export var Client: {
+ new(): ClientInstance
+ };
+}
+
+/**
+ * Async Hooks module: https://nodejs.org/api/async_hooks.html
+ */
+declare module "async_hooks" {
+ /**
+ * Returns the asyncId of the current execution context.
+ */
+ export function executionAsyncId(): number;
+ /// @deprecated - replaced by executionAsyncId()
+ export function currentId(): number;
+
+ /**
+ * Returns the ID of the resource responsible for calling the callback that is currently being executed.
+ */
+ export function triggerAsyncId(): number;
+ /// @deprecated - replaced by triggerAsyncId()
+ export function triggerId(): number;
+
+ export interface HookCallbacks {
+ /**
+ * Called when a class is constructed that has the possibility to emit an asynchronous event.
+ * @param asyncId a unique ID for the async resource
+ * @param type the type of the async resource
+ * @param triggerAsyncId the unique ID of the async resource in whose execution context this async resource was created
+ * @param resource reference to the resource representing the async operation, needs to be released during destroy
+ */
+ init?(asyncId: number, type: string, triggerAsyncId: number, resource: Object): void;
+
+ /**
+ * When an asynchronous operation is initiated or completes a callback is called to notify the user.
+ * The before callback is called just before said callback is executed.
+ * @param asyncId the unique identifier assigned to the resource about to execute the callback.
+ */
+ before?(asyncId: number): void;
+
+ /**
+ * Called immediately after the callback specified in before is completed.
+ * @param asyncId the unique identifier assigned to the resource which has executed the callback.
+ */
+ after?(asyncId: number): void;
+
+ /**
+ * Called after the resource corresponding to asyncId is destroyed
+ * @param asyncId a unique ID for the async resource
+ */
+ destroy?(asyncId: number): void;
+ }
+
+ export interface AsyncHook {
+ /**
+ * Enable the callbacks for a given AsyncHook instance. If no callbacks are provided enabling is a noop.
+ */
+ enable(): this;
+
+ /**
+ * Disable the callbacks for a given AsyncHook instance from the global pool of AsyncHook callbacks to be executed. Once a hook has been disabled it will not be called again until enabled.
+ */
+ disable(): this;
+ }
+
+ /**
+ * Registers functions to be called for different lifetime events of each async operation.
+ * @param options the callbacks to register
+ * @return an AsyncHooks instance used for disabling and enabling hooks
+ */
+ export function createHook(options: HookCallbacks): AsyncHook;
}
diff --git a/node_modules/@types/node/package.json b/node_modules/@types/node/package.json
new file mode 100644
index 0000000..9c33837
--- /dev/null
+++ b/node_modules/@types/node/package.json
@@ -0,0 +1,96 @@
+{
+ "_from": "@types/node@^8.0.7",
+ "_id": "@types/node@8.0.20",
+ "_inBundle": false,
+ "_integrity": "sha512-MnB7YEpmLUyEWRVRhKpRs4swwqITnY8BcVFPoTuCl99SCplI/lLUiU5vcJ/OANDqwkpdIg0pDEM38K22KQT2RA==",
+ "_location": "/@types/node",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "@types/node@^8.0.7",
+ "name": "@types/node",
+ "escapedName": "@types%2fnode",
+ "scope": "@types",
+ "rawSpec": "^8.0.7",
+ "saveSpec": null,
+ "fetchSpec": "^8.0.7"
+ },
+ "_requiredBy": [
+ "#DEV:/"
+ ],
+ "_resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.20.tgz",
+ "_shasum": "65c7375255c24b184c215a5d0b63247c32f01c91",
+ "_spec": "@types/node@^8.0.7",
+ "_where": "/home/sinclair/Desktop/typebox-upgrade",
+ "bundleDependencies": false,
+ "contributors": [
+ {
+ "name": "Microsoft TypeScript",
+ "url": "http://typescriptlang.org"
+ },
+ {
+ "name": "DefinitelyTyped",
+ "url": "https://github.com/DefinitelyTyped/DefinitelyTyped"
+ },
+ {
+ "name": "Parambir Singh",
+ "url": "https://github.com/parambirs"
+ },
+ {
+ "name": "Roberto Desideri",
+ "url": "https://github.com/RobDesideri"
+ },
+ {
+ "name": "Christian Vaagland Tellnes",
+ "url": "https://github.com/tellnes"
+ },
+ {
+ "name": "Wilco Bakker",
+ "url": "https://github.com/WilcoBakker"
+ },
+ {
+ "name": "Nicolas Voigt",
+ "url": "https://github.com/octo-sniffle"
+ },
+ {
+ "name": "Chigozirim C.",
+ "url": "https://github.com/smac89"
+ },
+ {
+ "name": "Flarna",
+ "url": "https://github.com/Flarna"
+ },
+ {
+ "name": "Mariusz Wiktorczyk",
+ "url": "https://github.com/mwiktorczyk"
+ },
+ {
+ "name": "wwwy3y3",
+ "url": "https://github.com/wwwy3y3"
+ },
+ {
+ "name": "Daniel Imms",
+ "url": "https://github.com/Tyriar"
+ },
+ {
+ "name": "Deividas Bakanas",
+ "url": "https://github.com/DeividasBakanas"
+ }
+ ],
+ "dependencies": {},
+ "deprecated": false,
+ "description": "TypeScript definitions for Node.js",
+ "license": "MIT",
+ "main": "",
+ "name": "@types/node",
+ "peerDependencies": {},
+ "repository": {
+ "type": "git",
+ "url": "https://www.github.com/DefinitelyTyped/DefinitelyTyped.git"
+ },
+ "scripts": {},
+ "typeScriptVersion": "2.2",
+ "typesPublisherContentHash": "7fe73090c10b2c90f6acb01b83f3f55735b274b2fa9b95a0a2feade8f3cfc16b",
+ "version": "8.0.20"
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..a397cec
--- /dev/null
+++ b/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "typebox",
+ "version": "0.9.0",
+ "description": "A runtime type system for javascript.",
+ "main": "./target/index.js",
+ "test": "node ./target/test.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/sinclairzx81/typebox"
+ },
+ "author": "sinclairzx81",
+ "license": "MIT",
+ "devDependencies": {
+ "@types/mocha": "^2.2.41",
+ "@types/node": "^8.0.7"
+ }
+}
diff --git a/readme.md b/readme.md
index 910d7a8..daab764 100644
--- a/readme.md
+++ b/readme.md
@@ -3,7 +3,7 @@
A runtime type system for javascript.
```javascript
-const Customer = typebox.Object({
+const Customer = typebox.Complex({
firstname: typebox.String(),
lastname : typebox.String(),
email : typebox.String(),
@@ -34,7 +34,7 @@ type | typescript | typebox
Any | ```type T = any``` | ```const T = typebox.Any()``` |
Null | ```type T = null``` | ```const T = typebox.Null()``` |
Undefined | ```type T = undefined``` | ```const T = typebox.Undefined()``` |
-Object | ```type T = {name: string}``` | ```const T = typebox.Object({name: typebox.String()})``` |
+Complex | ```type T = {name: string}``` | ```const T = typebox.Complex({name: typebox.String()})``` |
Array | ```type T = number[]``` | ```const T = typebox.Array(typebox.String())``` |
Tuple | ```type T = [string, number]``` | ```const T = typebox.Tuple(typebox.String(), typebox.Number())``` |
Number | ```type T = number``` | ```const T = typebox.Number()``` |
@@ -48,7 +48,7 @@ Literal | ```type T = "click"``` | ```const T = typebox
Once a type is created, an object can be type checked against it by calling the ```typebox.check(...)``` method.
```javascript
-const Ship = typebox.Object({
+const Ship = typebox.Complex({
pilot : typebox.String(),
position : typebox.Tuple(
typebox.Number(),
@@ -69,7 +69,7 @@ let result = typebox.check(Ship, {
The ```typebox.check(...)``` function returns a type check result object. Callers can inspect this result with.
```javascript
-const Ship = typebox.Object({
+const Ship = typebox.Complex({
pilot : typebox.String(),
position : typebox.Tuple(
typebox.Number(),
@@ -130,7 +130,7 @@ note: static type resolution has been tested with TypeScript version 2.2.2 and i
```typescript
// typebox type.
-const User = typebox.Object({
+const User = typebox.Complex({
name : typebox.String(),
email : typebox.String(),
roles : typebox.Array(typebox.String()),
@@ -150,7 +150,7 @@ typebox provides functionality to generate draft-4 compatiable JSONschema from t
to be shared to JSONSchema compatible user.
```javascript
-const Ship = typebox.Object({
+const Ship = typebox.Complex({
pilot : typebox.String(),
position : typebox.Tuple(
typebox.Number(),
diff --git a/src/check.ts b/src/check.ts
index 406dd8a..4362f10 100644
--- a/src/check.ts
+++ b/src/check.ts
@@ -27,96 +27,96 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/
import { reflect } from "./reflect"
-import * as spec from "./spec"
+import * as spec from "./spec"
/**
* TypeCheckError: encapsulates a type check error.
*/
export interface TypeCheckError {
- binding: string
- message: string
- expect: string
- actual: string
+ binding: string
+ message: string
+ expect : string
+ actual : string
}
/**
* TypeCheckResult: encapsulates a type check result.
*/
export interface TypeCheckResult {
- success: boolean
- errors: Array
+ success: boolean
+ errors : Array
}
/**
* creates a successful typecheck result.
*/
function Ok(): TypeCheckResult {
- return {
- success: true,
- errors: []
- }
+ return {
+ success: true,
+ errors : []
+ }
}
/**
* creates a failed typecheck result.
*/
function FailBinding(binding: string, expect: string, actual: string): TypeCheckResult {
- return {
- success: false,
- errors: [{
- binding: binding,
- message: `Type '${actual}' is not assignable to type '${expect}'`,
- expect : expect,
- actual : actual
- }]
- }
+ return {
+ success: false,
+ errors: [{
+ binding: binding,
+ message: `Type '${actual}' is not assignable to type '${expect}'`,
+ expect : expect,
+ actual : actual
+ }]
+ }
}
/**
* creates a failed typecheck result.
*/
function FailRequired(binding: string, expect: string, actual: string): TypeCheckResult {
- return {
- success: false,
- errors: [{
- binding: binding,
- message: `Property of type '${expect}' is required`,
- expect : expect,
- actual : actual
- }]
- }
+ return {
+ success: false,
+ errors: [{
+ binding: binding,
+ message: `Property of type '${expect}' is required`,
+ expect : expect,
+ actual : actual
+ }]
+ }
}
/**
* creates a failed typecheck result.
*/
function FailLengthMismatch(binding: string, expect: string, actual: string, expect_length: number, actual_length: number): TypeCheckResult {
- return {
- success: false,
- errors: [{
- binding: binding,
- message: `Property of type '${actual}' with a length ${actual_length} is invalid. Expect length of ${expect_length}`,
- expect : expect,
- actual : actual
- }]
- }
+ return {
+ success: false,
+ errors: [{
+ binding: binding,
+ message: `Property of type '${actual}' with a length ${actual_length} is invalid. Expect length of ${expect_length}`,
+ expect : expect,
+ actual : actual
+ }]
+ }
}
/**
* creates a failed typecheck result.
*/
function FailUnexpected(binding: string, expect: string, actual: string): TypeCheckResult {
- let parts = binding.split(".")
- let property = parts[parts.length - 1]
- return {
- success: false,
- errors: [{
- binding: binding,
- message: `Property of type '${actual}' is not valid for this object`,
- expect : expect,
- actual : actual
- }]
- }
+ const parts = binding.split(".")
+ const property = parts[parts.length - 1]
+ return {
+ success: false,
+ errors: [{
+ binding: binding,
+ message: `Property of type '${actual}' is not valid for this object`,
+ expect: expect,
+ actual: actual
+ }]
+ }
}
/**
@@ -127,7 +127,7 @@ function FailUnexpected(binding: string, expect: string, actual: string): TypeCh
* @returns {TypeCheckResult}
*/
function check_Any(type: spec.TAny, name: string, value: any): TypeCheckResult {
- return Ok()
+ return Ok()
}
/**
@@ -138,10 +138,10 @@ function check_Any(type: spec.TAny, name: string, value: any): TypeCheckResult {
* @returns {TypeCheckResult}
*/
function check_Undefined(type: spec.TUndefined, name: string, value: any): TypeCheckResult {
- let kind = reflect(value)
- return (kind !== "undefined")
- ? FailBinding(name, type.kind, kind)
- : Ok()
+ const kind = reflect(value)
+ return (kind !== "undefined")
+ ? FailBinding(name, type.kind, kind)
+ : Ok()
}
/**
@@ -152,12 +152,11 @@ function check_Undefined(type: spec.TUndefined, name: string, value: any): TypeC
* @returns {TypeCheckResult}
*/
function check_Null(type: spec.TNull, name: string, value: any): TypeCheckResult {
- let kind = reflect(value)
- return (kind !== "null")
- ? FailBinding(name, type.kind, kind)
- : Ok()
+ const kind = reflect(value)
+ return (kind !== "null")
+ ? FailBinding(name, type.kind, kind)
+ : Ok()
}
-
/**
* validates the given value against the given TLiteral type.
* @param {TLiteral} type the type.
@@ -166,17 +165,16 @@ function check_Null(type: spec.TNull, name: string, value: any): TypeCheckResult
* @returns {TypeCheckResult}
*/
function check_Literal(type: spec.TLiteral, name: string, value: any): TypeCheckResult {
- let actual = reflect(value)
- let expect = reflect(type.value)
- if (actual !== expect) {
- return FailBinding(name, expect, actual)
- } else if (type.value !== value) {
- return FailBinding(name, type.value as string, actual)
- } else {
- return Ok()
- }
+ const actual = reflect(value)
+ const expect = reflect(type.value)
+ if (actual !== expect) {
+ return FailBinding(name, expect, actual)
+ } else if (type.value !== value) {
+ return FailBinding(name, type.value as string, actual)
+ } else {
+ return Ok()
+ }
}
-
/**
* validates the given value against the given TString type.
* @param {TString} type the type.
@@ -185,10 +183,10 @@ function check_Literal(type: spec.TLiteral, name: string, val
* @returns {TypeCheckResult}
*/
function check_String(type: spec.TString, name: string, value: any): TypeCheckResult {
- let kind = reflect(value)
- return (kind !== "string")
- ? FailBinding(name, type.kind, kind)
- : Ok()
+ const kind = reflect(value)
+ return (kind !== "string")
+ ? FailBinding(name, type.kind, kind)
+ : Ok()
}
/**
* validates the given value against the given TNumber type.
@@ -198,10 +196,10 @@ function check_String(type: spec.TString, name: string, value: any): TypeCheckRe
* @returns {TypeCheckResult}
*/
function check_Number(type: spec.TNumber, name: string, value: any): TypeCheckResult {
- let kind = reflect(value)
- return (kind !== "number")
- ? FailBinding(name, type.kind, kind)
- : Ok()
+ const kind = reflect(value)
+ return (kind !== "number")
+ ? FailBinding(name, type.kind, kind)
+ : Ok()
}
/**
* validates the given value against the given TBoolean type.
@@ -211,10 +209,10 @@ function check_Number(type: spec.TNumber, name: string, value: any): TypeCheckRe
* @returns {TypeCheckResult}
*/
function check_Boolean(type: spec.TBoolean, name: string, value: any): TypeCheckResult {
- let kind = reflect(value)
- return (kind !== "boolean")
- ? FailBinding(name, type.kind, kind)
- : Ok()
+ const kind = reflect(value)
+ return (kind !== "boolean")
+ ? FailBinding(name, type.kind, kind)
+ : Ok()
}
/**
@@ -224,48 +222,48 @@ function check_Boolean(type: spec.TBoolean, name: string, value: any): TypeCheck
* @param {string} the value to validate.
* @returns {TypeCheckResult}
*/
-function check_Object(type: spec.TObject, name: string, value: any): TypeCheckResult {
- let kind = reflect(value)
- if (kind !== "object") {
- return FailBinding(name, type.kind, kind)
- } else {
- let results = new Array()
+function check_Complex(type: spec.TComplex, name: string, value: any): TypeCheckResult {
+ const kind = reflect(value)
+ if (kind !== "complex") {
+ return FailBinding(name, type.kind, kind)
+ } else {
+ const results = new Array()
- // scan for unexpected properties.
- let unexpected_queue = Object.keys(value).map(key => ({ key: key, value: value[key] }));
- while (unexpected_queue.length > 0) {
- let property = unexpected_queue.shift()
- if (type.properties[property.key] === undefined) {
- results.push(
- FailUnexpected(name + "." + property.key, "undefined", reflect(property.value))
- )
- }
- }
-
- // scan for expected properties.
- let expected_queue = Object.keys(type.properties).map(key => ({ key: key, type: type.properties[key] }))
- while (expected_queue.length > 0) {
- let property = expected_queue.shift()
- if (value[property.key] === undefined && property.type.kind !== "undefined") {
- results.push(
- FailRequired(name + "." + property.key, property.type.kind, "undefined")
- )
- } else {
- results.push(
- check_All(property.type, name + "." + property.key, value[property.key])
- )
- }
- }
-
- // gather results.
- return results.reduce((acc, result) => {
- if (result.errors.length > 0)
- acc.success = false
- for (let i = 0; i < result.errors.length; i++)
- acc.errors.push(result.errors[i])
- return acc
- }, { success: true, errors: [] })
+ // scan for unexpected properties.
+ const unexpected_queue = Object.keys(value).map(key => ({ key: key, value: value[key] }));
+ while (unexpected_queue.length > 0) {
+ const property = unexpected_queue.shift()
+ if (type.properties[property.key] === undefined) {
+ results.push(
+ FailUnexpected(name + "." + property.key, "undefined", reflect(property.value))
+ )
+ }
}
+
+ // scan for expected properties.
+ const expected_queue = Object.keys(type.properties).map(key => ({ key: key, type: type.properties[key] }))
+ while (expected_queue.length > 0) {
+ const property = expected_queue.shift()
+ if (value[property.key] === undefined && property.type.kind !== "undefined") {
+ results.push(
+ FailRequired(name + "." + property.key, property.type.kind, "undefined")
+ )
+ } else {
+ results.push(
+ check_All(property.type, name + "." + property.key, value[property.key])
+ )
+ }
+ }
+
+ // gather results.
+ return results.reduce((acc, result) => {
+ if (result.errors.length > 0)
+ acc.success = false
+ for (let i = 0; i < result.errors.length; i++)
+ acc.errors.push(result.errors[i])
+ return acc
+ }, { success: true, errors: [] })
+ }
}
/**
@@ -276,21 +274,21 @@ function check_Object(type: spec.TObject, name: string,
* @returns {TypeCheckResult}
*/
function check_Array(type: spec.TArray>, name: string, value: any): TypeCheckResult {
- let kind = reflect(value)
- if (kind !== "array") {
- return FailBinding(name, type.kind, kind)
- } else {
- let array = value as Array
- return array.map((item, index) => check_All(type.type, name + `[${index}]`, item)).reduce((acc, result) => {
- if (result.errors.length > 0) {
- acc.success = false
- }
- for (let i = 0; i < result.errors.length; i++) {
- acc.errors.push(result.errors[i])
- }
- return acc
- }, { success: true, errors: [] })
- }
+ const kind = reflect(value)
+ if (kind !== "array") {
+ return FailBinding(name, type.kind, kind)
+ } else {
+ const array = value as Array
+ return array.map((item, index) => check_All(type.type, name + `[${index}]`, item)).reduce((acc, result) => {
+ if (result.errors.length > 0) {
+ acc.success = false
+ }
+ for (let i = 0; i < result.errors.length; i++) {
+ acc.errors.push(result.errors[i])
+ }
+ return acc
+ }, { success: true, errors: [] })
+ }
}
/**
@@ -301,25 +299,25 @@ function check_Array(type: spec.TArray>, name: string, value: an
* @returns {TypeCheckResult}
*/
function check_Tuple(type: spec.TTuple1>, name: string, value: any): TypeCheckResult {
- let kind = reflect(value)
- let array = value as Array
- if (kind !== "array") {
- return FailBinding("name", type.kind, kind)
- } else if (array.length !== type.types.length) {
- return FailLengthMismatch(name, type.kind, kind, type.types.length, array.length)
- } else {
- return array.map((item, index) =>
- check_All(type.types[index], name + `[${index}]`, item)
- ).reduce((acc, c) => {
- if (c.errors.length > 0) {
- acc.success = false
- }
- for (let i = 0; i < c.errors.length; i++) {
- acc.errors.push(c.errors[i])
- }
- return acc
- }, { success: true, errors: [] })
- }
+ const kind = reflect(value)
+ const array = value as Array
+ if (kind !== "array") {
+ return FailBinding("name", type.kind, kind)
+ } else if (array.length !== type.types.length) {
+ return FailLengthMismatch(name, type.kind, kind, type.types.length, array.length)
+ } else {
+ return array.map((item, index) =>
+ check_All(type.types[index], name + `[${index}]`, item)
+ ).reduce((acc, c) => {
+ if (c.errors.length > 0) {
+ acc.success = false
+ }
+ for (let i = 0; i < c.errors.length; i++) {
+ acc.errors.push(c.errors[i])
+ }
+ return acc
+ }, { success: true, errors: [] })
+ }
}
/**
@@ -330,26 +328,25 @@ function check_Tuple(type: spec.TTuple1>, name: string, value: a
* @returns {TypeCheckResult}
*/
function check_Union(type: spec.TUnion1>, name: string, value: any): TypeCheckResult {
- let results = type.types.map(type => check_All(type, name, value))
-
- // test for failed, we expect at least one to pass.
- let failed = results.reduce((acc, result) => {
- if (result.success === false) {
- acc += 1;
- } return acc
- }, 0)
+ const results = type.types.map(type => check_All(type, name, value))
+ // test for failed, we expect at least one to pass.
+ const failed = results.reduce((acc, result) => {
+ if (result.success === false) {
+ acc += 1;
+ } return acc
+ }, 0)
- // if they all fail, then we need to resolve a error.
- if (failed === type.types.length) {
- let unionkind = type.types.map(type => {
- return type.kind === "literal"
- ? (>type).value
- : type.kind
- }).join(" | ")
- return FailBinding(name, unionkind, reflect(value))
- } else {
- return Ok()
- }
+ // if they all fail, then we need to resolve a error.
+ if (failed === type.types.length) {
+ const unionkind = type.types.map(type => {
+ return type.kind === "literal"
+ ? (>type).value
+ : type.kind
+ }).join(" | ")
+ return FailBinding(name, unionkind, reflect(value))
+ } else {
+ return Ok()
+ }
}
@@ -360,20 +357,20 @@ function check_Union(type: spec.TUnion1>, name: string, value: a
* @returns {TypeCheckResult}
*/
function check_All(type: spec.TBase, name: string, value: any): TypeCheckResult {
- switch (type.kind) {
- case "any": return check_Any (type as spec.TAny, name, value)
- case "undefined": return check_Undefined (type as spec.TUndefined, name, value)
- case "null": return check_Null (type as spec.TNull, name, value)
- case "literal": return check_Literal (type as spec.TLiteral, name, value)
- case "string": return check_String (type as spec.TString, name, value)
- case "number": return check_Number (type as spec.TNumber, name, value)
- case "boolean": return check_Boolean (type as spec.TBoolean, name, value)
- case "object": return check_Object (type as spec.TObject, name, value)
- case "array": return check_Array (type as spec.TArray>, name, value)
- case "tuple": return check_Tuple (type as spec.TTuple1>, name, value)
- case "union": return check_Union (type as spec.TUnion1>, name, value)
- default: throw new Error("unknown type.")
- }
+ switch (type.kind) {
+ case "any": return check_Any(type as spec.TAny, name, value)
+ case "undefined": return check_Undefined(type as spec.TUndefined, name, value)
+ case "null": return check_Null(type as spec.TNull, name, value)
+ case "literal": return check_Literal(type as spec.TLiteral, name, value)
+ case "string": return check_String(type as spec.TString, name, value)
+ case "number": return check_Number(type as spec.TNumber, name, value)
+ case "boolean": return check_Boolean(type as spec.TBoolean, name, value)
+ case "complex": return check_Complex(type as spec.TComplex, name, value)
+ case "array": return check_Array(type as spec.TArray>, name, value)
+ case "tuple": return check_Tuple(type as spec.TTuple1>, name, value)
+ case "union": return check_Union(type as spec.TUnion1>, name, value)
+ default: throw new Error("unknown type.")
+ }
}
/**
@@ -383,5 +380,5 @@ function check_All(type: spec.TBase, name: string, value: any): TypeCheckRe
* @returns {TypeCheckResult}
*/
export function check(type: spec.TBase, value: any): TypeCheckResult {
- return check_All(type, "value", value)
+ return check_All(type, "value", value)
}
\ No newline at end of file
diff --git a/src/compare.ts b/src/compare.ts
index 5bb6dc3..151716a 100644
--- a/src/compare.ts
+++ b/src/compare.ts
@@ -29,85 +29,85 @@ THE SOFTWARE.
import * as spec from "./spec"
/**
- * tests the left and right type for structural compatiable. If this function
+ * tests the left and right type for structural compatibility. If this function
* returns true, it means that the left type is compatiable with the right.
* @param {TAny} left the left type.
* @param {TAny} right the right type.
* @returns {boolean}
*/
export function compare(left: spec.TBase, right: spec.TBase): boolean {
- if(left.kind === "any" || right.kind === "any") return true
- if(left.kind === "string" && right.kind === "string") return true
- if(left.kind === "number" && right.kind === "number") return true
- if(left.kind === "null" && right.kind === "null") return true
- if(left.kind === "undefined" && right.kind === "undefined") return true
- if(left.kind === "boolean" && right.kind === "boolean") return true
- if(left.kind === "literal" && right.kind === "literal") return (>left).value === (>right).value
-
+ if (left.kind === "any" || right.kind === "any") return true
+ if (left.kind === "string" && right.kind === "string") return true
+ if (left.kind === "number" && right.kind === "number") return true
+ if (left.kind === "null" && right.kind === "null") return true
+ if (left.kind === "undefined" && right.kind === "undefined") return true
+ if (left.kind === "boolean" && right.kind === "boolean") return true
+ if (left.kind === "literal" && right.kind === "literal") return (>left).value === (>right).value
+
// Object
- if(left.kind === "object" && right.kind === "object") {
- let object_left = }>>left
- let object_right = }>>right
- let keys = Object.keys(object_left.properties)
- if(keys.length !== Object.keys(object_right.properties).length) {
+ if (left.kind === "complex" && right.kind === "complex") {
+ const object_left = }>>left
+ const object_right = }>>right
+ const keys = Object.keys(object_left.properties)
+ if (keys.length !== Object.keys(object_right.properties).length) {
return false
}
- for(let i = 0; i < keys.length; i++) {
- if(object_right.properties[keys[i]] === undefined) {
+ for (let i = 0; i < keys.length; i++) {
+ if (object_right.properties[keys[i]] === undefined) {
return false
}
}
- for(let i = 0; i < keys.length; i++) {
- if(compare(object_left.properties[keys[i]], object_right.properties[keys[i]]) === false) {
+ for (let i = 0; i < keys.length; i++) {
+ if (compare(object_left.properties[keys[i]], object_right.properties[keys[i]]) === false) {
return false
}
} return true
}
// Array
- if(left.kind === "array" && right.kind === "array") {
- let array_left = >>left
- let array_right = >>right
+ if (left.kind === "array" && right.kind === "array") {
+ const array_left = >>left
+ const array_right = >>right
return compare(array_left.type, array_right.type)
}
// Tuple
- if(left.kind === "tuple" && right.kind === "tuple") {
- let tuple_left = >>left
- let tuple_right = >>right
- if(tuple_left.types.length !== tuple_right.types.length) return false
- for(let i = 0; i < tuple_left.types.length; i++) {
- if(compare(tuple_left.types[i], tuple_right.types[i]) === false) {
+ if (left.kind === "tuple" && right.kind === "tuple") {
+ const tuple_left = >>left
+ const tuple_right = >>right
+ if (tuple_left.types.length !== tuple_right.types.length) return false
+ for (let i = 0; i < tuple_left.types.length; i++) {
+ if (compare(tuple_left.types[i], tuple_right.types[i]) === false) {
return false
}
} return true
}
-
+
// union:zero length for left and right.
- if(left.kind === "union" && right.kind === "union") {
- let union_left = >>left
- let union_right = >>right
- if(union_left.types.length === 0 && union_right.types.length === 0) {
+ if (left.kind === "union" && right.kind === "union") {
+ const union_left = >>left
+ const union_right = >>right
+ if (union_left.types.length === 0 && union_right.types.length === 0) {
return true
}
}
// union:left
- if(left.kind === "union") {
- let union_left = >>left
- for(let i = 0; i < union_left.types.length; i++) {
- if(compare(union_left.types[i], right) === true) {
+ if (left.kind === "union") {
+ const union_left = >>left
+ for (let i = 0; i < union_left.types.length; i++) {
+ if (compare(union_left.types[i], right) === true) {
return true
- }
+ }
}
}
// union:right
- if(right.kind === "union") {
- let union_right = >>right
- for(let i = 0; i < union_right.types.length; i++) {
- if(compare(union_right.types[i], left) === true) {
+ if (right.kind === "union") {
+ const union_right = >>right
+ for (let i = 0; i < union_right.types.length; i++) {
+ if (compare(union_right.types[i], left) === true) {
return true
- }
+ }
}
} return false
}
\ No newline at end of file
diff --git a/src/generate.ts b/src/generate.ts
index d8f03c1..345e69f 100644
--- a/src/generate.ts
+++ b/src/generate.ts
@@ -60,9 +60,9 @@ function generate_Undefined(type: spec.TUndefined): any {
* @param {TAny} type the type.
* @returns {any}
*/
-function generate_Object(type: spec.TObject): any {
+function generate_Complex(type: spec.TComplex): any {
return Object.keys(type.properties)
- .map(key => ({key: key, value: generate(type.properties[key])}))
+ .map(key => ({ key: key, value: generate(type.properties[key]) }))
.reduce((acc, value) => {
acc[value.key] = value.value
return acc
@@ -76,8 +76,8 @@ function generate_Object(type: spec.TObject): any {
*/
function generate_Array(t: spec.TArray>): any[] {
return [
- generate(t.type),
- generate(t.type),
+ generate(t.type),
+ generate(t.type),
generate(t.type)
]
}
@@ -118,14 +118,23 @@ function generate_Boolean(t: spec.TBoolean): boolean {
return true
}
+/**
+ * generates a union type
+ * @param {TAny} t the union type.
+ * @returns {any}
+ */
function generate_Union(t: spec.TUnion1>): any {
- if(t.types.length === 0) {
+ if (t.types.length === 0) {
return {}
} else {
return generate(t.types[0])
}
}
+/**
+ * generates a literal type.
+ * @param t
+ */
function generate_Literal(t: spec.TLiteral): any {
return t.value
}
@@ -136,18 +145,18 @@ function generate_Literal(t: spec.TLiteral): any {
* @returns {any}
*/
export function generate(type: spec.TBase): any {
- switch (type.kind) {
- case "any": return generate_Any (type as spec.TAny)
- case "null": return generate_Null (type as spec.TNull)
- case "undefined": return generate_Undefined (type as spec.TUndefined)
- case "object": return generate_Object (type as spec.TObject)
- case "array": return generate_Array (type as spec.TArray>)
- case "tuple": return generate_Tuple (type as spec.TTuple1>)
- case "number": return generate_Number (type as spec.TNumber)
- case "string": return generate_String (type as spec.TString)
- case "boolean": return generate_Boolean (type as spec.TBoolean)
- case "union": return generate_Union (type as spec.TUnion1>)
- case "literal": return generate_Literal (type as spec.TLiteral)
- default: throw Error("unknown type.")
- }
+ switch (type.kind) {
+ case "any": return generate_Any (type as spec.TAny)
+ case "null": return generate_Null (type as spec.TNull)
+ case "undefined": return generate_Undefined(type as spec.TUndefined)
+ case "complex": return generate_Complex (type as spec.TComplex)
+ case "array": return generate_Array (type as spec.TArray>)
+ case "tuple": return generate_Tuple (type as spec.TTuple1>)
+ case "number": return generate_Number (type as spec.TNumber)
+ case "string": return generate_String (type as spec.TString)
+ case "boolean": return generate_Boolean (type as spec.TBoolean)
+ case "union": return generate_Union (type as spec.TUnion1>)
+ case "literal": return generate_Literal (type as spec.TLiteral)
+ default: throw Error("unknown type.")
+ }
}
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
index 4db5ba1..1d58f0a 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -44,8 +44,8 @@ import {
TString,
TNumber,
TBoolean,
- TObjectProperties,
- TObject,
+ TComplexProperties,
+ TComplex,
TArray,
TTuple1,
TTuple2,
@@ -70,7 +70,7 @@ import {
String,
Number,
Boolean,
- Object,
+ Complex,
Array,
Tuple,
Union
@@ -94,8 +94,8 @@ export {
TString,
TNumber,
TBoolean,
- TObjectProperties,
- TObject,
+ TComplexProperties,
+ TComplex,
TArray,
TTuple1,
TTuple2,
@@ -120,7 +120,7 @@ export {
String,
Number,
Boolean,
- Object,
+ Complex,
Array,
Tuple,
Union
diff --git a/src/infer.ts b/src/infer.ts
index 928e232..a6569c9 100644
--- a/src/infer.ts
+++ b/src/infer.ts
@@ -1,6 +1,6 @@
-import {reflect} from "./reflect"
-import {compare} from "./compare"
+import { reflect } from "./reflect"
+import { compare } from "./compare"
import * as spec from "./spec"
/**
@@ -9,47 +9,47 @@ import * as spec from "./spec"
* @returns {TAny}
*/
export function infer(value: any): spec.TBase {
- let kind = reflect(value)
- switch(kind) {
- case "undefined": return spec.Undefined();
+ const kind = reflect(value)
+ switch (kind) {
+ case "undefined": return spec.Undefined();
case "null": return spec.Null();
case "string": return spec.String()
case "number": return spec.Number()
case "boolean": return spec.Boolean()
case "array":
- let array = value
- if(array.length === 0) {
+ const array = value
+ if (array.length === 0) {
return spec.Array(spec.Any())
} else {
- let types = array.reduce((acc, value, index) => {
- if(index > 64) return acc
- let type = infer(value)
+ const types = array.reduce((acc, value, index) => {
+ if (index > 64) return acc
+ const type = infer(value)
let found = false
- for(let i = 0; i < acc.length; i++) {
- if(compare(acc[i], type)) {
+ for (let i = 0; i < acc.length; i++) {
+ if (compare(acc[i], type)) {
found = true
break;
}
}
- if(!found) {
+ if (!found) {
acc.push(type)
}
return acc
}, [])
return spec.Array(
(types.length > 1)
- ? spec.Union.apply(this, types)
- : types[0])
+ ? spec.Union.apply(this, types)
+ : types[0])
}
- case "object":
- return spec.Object(Object.keys(value)
- .map (key => ({
- key : key,
- type: infer(value[key])
- })).reduce((acc, value) => {
- acc[value.key] = value.type;
- return acc;
- }, {}))
+ case "complex":
+ return spec.Complex(Object.keys(value)
+ .map(key => ({
+ key: key,
+ type: infer(value[key])
+ })).reduce((acc, value) => {
+ acc[value.key] = value.type;
+ return acc;
+ }, {}))
default:
throw new Error(`unsupported type '${kind}'`)
}
diff --git a/src/reflect.ts b/src/reflect.ts
index cd71b32..d125171 100644
--- a/src/reflect.ts
+++ b/src/reflect.ts
@@ -26,7 +26,7 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/
-export type TypeName = "undefined" | "null" | "function" | "string" | "number" | "boolean" | "date" | "array" | "object"
+export type TypeName = "undefined" | "null" | "function" | "string" | "number" | "boolean" | "date" | "array" | "complex"
/**
* returns the typename for the given value.
@@ -43,5 +43,5 @@ export function reflect(value: any): TypeName {
if (typeof value === "object") {
if (value instanceof Array) return "array"
if (value instanceof Date) return "date"
- } return "object"
+ } return "complex"
}
\ No newline at end of file
diff --git a/src/schema.ts b/src/schema.ts
index 8bd00ed..7c05b1f 100644
--- a/src/schema.ts
+++ b/src/schema.ts
@@ -61,12 +61,11 @@ function schema_Null(type: spec.TNull): any {
* @returns {any}
*/
function schema_Literal(type: spec.TLiteral): any {
- let kind = reflect(type.value)
+ const kind = reflect(type.value)
switch(kind) {
case "string": return { "type": "string", "pattern": type.value }
case "number": return { "type": "number", "minimum": type.value, "maximum": type.value }
}
-
}
/**
@@ -100,7 +99,7 @@ function schema_Boolean(type: spec.TBoolean): any {
* @param {spec.TAny} type the type
* @returns {any}
*/
-function schema_Object(type: spec.TObject): any {
+function schema_Complex(type: spec.TComplex): any {
const expanded = Object.keys(type.properties).map(key => ({
key: key,
type: type.properties[key]
@@ -154,7 +153,7 @@ function schema_Tuple(type: spec.TTuple1>): any {
* @returns {any}
*/
function schema_Union(type: spec.TUnion1>): any {
- let types = type.types.map(type => schema_Base(type))
+ const types = type.types.map(type => schema_Base(type))
return {
"anyOf": types
}
@@ -170,21 +169,26 @@ function schema_Base(type: spec.TBase): any {
case "any": return schema_Any(type as spec.TAny)
case "undefined": return schema_Undefined(type as spec.TUndefined)
case "null": return schema_Null(type as spec.TNull)
- case "literal": return schema_Literal(type as spec.TLiteral)
- case "string": return schema_String(type as spec.TString)
- case "number": return schema_Number(type as spec.TNumber)
- case "boolean": return schema_Boolean(type as spec.TBoolean)
- case "object": return schema_Object(type as spec.TObject)
- case "array": return schema_Array(type as spec.TArray>)
- case "tuple": return schema_Tuple(type as spec.TTuple1>)
- case "union": return schema_Union(type as spec.TUnion1>)
+ case "literal": return schema_Literal(type as spec.TLiteral)
+ case "string": return schema_String(type as spec.TString)
+ case "number": return schema_Number(type as spec.TNumber)
+ case "boolean": return schema_Boolean(type as spec.TBoolean)
+ case "complex": return schema_Complex(type as spec.TComplex)
+ case "array": return schema_Array(type as spec.TArray>)
+ case "tuple": return schema_Tuple(type as spec.TTuple1>)
+ case "union": return schema_Union(type as spec.TUnion1>)
default: throw new Error("unknown type.")
}
}
+/**
+ * maps the given typebox type into JSONSchema.
+ * @param {spec.TBase} type the type to convert.
+ * @returns {any}
+ */
export function schema(type: spec.TBase): any {
- let base = schema_Base(type)
- let schema = {
+ const base = schema_Base(type)
+ const schema = {
"$schema": "http://json-schema.org/draft-04/schema#"
}
return Object.keys(base).reduce((acc, key) => {
diff --git a/src/spec.ts b/src/spec.ts
index 05e06ee..ffb7528 100644
--- a/src/spec.ts
+++ b/src/spec.ts
@@ -35,7 +35,7 @@ export type Static> = T["phantom"]
* TBase: base type for all supported types.
*/
export interface TBase {
- kind: "any" | "undefined" | "null" | "literal" | "string" | "number" | "boolean" | "object" | "array" | "tuple" | "union" | "intersect"
+ kind: "any" | "undefined" | "null" | "literal" | "string" | "number" | "boolean" | "complex" | "array" | "tuple" | "union" | "intersect"
phantom: T
}
@@ -95,15 +95,15 @@ export interface TBoolean extends TBase {
}
/**
- * TObjectProperties: TObject type parameter constraint.
+ * TComplexProperties: TObject type parameter constraint.
*/
-export type TObjectProperties = {[key in string]: TBase}
+export type TComplexProperties = {[key in string]: TBase}
/**
- * TObject: represents a complex type.
+ * TComplex: represents a complex type.
*/
-export interface TObject extends TBase<{[K in keyof T]: Static