UNPKG

@opra/common

Version:
56 lines (55 loc) 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TimeType = void 0; const tslib_1 = require("tslib"); const valgen_1 = require("valgen"); const constants_js_1 = require("../../constants.js"); const simple_type_js_1 = require("../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); } [constants_js_1.DECODER](properties) { const fn = valgen_1.vg.matches(TIME_PATTERN, { formatName: 'time', coerce: true, }); const x = []; if (properties.minValue != null) x.push(valgen_1.vg.isGte(properties.minValue)); if (properties.maxValue != null) x.push(valgen_1.vg.isLte(properties.maxValue)); return x.length > 0 ? valgen_1.vg.pipe([fn, ...x], { returnIndex: 0 }) : fn; } [constants_js_1.ENCODER](properties) { return this[constants_js_1.DECODER](properties); } }; exports.TimeType = TimeType; tslib_1.__decorate([ simple_type_js_1.SimpleType.Attribute({ description: 'Minimum value', }), tslib_1.__metadata("design:type", String) ], TimeType.prototype, "minValue", void 0); tslib_1.__decorate([ simple_type_js_1.SimpleType.Attribute({ description: 'Maximum value', }), tslib_1.__metadata("design:type", String) ], TimeType.prototype, "maxValue", void 0); exports.TimeType = TimeType = tslib_1.__decorate([ ((0, simple_type_js_1.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')), tslib_1.__metadata("design:paramtypes", [Object]) ], TimeType);