From f472296cb002d64412861887e4560f444d0ff92d Mon Sep 17 00:00:00 2001 From: Konrad Perlicki Date: Tue, 19 Sep 2023 23:05:08 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#66731=20Add=20@typ?= =?UTF-8?q?es/map-stream=20by=20@KonradPerlicki?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add @types/map-stream * Update comment in types/map-stream/index.d.ts Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) * Fixed return type --------- Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) --- types/map-stream/index.d.ts | 38 ++++++++++++++++++++++++++++ types/map-stream/map-stream-tests.ts | 15 +++++++++++ types/map-stream/tsconfig.json | 23 +++++++++++++++++ types/map-stream/tslint.json | 1 + 4 files changed, 77 insertions(+) create mode 100644 types/map-stream/index.d.ts create mode 100644 types/map-stream/map-stream-tests.ts create mode 100644 types/map-stream/tsconfig.json create mode 100644 types/map-stream/tslint.json diff --git a/types/map-stream/index.d.ts b/types/map-stream/index.d.ts new file mode 100644 index 00000000000000..1706ceceecd0b4 --- /dev/null +++ b/types/map-stream/index.d.ts @@ -0,0 +1,38 @@ +// Type definitions for map-stream 0.0 +// Project: http://github.com/dominictarr/map-stream +// Definitions by: Konrad Perlicki +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { Stream } from 'stream'; + +export = mapStream; + +declare namespace mapStream { + interface Options { + /** + * Continue mapping even if error occured. + * + * On error `map-stream` will emit `failure` event. + * + * @default false + */ + failures?: boolean; + } + + interface mapStream extends Stream { + resume(): void; + pause(): void; + destroy(): void; + end(): void; + write(): boolean | never; + } + + type Callback = (err: null | Error, data: unknown) => void; +} + +declare function mapStream( + mapper: (data: unknown, callback: mapStream.Callback) => void, + opts?: mapStream.Options, +): mapStream.mapStream; diff --git a/types/map-stream/map-stream-tests.ts b/types/map-stream/map-stream-tests.ts new file mode 100644 index 00000000000000..aa83d436187155 --- /dev/null +++ b/types/map-stream/map-stream-tests.ts @@ -0,0 +1,15 @@ +import map = require('map-stream'); + +const callback: map.Callback = function (err, data) {}; + +const fn = map((data, callback) => {}, { + failures: true, +}); + +fn.pause(); +fn.write(); +fn.resume(); +fn.destroy(); +fn.end(); + +map((data, callback) => {}); diff --git a/types/map-stream/tsconfig.json b/types/map-stream/tsconfig.json new file mode 100644 index 00000000000000..aadc96fffd1012 --- /dev/null +++ b/types/map-stream/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", + "map-stream-tests.ts" + ] +} diff --git a/types/map-stream/tslint.json b/types/map-stream/tslint.json new file mode 100644 index 00000000000000..794cb4bf3e0782 --- /dev/null +++ b/types/map-stream/tslint.json @@ -0,0 +1 @@ +{ "extends": "@definitelytyped/dtslint/dt.json" }