From cf8d9038e5b3487a97b9a19221aecfb845369801 Mon Sep 17 00:00:00 2001 From: Lucas Hill Date: Sun, 16 Jul 2017 23:12:54 -0700 Subject: [PATCH] Create type defintions for through2-map. --- types/through2-map/index.d.ts | 31 +++++++++++++++++++++ types/through2-map/through2-map-tests.ts | 35 ++++++++++++++++++++++++ types/through2-map/tsconfig.json | 22 +++++++++++++++ types/through2-map/tslint.json | 1 + 4 files changed, 89 insertions(+) create mode 100644 types/through2-map/index.d.ts create mode 100644 types/through2-map/through2-map-tests.ts create mode 100644 types/through2-map/tsconfig.json create mode 100644 types/through2-map/tslint.json diff --git a/types/through2-map/index.d.ts b/types/through2-map/index.d.ts new file mode 100644 index 0000000000..c14982705b --- /dev/null +++ b/types/through2-map/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for through2-map 3.0 +// Project: https://github.com/brycebaril/through2-map +// Definitions by: Lucas Hill +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +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; diff --git a/types/through2-map/through2-map-tests.ts b/types/through2-map/through2-map-tests.ts new file mode 100644 index 0000000000..88a26d2f24 --- /dev/null +++ b/types/through2-map/through2-map-tests.ts @@ -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 }); diff --git a/types/through2-map/tsconfig.json b/types/through2-map/tsconfig.json new file mode 100644 index 0000000000..b20edc8d85 --- /dev/null +++ b/types/through2-map/tsconfig.json @@ -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" + ] +} diff --git a/types/through2-map/tslint.json b/types/through2-map/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/through2-map/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }