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.
18 lines
496 B
JavaScript
18 lines
496 B
JavaScript
"use strict";
|
|
|
|
const ValidationError = require("@validatem/error");
|
|
const util = require("util");
|
|
|
|
module.exports = function (expectedValue) {
|
|
if (expectedValue != null) {
|
|
return function (value) {
|
|
// TODO: Add special deep-equals handling for eg. arrays and objects?
|
|
if (value !== expectedValue) {
|
|
throw new ValidationError(`Must be exactly this value: ${util.inspect(expectedValue)}`);
|
|
}
|
|
};
|
|
} else {
|
|
throw new Error("Argument to `isValue` must be a non-null value");
|
|
}
|
|
};
|