From 15289fd4ac988ecd2005589bbbd3449fa93b87c4 Mon Sep 17 00:00:00 2001 From: Michael de Wit Date: Mon, 26 Aug 2019 17:18:53 +0200 Subject: [PATCH] Add types for stream-fork (#37891) --- types/stream-fork/index.d.ts | 40 ++++++++++++++++++++++++++ types/stream-fork/stream-fork-tests.ts | 15 ++++++++++ types/stream-fork/tsconfig.json | 23 +++++++++++++++ types/stream-fork/tslint.json | 1 + 4 files changed, 79 insertions(+) create mode 100644 types/stream-fork/index.d.ts create mode 100644 types/stream-fork/stream-fork-tests.ts create mode 100644 types/stream-fork/tsconfig.json create mode 100644 types/stream-fork/tslint.json diff --git a/types/stream-fork/index.d.ts b/types/stream-fork/index.d.ts new file mode 100644 index 0000000000..0603d3d54b --- /dev/null +++ b/types/stream-fork/index.d.ts @@ -0,0 +1,40 @@ +// Type definitions for stream-fork 1.0 +// Project: https://github.com/uhop/stream-fork#readme +// Definitions by: Michael de Wit +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import stream = require("stream"); + +export = Fork; + +declare class Fork extends stream.Writable { + /** + * A specialized Writable stream. It propagates every piece of data downstream to its dependent Writable streams (including Transform and Duplex streams). + * @param outputs outputs is an array of Writable streams, which will be used duplicate written chunks or items. + * @param options options is an options object, which is used to create a Writable stream. + * Read all about it in Implementing a Writable stream. If it is not specified or falsy, {objectMode: true} is assumed. This default is useful for creating object mode streams. + */ + constructor(outputs: ReadonlyArray, options?: Fork.ForkOptions); + + /** + * It returns true if outputs property is empty, and false otherwise. If isEmpty() is true, it means that the stream do not duplicate data. + */ + isEmpty(): boolean; + + /** + * It is a factory function, which accepts the same arguments as the constructor, and returns a fully constructed Fork object. + */ + static fork(outputs: ReadonlyArray, options?: Fork.ForkOptions): Fork; +} + +declare namespace Fork { + interface ForkOptions extends stream.WritableOptions { + /** + * ignoreErrors is a flag. When its value is truthy, a Fork instance never fails on write() silently ignoring downstream errors. + * Otherwise, the first encountered downstream error is reported upstream as its own error. The default: false. + */ + ignoreErrors?: boolean; + } +} diff --git a/types/stream-fork/stream-fork-tests.ts b/types/stream-fork/stream-fork-tests.ts new file mode 100644 index 0000000000..9a218afbbb --- /dev/null +++ b/types/stream-fork/stream-fork-tests.ts @@ -0,0 +1,15 @@ +import stream = require('stream'); +import Fork = require('stream-fork'); + +let fork: stream.Writable; + +const ws = new stream.Writable(); + +fork = new Fork([]); +fork = new Fork([ws]); +fork = new Fork([ws], { ignoreErrors: true }); +fork = new Fork([ws], { objectMode: false }); +fork = Fork.fork([ws, ws], { ignoreErrors: true }); + +let empty: boolean; +empty = Fork.fork([]).isEmpty(); diff --git a/types/stream-fork/tsconfig.json b/types/stream-fork/tsconfig.json new file mode 100644 index 0000000000..1dfc7fd451 --- /dev/null +++ b/types/stream-fork/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "stream-fork-tests.ts" + ] +} diff --git a/types/stream-fork/tslint.json b/types/stream-fork/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/stream-fork/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }