UNPKG

@allgemein/schema-api

Version:
36 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MAIL_REGEX = void 0; exports.IsEmail = IsEmail; const lodash_1 = require("lodash"); const AnnotationsHelper_1 = require("../../lib/AnnotationsHelper"); const DefaultValidator_1 = require("../../lib/validation/DefaultValidator"); function IsEmail(options = null) { return function (source, propertyName) { const opts = { format: 'email' }; if (options) { (0, lodash_1.assign)(opts, { validateOptions: { email: {} } }); opts.validateOptions = { email: options }; } AnnotationsHelper_1.AnnotationsHelper.forPropertyOn(source.constructor, propertyName, opts, 'merge'); }; } exports.MAIL_REGEX = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/; DefaultValidator_1.DefaultValidator.define({ name: 'email', fn: (value, options, instance) => { if ((0, lodash_1.isUndefined)(value) || (0, lodash_1.isNull)(value) || !(0, lodash_1.isString)(value)) { // if (!get(options, 'required', false)) { // return true; // } return false; } return exports.MAIL_REGEX.test(value); }, defaultOptions: { message: 'Value of property "%propertyName" must be a valid email.' } }); //# sourceMappingURL=IsEmail.js.map