Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#66731 Add @types/map-stream by @KonradPerl…
Browse files Browse the repository at this point in the history
…icki

* Add @types/map-stream

* Update comment in types/map-stream/index.d.ts

Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <[email protected]>

* Fixed return type

---------

Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <[email protected]>
  • Loading branch information
KonradPerlicki and peterblazejewicz authored Sep 19, 2023
1 parent 127cdd3 commit f472296
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
38 changes: 38 additions & 0 deletions types/map-stream/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Type definitions for map-stream 0.0
// Project: http://github.com/dominictarr/map-stream
// Definitions by: Konrad Perlicki <https://github.com/KonradPerlicki>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference types="node"/>

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;
15 changes: 15 additions & 0 deletions types/map-stream/map-stream-tests.ts
Original file line number Diff line number Diff line change
@@ -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) => {});
23 changes: 23 additions & 0 deletions types/map-stream/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
1 change: 1 addition & 0 deletions types/map-stream/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "@definitelytyped/dtslint/dt.json" }

0 comments on commit f472296

Please sign in to comment.