UNPKG

validate

Version:

Validate object properties in javascript.

89 lines (78 loc) 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; /** * Default error messages. * * @private */ var Messages = { // Type message type: function type(prop, ctx, _type) { if (typeof _type == 'function') { _type = _type.name; } return "".concat(prop, " must be of type ").concat(_type, "."); }, // Required message required: function required(prop) { return "".concat(prop, " is required."); }, // Match message match: function match(prop, ctx, regexp) { return "".concat(prop, " must match ").concat(regexp, "."); }, // Length message length: function length(prop, ctx, len) { if (typeof len == 'number') { return "".concat(prop, " must have a length of ").concat(len, "."); } var min = len.min, max = len.max; if (min && max) { return "".concat(prop, " must have a length between ").concat(min, " and ").concat(max, "."); } if (max) { return "".concat(prop, " must have a maximum length of ").concat(max, "."); } if (min) { return "".concat(prop, " must have a minimum length of ").concat(min, "."); } }, // Size message size: function size(prop, ctx, _size) { if (typeof _size == 'number') { return "".concat(prop, " must have a size of ").concat(_size, "."); } var min = _size.min, max = _size.max; if (min !== undefined && max !== undefined) { return "".concat(prop, " must be between ").concat(min, " and ").concat(max, "."); } if (max !== undefined) { return "".concat(prop, " must be less than ").concat(max, "."); } if (min !== undefined) { return "".concat(prop, " must be greater than ").concat(min, "."); } }, // Enum message "enum": function _enum(prop, ctx, enums) { var copy = enums.slice(); var last = copy.pop(); return "".concat(prop, " must be either ").concat(copy.join(', '), " or ").concat(last, "."); }, // Illegal property illegal: function illegal(prop) { return "".concat(prop, " is not allowed."); }, // Default message "default": function _default(prop) { return "Validation failed for ".concat(prop, "."); } }; var _default2 = Messages; exports["default"] = _default2; module.exports = exports.default;