Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (type && !regex && regularExpressions[type]) {
regex = regularExpressions[type];
}
if (type === 'email') {
if (regex === regularExpressions.email) {
regex = formatEmailRegex(options);
}
set(options, 'regex', regex);
}
if (!canInvoke(value, 'match') || (regex && isEmpty(value.match(regex)) !== inverse)) {
return validationError(type || 'invalid', value, options);
}
return true;
}
}
if (isEmpty(value)) {
return validationError('notANumber', value, options);
}
if (typeof value === 'string' && !allowString) {
return validationError('notANumber', value, options);
}
if (!isNumber(numValue)) {
return validationError('notANumber', value, options);
}
if (integer && !isInteger(numValue)) {
return validationError('notAnInteger', value, options);
}
for (let i = 0; i < optionKeys.length; i++) {
let type = optionKeys[i];
let returnValue = _validateType(type, options, numValue);
if (typeof returnValue !== 'boolean') {
return returnValue;
}
}
return true;
}
let actual = value;
if (type === 'is' && actual !== expected) {
return validationError('equalTo', value, options);
} else if (type === 'lt' && actual >= expected) {
return validationError('lessThan', value, options);
} else if (type === 'lte' && actual > expected) {
return validationError('lessThanOrEqualTo', value, options);
} else if (type === 'gt' && actual <= expected) {
return validationError('greaterThan', value, options);
} else if (type === 'gte' && actual < expected) {
return validationError('greaterThanOrEqualTo', value, options);
} else if (type === 'positive' && actual < 0) {
return validationError('positive', value, options);
} else if (type === 'odd' && actual % 2 === 0) {
return validationError('odd', value, options);
} else if (type === 'even' && actual % 2 !== 0) {
return validationError('even', value, options);
} else if (type === 'multipleOf' && !isInteger(actual / expected)) {
return validationError('multipleOf', value, options);
}
return true;
}
if (before) {
before = parseDate(before, format);
if (!date.isBefore(before, precision)) {
set(options, 'before', before.format(errorFormat));
return validationError('before', value, options);
}
}
if (onOrBefore) {
onOrBefore = parseDate(onOrBefore, format);
if (!date.isSameOrBefore(onOrBefore, precision)) {
set(options, 'onOrBefore', onOrBefore.format(errorFormat));
return validationError('onOrBefore', value, options);
}
}
if (after) {
after = parseDate(after, format);
if (!date.isAfter(after, precision)) {
set(options, 'after', after.format(errorFormat));
return validationError('after', value, options);
}
}
if (onOrAfter) {
onOrAfter = parseDate(onOrAfter, format);
if (!date.isSameOrAfter(onOrAfter, precision)) {
function _validateType(type, options, value) {
let expected = get(options, type);
let actual = value;
if (type === 'is' && actual !== expected) {
return validationError('equalTo', value, options);
} else if (type === 'lt' && actual >= expected) {
return validationError('lessThan', value, options);
} else if (type === 'lte' && actual > expected) {
return validationError('lessThanOrEqualTo', value, options);
} else if (type === 'gt' && actual <= expected) {
return validationError('greaterThan', value, options);
} else if (type === 'gte' && actual < expected) {
return validationError('greaterThanOrEqualTo', value, options);
} else if (type === 'positive' && actual < 0) {
return validationError('positive', value, options);
} else if (type === 'odd' && actual % 2 === 0) {
return validationError('odd', value, options);
} else if (type === 'even' && actual % 2 !== 0) {
return validationError('even', value, options);
} else if (type === 'multipleOf' && !isInteger(actual / expected)) {
return validationError('multipleOf', value, options);
}
if (type === 'is' && actual !== expected) {
return validationError('equalTo', value, options);
} else if (type === 'lt' && actual >= expected) {
return validationError('lessThan', value, options);
} else if (type === 'lte' && actual > expected) {
return validationError('lessThanOrEqualTo', value, options);
} else if (type === 'gt' && actual <= expected) {
return validationError('greaterThan', value, options);
} else if (type === 'gte' && actual < expected) {
return validationError('greaterThanOrEqualTo', value, options);
} else if (type === 'positive' && actual < 0) {
return validationError('positive', value, options);
} else if (type === 'odd' && actual % 2 === 0) {
return validationError('odd', value, options);
} else if (type === 'even' && actual % 2 !== 0) {
return validationError('even', value, options);
} else if (type === 'multipleOf' && !isInteger(actual / expected)) {
return validationError('multipleOf', value, options);
}
return true;
}
function _validateType(type, options, value) {
let expected = get(options, type);
let actual = value;
if (type === 'is' && actual !== expected) {
return validationError('equalTo', value, options);
} else if (type === 'lt' && actual >= expected) {
return validationError('lessThan', value, options);
} else if (type === 'lte' && actual > expected) {
return validationError('lessThanOrEqualTo', value, options);
} else if (type === 'gt' && actual <= expected) {
return validationError('greaterThan', value, options);
} else if (type === 'gte' && actual < expected) {
return validationError('greaterThanOrEqualTo', value, options);
} else if (type === 'positive' && actual < 0) {
return validationError('positive', value, options);
} else if (type === 'odd' && actual % 2 === 0) {
return validationError('odd', value, options);
} else if (type === 'even' && actual % 2 !== 0) {
return validationError('even', value, options);
} else if (type === 'multipleOf' && !isInteger(actual / expected)) {
return validationError('multipleOf', value, options);
}
return true;
}
function _validateType(type, options, value) {
let expected = get(options, type);
let actual = value;
if (type === 'is' && actual !== expected) {
return validationError('equalTo', value, options);
} else if (type === 'lt' && actual >= expected) {
return validationError('lessThan', value, options);
} else if (type === 'lte' && actual > expected) {
return validationError('lessThanOrEqualTo', value, options);
} else if (type === 'gt' && actual <= expected) {
return validationError('greaterThan', value, options);
} else if (type === 'gte' && actual < expected) {
return validationError('greaterThanOrEqualTo', value, options);
} else if (type === 'positive' && actual < 0) {
return validationError('positive', value, options);
} else if (type === 'odd' && actual % 2 === 0) {
return validationError('odd', value, options);
} else if (type === 'even' && actual % 2 !== 0) {
return validationError('even', value, options);
} else if (type === 'multipleOf' && !isInteger(actual / expected)) {
return validationError('multipleOf', value, options);
}
return true;
}
let length = get(value, 'length');
if (!isNone(is) && is !== length) {
return validationError('wrongLength', value, options);
}
if (useBetweenMessage && !isNone(min) && !isNone(max) && (length < min || length > max)) {
return validationError('between', value, options);
}
if (!isNone(min) && min > length) {
return validationError('tooShort', value, options);
}
if (!isNone(max) && max < length) {
return validationError('tooLong', value, options);
}
return true;
}