scramjet-core
Advanced tools
Comparing version 4.29.2 to 4.30.0
@@ -90,3 +90,3 @@ const scramjet = require("."); | ||
const unHook = (async () => { | ||
const unHook = () => { | ||
this.removeListener("data", chunkHandler); | ||
@@ -96,3 +96,3 @@ this.removeListener("end", endHandler); | ||
return func(ret); | ||
}); | ||
}; | ||
@@ -99,0 +99,0 @@ |
@@ -82,3 +82,3 @@ const {PromiseTransformStream} = require("./util/promise-transform-stream"); | ||
* | ||
* @param {Array|Iterable<any>|AsyncGeneratorFunction|GeneratorFunction|AsyncFunction|Function|string|Readable} input argument to be turned into new stream | ||
* @param {Array|Iterable<any>|AsyncGeneratorFunction|GeneratorFunction|AsyncFunction|Promise|Function|string|Readable} input argument to be turned into new stream | ||
* @param {DataStreamOptions|Writable} [options={}] options for creation of a new stream or the target stream | ||
@@ -137,2 +137,12 @@ * @param {any[]} ...args additional arguments for the stream - will be passed to the function or generator | ||
if (input instanceof Promise) { | ||
const out = new this(Object.assign({}, options)); | ||
input | ||
.then(source => this.from(source, out)) | ||
.catch(e => out.raise(new StreamError(e, out, "EXTERNAL", null))); | ||
return out; | ||
} | ||
if (typeof input === "function") { | ||
@@ -139,0 +149,0 @@ const out = new this(Object.assign({}, options)); |
@@ -225,3 +225,3 @@ /** @ignore */ | ||
* @param {ParseCallback} parser The transform function | ||
* @param {function(new:DataStream)} StreamClass the output stream class to return | ||
* @param {function(new:DataStream)} [StreamClass] the output stream class to return | ||
* @return {DataStream} The parsed objects stream. | ||
@@ -231,4 +231,4 @@ * | ||
*/ | ||
parse(parser, StreamClass) { | ||
return this.tap().map(parser, StreamClass || scramjet.DataStream); | ||
parse(parser, StreamClass = scramjet.DataStream) { | ||
return this.tap().map(parser, StreamClass); | ||
} | ||
@@ -235,0 +235,0 @@ |
{ | ||
"name": "scramjet-core", | ||
"version": "4.29.2", | ||
"version": "4.30.0", | ||
"description": "A pluggable minimal version of Scramjet that focuses only on stream transform and exposes only core features", | ||
@@ -60,3 +60,3 @@ "main": "lib/index.js", | ||
"eslint": "^7.9.0", | ||
"eslint-config-scramjet": "^2.0.1", | ||
"eslint-config-scramjet": "^3.0.0", | ||
"fancy-log": "^1.3.3", | ||
@@ -63,0 +63,0 @@ "gulp": "^4.0.2", |
@@ -239,3 +239,3 @@ [](https://travis-ci.org/signicode/scramjet-core) | ||
* [`stringStream.toBufferStream() : BufferStream ↺`](docs/string-stream.md#module_scramjet.StringStream+toBufferStream) - Transforms the StringStream to BufferStream | ||
* [`stringStream.parse(parser, StreamClass) : DataStream ↺`](docs/string-stream.md#module_scramjet.StringStream+parse) - Parses every string to object | ||
* [`stringStream.parse(parser, [StreamClass]) : DataStream ↺`](docs/string-stream.md#module_scramjet.StringStream+parse) - Parses every string to object | ||
* [`stringStream.toDataStream()`](docs/string-stream.md#module_scramjet.StringStream+toDataStream) - Alias for {@link StringStream#parse} | ||
@@ -242,0 +242,0 @@ * [`StringStream:SPLIT_LINE`](docs/string-stream.md#module_scramjet.StringStream.SPLIT_LINE) - A handy split by line regex to quickly get a line-by-line stream |
@@ -69,2 +69,8 @@ const { DataStream, StringStream } = require(process.env.SCRAMJET_TEST_HOME || "../../"); | ||
test_from: { | ||
async fromPromise(test) { | ||
const dsp = await DataStream.from(Promise.resolve([1,2,3])).toArray(); | ||
test.deepEqual([1, 2, 3], dsp, "Should be the same as the stream"); | ||
test.done(); | ||
}, | ||
async noOptions(test) { | ||
@@ -71,0 +77,0 @@ const x = new PassThrough({ objectMode: true }); |
236676
4738