Skip to content

Commit

Permalink
add byline default function calling convention (DefinitelyTyped#11659)
Browse files Browse the repository at this point in the history
* add byline default function calling convention

* add tests for function-like usage of byline
  • Loading branch information
jakubskopal authored and vvakame committed Oct 6, 2016
1 parent b73e47c commit 851b50f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
7 changes: 4 additions & 3 deletions byline/byline-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'} ) );

Expand Down Expand Up @@ -44,4 +45,4 @@ var output = fs.createWriteStream('nolines.txt');

var lineStream:byline.LineStream = new LineStream();
input.pipe(lineStream);
lineStream.pipe(output);
lineStream.pipe(output);
42 changes: 19 additions & 23 deletions byline/byline.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 851b50f

Please sign in to comment.