UNPKG

@opra/common

Version:
55 lines (54 loc) 1.67 kB
import { __decorate, __metadata } from "tslib"; import { vg } from 'valgen'; import { DECODER, ENCODER } from '../../constants.js'; import { SimpleType } from '../simple-type.js'; const TIME_PATTERN = /^([0-1][0-9]|2[0-4]):([0-5][0-9])(?::([0-5][0-9]))?$/; let TimeType = class TimeType { constructor(attributes) { if (attributes) Object.assign(this, attributes); } minValue; maxValue; [DECODER](properties) { const fn = vg.matches(TIME_PATTERN, { formatName: 'time', coerce: true, }); const x = []; if (properties.minValue != null) x.push(vg.isGte(properties.minValue)); if (properties.maxValue != null) x.push(vg.isLte(properties.maxValue)); return x.length > 0 ? vg.pipe([fn, ...x], { returnIndex: 0 }) : fn; } [ENCODER](properties) { return this[DECODER](properties); } }; __decorate([ SimpleType.Attribute({ description: 'Minimum value', }), __metadata("design:type", String) ], TimeType.prototype, "minValue", void 0); __decorate([ SimpleType.Attribute({ description: 'Maximum value', }), __metadata("design:type", String) ], TimeType.prototype, "maxValue", void 0); TimeType = __decorate([ (SimpleType({ name: 'time', description: 'Time string in 24h format', nameMappings: { js: 'string', json: 'string', }, }) .Example('18:23:00', 'Full time value') .Example('18:23:00', 'Time value without seconds')), __metadata("design:paramtypes", [Object]) ], TimeType); export { TimeType };