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.

14 lines
502 B
JavaScript

"use strict";
const ValidationError = require("@validatem/error");
// FIXME: Note in README that this module DOES NOT enforce any particular type, due to `.length` being a de facto standard of sorts
module.exports = function createHasLengthOfValidator(expectedLength) {
return function hasLengthOf(value) {
if (value.length == null || value.length !== expectedLength) {
throw new ValidationError(`Must have a length of exactly ${expectedLength}; actual length was ${value.length}`);
}
}
};