From 346ee85f5dc6586bfce755108b36811569e262a4 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Mon, 20 Jul 2020 22:32:05 +0200 Subject: [PATCH] Add dependencies, permit single-function usage --- index.js | 28 ++++++++++++++-------------- package.json | 3 +++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index a033962..bb1931b 100644 --- a/index.js +++ b/index.js @@ -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, { - onResult: [ required, isFunction ], - onEnd: [ isFunction, defaultTo.literal(defaultOnEnd) ], - onAbort: [ isFunction, defaultTo.literal(defaultOnAbort) ] - }); + let { onResult, onEnd, onAbort } = validateOptions(arguments, [ + required, + wrapValueAsOption("onResult"), { + onResult: [ required, isFunction ], + 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, diff --git a/package.json b/package.json index 7be796c..afa368a 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,15 @@ "author": "Sven Slootweg ", "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" } }