diff --git a/byline/byline-tests.ts b/byline/byline-tests.ts new file mode 100644 index 0000000000..42de3d5d9c --- /dev/null +++ b/byline/byline-tests.ts @@ -0,0 +1,47 @@ +/** + * Created by stefansteinhart on 31.01.15. + */ + +/// + +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.createStream( fs.createReadStream( 'sample.txt', {encoding: 'utf8'} ) ); + +stream.on('data', function(line:string) { + console.log(line); +}); + +stream = byline.createStream(stream); + +stream.on('data', function(line:string) { + console.log(line); +}); + +var input = fs.createReadStream('sample.txt'); +stream.pipe(fs.createWriteStream('nolines.txt')); + +var lineStream = byline.createStream(); +input.pipe(lineStream); + +var output = fs.createWriteStream('test.txt'); +lineStream.pipe(output); + +stream.on('readable', function() { + var line:string; + while (null !== (line = stream.read())) { + console.log(line); + } +}); + +var LineStream = require('byline').LineStream; + +var output = fs.createWriteStream('nolines.txt'); + +var lineStream:byline.LineStream = new LineStream(); +input.pipe(lineStream); +lineStream.pipe(output); \ No newline at end of file diff --git a/byline/byline.d.ts b/byline/byline.d.ts new file mode 100644 index 0000000000..6dac6ad50b --- /dev/null +++ b/byline/byline.d.ts @@ -0,0 +1,38 @@ +// Type definitions for byline 4.2.1 +// Project: https://github.com/jahewson/node-byline +// Definitions by: Stefan Steinhart +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "byline" { + import stream = require("stream"); + + export interface LineStreamOptions extends stream.TransformOptions { + keepEmptyLines: boolean; + } + + export interface LineStream extends stream.Transform { + } + + export interface LineStreamCreatable extends LineStream { + new (options?:LineStreamOptions):LineStream + } + + //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; +} \ No newline at end of file