"use strict"; const ValidationError = require("@validatem/error"); // TODO: Generate custom error message for cases where minimum is -Infinity or maximum is Infinity? // TODO: 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 createHasLengthBetweenValidator(minimum, maximum) { // NOTE: minimum/maximum are both INCLUSIVE! // TODO: Note that in README return function hasLengthBetween(value) { if (value.length == null || value.length < minimum || value.length > maximum) { throw new ValidationError(`Must have a length between ${minimum} and ${maximum}; actual length was ${value.length}`); } } };