Merge pull request #18125 from LucasHill/through2-map

Create type defintions for through2-map.
This commit is contained in:
Wesley Wigham
2017-07-17 10:41:26 -07:00
committed by GitHub
4 changed files with 89 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
// Type definitions for through2-map 3.0
// Project: https://github.com/brycebaril/through2-map
// Definitions by: Lucas Hill <https://github.com/LucasHill>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import through2 = require('through2');
import stream = require('stream');
type MapCallback = (chunk: any, index: number) => void;
interface Through2MapOptions extends stream.DuplexOptions {
wantStrings?: boolean;
}
declare function through2_map(options?: Through2MapOptions, fn?: MapCallback): through2.Through2Constructor;
declare function through2_map(fn?: MapCallback): through2.Through2Constructor;
declare namespace through2_map {
function ctor(options?: Through2MapOptions, fn?: MapCallback): through2.Through2Constructor;
function ctor(fn?: MapCallback): through2.Through2Constructor;
function obj(options?: Through2MapOptions, fn?: MapCallback): through2.Through2Constructor;
function obj(fn?: MapCallback): through2.Through2Constructor;
function objCtor(options?: Through2MapOptions, fn?: MapCallback): through2.Through2Constructor;
function objCtor(fn?: MapCallback): through2.Through2Constructor;
}
export = through2_map;
+35
View File
@@ -0,0 +1,35 @@
import stream = require('stream');
import map = require('through2-map');
const stripTags = map({wantStrings: true}, (str) => {
return str.replace(/<.*?>/g, "");
});
process.stdin.pipe(stripTags);
const truncate = map((chunk) => {
return chunk.slice(0, 10);
});
process.stdin.pipe(truncate);
const Ctor = map.ctor((chunk) => {
return chunk.slice(0, 10);
});
new Ctor();
new Ctor({ objectMode: true, allowHalfOpen: true });
const Obj = map.obj((chunk) => {
return chunk.slice(0, 10);
});
new Obj();
new Obj({ objectMode: true, allowHalfOpen: true });
const Objctor = map.objCtor((chunk) => {
return chunk.slice(0, 10);
});
new Objctor();
new Objctor({ objectMode: true, allowHalfOpen: true });
+22
View File
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"through2-map-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }