env-sentinel
Version:
Zero-dependency tool that auto-validates .env files against schema.env, with optional fallback and secure warnings.
19 lines (18 loc) • 541 B
JavaScript
export function maxValueValidator(key, value, args) {
const maxValue = parseFloat(args[0]);
if (isNaN(maxValue)) {
return `Invalid max argument for ${key}`;
}
const numValue = parseFloat(value);
if (!isNaN(numValue) && numValue.toString() === value) {
if (numValue > maxValue) {
return `${key} must be <= ${maxValue}`;
}
}
else {
if (value.length > maxValue) {
return `${key} must be at most ${maxValue} characters long`;
}
}
return true;
}