UNPKG

@opra/common

Version:

Opra common package

46 lines (45 loc) 1.32 kB
import { __decorate, __metadata } from "tslib"; import { vg } from 'valgen'; import { DECODER, ENCODER } from '../../constants.js'; import { SimpleType } from '../simple-type.js'; let IpType = class IpType { constructor(attributes) { if (attributes) Object.assign(this, attributes); } version; [DECODER](properties) { return properties?.version ? vg.isIP(properties?.version, { coerce: true }) : vg.oneOf([ vg.isIP('4', { coerce: true }), vg.isIP('6', { coerce: true }), ]); } [ENCODER](properties) { return properties?.version ? vg.isIP(properties?.version, { coerce: true }) : vg.oneOf([ vg.isIP('4', { coerce: true }), vg.isIP('6', { coerce: true }), ]); } }; __decorate([ SimpleType.Attribute({ description: 'IP version to use for validation', }), __metadata("design:type", Object) ], IpType.prototype, "version", void 0); IpType = __decorate([ SimpleType({ name: 'ip', description: 'An IP address', nameMappings: { js: 'string', json: 'string', }, }), __metadata("design:paramtypes", [Object]) ], IpType); export { IpType };