"use strict"; const errors = require("../errors"); const getValueType = require("../util/get-value-type"); module.exports = function createStringValidatorFunction(options = {}, name = "") { let hasMatchCondition = (options.matches != null); let matchCondition = options.matches; return function validateString(value) { if (typeof value !== "string") { return new errors.ValidationError(`Expected a string, got ${getValueType(value)} instead`); // return new errors.ValidationError(`Specified value for property '${name}' is not a string`, { // value: value, // property: name // }); } else if (hasMatchCondition && !matchCondition.test(value)) { /* TODO: Improve regex display */ return new errors.ValidationError(`Value for property '${name}' failed \`matches\` condition`, { value: value, property: name, condition: matchCondition }); } else { return true; } }; };