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

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

Loading…
Cancel
Save