Browse Source

Add dependencies, permit single-function usage

master
Sven Slootweg 6 months ago
parent
commit
346ee85f5d
2 changed files with 17 additions and 14 deletions
  1. +14
    -14
      index.js
  2. +3
    -0
      package.json

+ 14
- 14
index.js View File

@@ -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,


+ 3
- 0
package.json View File

@@ -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