UNPKG

@allgemein/schema-api

Version:
36 lines 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IP4_REGEX = void 0; exports.Ip4 = Ip4; const AnnotationsHelper_1 = require("../../lib/AnnotationsHelper"); const DefaultValidator_1 = require("../../lib/validation/DefaultValidator"); const lodash_1 = require("lodash"); function Ip4(options) { return function (source, propertyName) { const opts = { format: 'ip4' }; if (options) { (0, lodash_1.assign)(opts, { validateOptions: { ip4: {} } }); (0, lodash_1.assign)(opts.validateOptions.ip4, options); } AnnotationsHelper_1.AnnotationsHelper.forPropertyOn(source.constructor, propertyName, opts, 'merge'); }; } exports.IP4_REGEX = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; DefaultValidator_1.DefaultValidator.define({ name: 'ip4', 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.IP4_REGEX.test(value); }, defaultOptions: { message: 'Value of property "%propertyName" must be a valid ip4 address.' } }); //# sourceMappingURL=Ip4.js.map