mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-22 20:37:58 +08:00
Merge pull request #3584 from reppners/node-byline
+ node-byline typings + test
This commit is contained in:
47
byline/byline-tests.ts
Normal file
47
byline/byline-tests.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Created by stefansteinhart on 31.01.15.
|
||||
*/
|
||||
|
||||
/// <reference path="byline.d.ts" />
|
||||
|
||||
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);
|
||||
38
byline/byline.d.ts
vendored
Normal file
38
byline/byline.d.ts
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
// Type definitions for byline 4.2.1
|
||||
// Project: https://github.com/jahewson/node-byline
|
||||
// Definitions by: Stefan Steinhart <https://github.com/reppners>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user