From 851b50fa81b02d2ab2e84d087f511d1e68e3f499 Mon Sep 17 00:00:00 2001 From: jakubskopal Date: Thu, 6 Oct 2016 15:21:46 +0200 Subject: [PATCH] add byline default function calling convention (#11659) * add byline default function calling convention * add tests for function-like usage of byline --- byline/byline-tests.ts | 7 ++++--- byline/byline.d.ts | 42 +++++++++++++++++++----------------------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/byline/byline-tests.ts b/byline/byline-tests.ts index 42de3d5d9c28bb..201d5dbda38317 100644 --- a/byline/byline-tests.ts +++ b/byline/byline-tests.ts @@ -7,8 +7,9 @@ import fs = require( 'fs' ); import byline = require( 'byline' ); -//TODO can this be typed in an ambient way? -//var stream = byline( fs.createReadStream( 'sample.txt', {encoding: 'utf8'} ) ); +var stream = byline(); + +var stream = byline( fs.createReadStream( 'sample.txt', {encoding: 'utf8'} ) ); var stream = byline.createStream( fs.createReadStream( 'sample.txt', {encoding: 'utf8'} ) ); @@ -44,4 +45,4 @@ var output = fs.createWriteStream('nolines.txt'); var lineStream:byline.LineStream = new LineStream(); input.pipe(lineStream); -lineStream.pipe(output); \ No newline at end of file +lineStream.pipe(output); diff --git a/byline/byline.d.ts b/byline/byline.d.ts index 48ddd2d57aa2c2..68cb81e139c286 100644 --- a/byline/byline.d.ts +++ b/byline/byline.d.ts @@ -8,31 +8,27 @@ declare module "byline" { import stream = require("stream"); - export interface LineStreamOptions extends stream.TransformOptions { - keepEmptyLines?: boolean; - } + function bl(): bl.LineStream; + function bl(stream: NodeJS.ReadableStream, options?: bl.LineStreamOptions): bl.LineStream; - export interface LineStream extends stream.Transform { - } + namespace bl { + + export interface LineStreamOptions extends stream.TransformOptions { + keepEmptyLines?: boolean; + } + + export interface LineStream extends stream.Transform { + } + + export interface LineStreamCreatable extends LineStream { + new (options?: LineStreamOptions): LineStream + } + + export function createStream(): LineStream; + export function createStream(stream: NodeJS.ReadableStream, options?: LineStreamOptions): LineStream; - export interface LineStreamCreatable extends LineStream { - new (options?:LineStreamOptions):LineStream + export var LineStream: LineStreamCreatable; } - //TODO is it possible to declare static factory functions without name (directly on the module) - // - // JS: - // // convinience API - // module.exports = function(readStream, options) { - // return module.exports.createStream(readStream, options); - // }; - // - // TS: - // ():LineStream; // same as createStream():LineStream - // (stream:stream.Stream, options?:LineStreamOptions):LineStream; // same as createStream(stream, options?):LineStream - - export function createStream():LineStream; - export function createStream(stream:NodeJS.ReadableStream, options?:LineStreamOptions):LineStream; - - export var LineStream:LineStreamCreatable; + export = bl; }