From 8ef38fbc561940342ea2073d74931f761be05891 Mon Sep 17 00:00:00 2001 From: TANAKA Koichi Date: Sun, 19 Jun 2016 12:32:02 +0900 Subject: [PATCH] Add definition for split2 (#9692) npm: https://www.npmjs.com/package/split2 project: https://github.com/mcollina/split2 --- split2/split2-tests.ts | 31 +++++++++++++++++++++++++++++++ split2/split2.d.ts | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 split2/split2-tests.ts create mode 100644 split2/split2.d.ts diff --git a/split2/split2-tests.ts b/split2/split2-tests.ts new file mode 100644 index 0000000000..2e09612c3b --- /dev/null +++ b/split2/split2-tests.ts @@ -0,0 +1,31 @@ +/// +/// +import * as split from 'split2'; +import * as fs from 'fs'; +import { Transform, TransformOptions } from 'stream'; + +let stream: Transform; +let options: split.Options = {}; +let matcherString = '\t'; +let matcherRegex = /\r?\n/; + +stream = split(); +stream = split(JSON.parse); +stream = split(options); +stream = split(JSON.parse, options); +stream = split(matcherString); +stream = split(matcherString, JSON.parse); +stream = split(matcherString, options); +stream = split(matcherString, JSON.parse, options); +stream = split(matcherRegex); +stream = split(matcherRegex, JSON.parse); +stream = split(matcherRegex, options); +stream = split(matcherRegex, JSON.parse, options); + +options = { + maxLength: 1000, + objectMode: true, + highWaterMark: 16, + encoding: 'utf8' +}; + diff --git a/split2/split2.d.ts b/split2/split2.d.ts new file mode 100644 index 0000000000..4ba12ae478 --- /dev/null +++ b/split2/split2.d.ts @@ -0,0 +1,34 @@ +// Type definitions for split2 2.1.0 +// Project: https://github.com/mcollina/split2 +// Definitions by: TANAKA Koichi +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +declare module "split2" { + import { Transform, TransformOptions } from 'stream'; + + type Matcher = string|RegExp; + type Mapper = split.Mapper; + type Options = split.Options; + + function split(): Transform; + function split(matcher: Matcher): Transform; + function split(mapper: Mapper): Transform; + function split(options: Options): Transform; + function split(matcher: Matcher, mapper: Mapper): Transform; + function split(matcher: Matcher, options: Options): Transform; + function split(mapper: Mapper, options: Options): Transform; + function split(matcher: Matcher, mapper: Mapper, options: Options): Transform; + + namespace split { + export interface Mapper { + (line: string): any; + } + + export interface Options extends TransformOptions { + maxLength?: number; + } + } + + export = split; +}