UNPKG

@allgemein/schema-api

Version:
36 lines 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IP6_REGEX = void 0; exports.Ip6 = Ip6; const AnnotationsHelper_1 = require("../../lib/AnnotationsHelper"); const DefaultValidator_1 = require("../../lib/validation/DefaultValidator"); const lodash_1 = require("lodash"); function Ip6(options) { return function (source, propertyName) { const opts = { format: 'ip6' }; 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.IP6_REGEX = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/; DefaultValidator_1.DefaultValidator.define({ name: 'ip6', 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.IP6_REGEX.test(value); }, defaultOptions: { message: 'Value of property "%propertyName" must be a valid ip6 address.' } }); //# sourceMappingURL=Ip6.js.map