You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
4 years ago
|
"use strict";
|
||
|
|
||
|
const ValidationError = require("@validatem/error");
|
||
|
const isStream = require("is-stream");
|
||
|
|
||
|
module.exports = {
|
||
|
any: function (value) {
|
||
|
if (!isStream(value)) {
|
||
|
return new ValidationError("Must be a Node.js stream");
|
||
|
}
|
||
|
},
|
||
|
readable: function (value) {
|
||
|
if (!isStream.readable(value) || isStream.writable(value)) {
|
||
|
return new ValidationError("Must be a Node.js Readable stream");
|
||
|
}
|
||
|
},
|
||
|
anyReadable: function (value) {
|
||
|
if (!isStream.readable(value)) {
|
||
|
return new ValidationError("Must be a Node.js stream that can be read from");
|
||
|
}
|
||
|
},
|
||
|
writable: function (value) {
|
||
|
if (!isStream.writable(value) || isStream.readable(value)) {
|
||
|
return new ValidationError("Must be a Node.js Writable stream");
|
||
|
}
|
||
|
},
|
||
|
anyWritable: function (value) {
|
||
|
if (!isStream.writable(value)) {
|
||
|
return new ValidationError("Must be a Node.js stream that can be written to");
|
||
|
}
|
||
|
},
|
||
|
duplex: function (value) {
|
||
|
if (!isStream.duplex(value) || isStream.transform(value)) {
|
||
|
return new ValidationError("Must be a Node.js Duplex stream");
|
||
|
}
|
||
|
},
|
||
|
anyDuplex: function (value) {
|
||
|
if (!isStream.duplex(value)) {
|
||
|
return new ValidationError("Must be a Node.js Duplex-based stream (eg. a Transform stream)");
|
||
|
}
|
||
|
},
|
||
|
transform: function (value) {
|
||
|
if (!isStream.transform(value)) {
|
||
|
return new ValidationError("Must be a Node.js Transform stream");
|
||
|
}
|
||
|
}
|
||
|
};
|