stream-to-promise-agnostic
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,6 +7,6 @@ * @author electricessence / https://github.com/electricessence/ | ||
*/ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var StreamToPromise_1 = require("./StreamToPromise"); | ||
@@ -19,4 +20,3 @@ function streamToPromise(PromiseFactory, isConstructor) { | ||
__export(require("./StreamToPromise")); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = streamToPromise; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "stream-to-promise-agnostic", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Convert streams (readable or writable) to promises using your own standard Promise library.", | ||
@@ -17,3 +17,7 @@ "main": "index.js", | ||
"author": "electricessence <npm@electrified.net>", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/node": "^8.0.53", | ||
"typescript": "^2.6.1" | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
/*! | ||
@@ -10,6 +11,6 @@ * @author electricessence / https://github.com/electricessence/ | ||
export declare module StreamEvents { | ||
const DATA: string; | ||
const END: string; | ||
const ERROR: string; | ||
const CLOSE: string; | ||
const DATA = "data"; | ||
const END = "end"; | ||
const ERROR = "error"; | ||
const CLOSE = "close"; | ||
} | ||
@@ -22,2 +23,4 @@ export interface Executor<T> { | ||
} | ||
export { ReadableStream, ReadWriteStream, WritableStream }; | ||
export declare type Stream = ReadableStream | ReadWriteStream | WritableStream; | ||
export declare class StreamToPromise { | ||
@@ -27,4 +30,12 @@ private _promiseFactory; | ||
toArray<T>(stream: ReadableStream): PromiseLike<T[]>; | ||
/** | ||
* Converts a stream into a respective promise. | ||
* Can take an array of streams and will execute them in sequence and resolve when complete or reject if any fail. | ||
* @param {NodeJS.ReadableStream | NodeJS.ReadWriteStream} stream | ||
* @returns {PromiseLike<T>} | ||
*/ | ||
toPromise<T>(stream: ReadableStream | ReadWriteStream): PromiseLike<T>; | ||
toPromise(stream: WritableStream): PromiseLike<void>; | ||
toPromise(stream: Stream): PromiseLike<void>; | ||
toPromise(streams: Stream[]): PromiseLike<void>; | ||
private fromReadable<T>(stream); | ||
@@ -31,0 +42,0 @@ private fromWritable(stream); |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/*! | ||
@@ -6,3 +7,3 @@ * @author electricessence / https://github.com/electricessence/ | ||
*/ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var _DATA = 'data', _END = 'end', _ERROR = 'error', _CLOSE = 'close'; | ||
@@ -17,3 +18,3 @@ var StreamEvents; | ||
Object.freeze(StreamEvents); | ||
var StreamToPromise = (function () { | ||
var StreamToPromise = /** @class */ (function () { | ||
// Expose DI to allow consumer to chose their own promise lib. | ||
@@ -57,7 +58,21 @@ function StreamToPromise(_promiseFactory) { | ||
StreamToPromise.prototype.toPromise = function (stream) { | ||
var _ = this; | ||
if (stream instanceof Array) { | ||
_._promiseFactory(function (resolve, reject) { | ||
var streams = stream; | ||
var i = 0; | ||
function next() { | ||
if (i < streams.length) | ||
_.toPromise(streams[i++]).then(next, reject); | ||
else | ||
resolve(); | ||
} | ||
next(); | ||
}); | ||
} | ||
if (stream.readable) | ||
return this.fromReadable(stream); | ||
return _.fromReadable(stream); | ||
if (stream.writable) | ||
return this.fromWritable(stream); | ||
return this._promiseFactory(function (resolve) { return resolve(); }); | ||
return _.fromWritable(stream); | ||
return _._promiseFactory(function (resolve) { return resolve(); }); | ||
}; | ||
@@ -80,4 +95,3 @@ StreamToPromise.prototype.fromReadable = function (stream) { | ||
exports.StreamToPromise = StreamToPromise; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = StreamToPromise; | ||
//# sourceMappingURL=StreamToPromise.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12663
162
2