Browse Source

Add dependencies, permit single-function usage

Sven Slootweg 3 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

@ -10,29 +10,29 @@ const { validateOptions } = require("@validatem/core");
10 10
const required = require("@validatem/required");
11 11
const isFunction = require("@validatem/is-function");
12 12
const defaultTo = require("@validatem/default-to");
13
const wrapValueAsOption = require("@validatem/wrap-value-as-option");
13 14
14 15
// FIXME: Update other stream implementations to new API
15 16
module.exports = function simpleSinkStream(_options) {
16
	let { onResult, onEnd, onAbort } = validateOptions(arguments, {
17
		onResult: [ required, isFunction ],
18
		onEnd: [ isFunction, defaultTo.literal(defaultOnEnd) ],
19
		onAbort: [ isFunction, defaultTo.literal(defaultOnAbort) ]
20
	});
17
	let { onResult, onEnd, onAbort } = validateOptions(arguments, [
18
		required,
19
		wrapValueAsOption("onResult"), {
20
			onResult: [ required, isFunction ],
21
			onEnd: [ isFunction, defaultTo.literal(function defaultOnEnd() {
22
				// We return whatever value we got last from the specified onResult callback.
23
				return lastResult;
24
			})],
25
			onAbort: [ isFunction, defaultTo.literal(function defaultOnAbort() {
26
				// no-op
27
			})]
28
		}
29
	]);
21 30
22 31
	let lastResult;
23 32
	let onEndCalled = false;
24 33
	let onEndResult;
25 34
	let abortHandled = false;
26 35
27
	function defaultOnEnd() {
28
		// We return whatever value we got last from the specified onResult callback.
29
		return lastResult;
30
	}
31
32
	function defaultOnAbort() {
33
		// no-op
34
	}
35
36 36
	return {
37 37
		description: `simple sink stream`,
38 38
		abort: propagateAbort,

+ 3 - 0
package.json

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