Add definition for split2 (#9692)

npm: https://www.npmjs.com/package/split2
project: https://github.com/mcollina/split2
This commit is contained in:
TANAKA Koichi
2016-06-19 12:32:02 +09:00
committed by Masahiro Wakame
parent 6ea0b792a0
commit 8ef38fbc56
2 changed files with 65 additions and 0 deletions

31
split2/split2-tests.ts Normal file
View File

@@ -0,0 +1,31 @@
/// <reference path="./split2.d.ts" />
/// <reference path="../node/node.d.ts" />
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'
};

34
split2/split2.d.ts vendored Normal file
View File

@@ -0,0 +1,34 @@
// Type definitions for split2 2.1.0
// Project: https://github.com/mcollina/split2
// Definitions by: TANAKA Koichi <https://github.com/mugeso/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
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;
}