Add dependencies, permit single-function usage

master
Sven Slootweg 4 years ago
parent 2976a37e0e
commit 346ee85f5d

@ -10,29 +10,29 @@ const { validateOptions } = require("@validatem/core");
const required = require("@validatem/required");
const isFunction = require("@validatem/is-function");
const defaultTo = require("@validatem/default-to");
const wrapValueAsOption = require("@validatem/wrap-value-as-option");
// FIXME: Update other stream implementations to new API
module.exports = function simpleSinkStream(_options) {
let { onResult, onEnd, onAbort } = validateOptions(arguments, {
let { onResult, onEnd, onAbort } = validateOptions(arguments, [
required,
wrapValueAsOption("onResult"), {
onResult: [ required, isFunction ],
onEnd: [ isFunction, defaultTo.literal(defaultOnEnd) ],
onAbort: [ isFunction, defaultTo.literal(defaultOnAbort) ]
});
onEnd: [ isFunction, defaultTo.literal(function defaultOnEnd() {
// We return whatever value we got last from the specified onResult callback.
return lastResult;
})],
onAbort: [ isFunction, defaultTo.literal(function defaultOnAbort() {
// no-op
})]
}
]);
let lastResult;
let onEndCalled = false;
let onEndResult;
let abortHandled = false;
function defaultOnEnd() {
// We return whatever value we got last from the specified onResult callback.
return lastResult;
}
function defaultOnAbort() {
// no-op
}
return {
description: `simple sink stream`,
abort: propagateAbort,

@ -6,12 +6,15 @@
"author": "Sven Slootweg <admin@cryto.net>",
"license": "WTFPL OR CC0-1.0",
"dependencies": {
"@ppstreams/is-aborted": "^0.1.0",
"@ppstreams/is-end-of-stream": "^0.1.0",
"@ppstreams/propagate-abort": "^0.1.2",
"@ppstreams/propagate-peek": "^0.1.0",
"@validatem/core": "^0.3.11",
"@validatem/default-to": "^0.1.0",
"@validatem/is-function": "^0.1.0",
"@validatem/required": "^0.1.1",
"@validatem/wrap-value-as-option": "^0.1.0",
"bluebird": "^3.5.4"
}
}

Loading…
Cancel
Save