UNPKG

@opra/common

Version:
50 lines (49 loc) 1.6 kB
import { __decorate, __metadata } from "tslib"; import { vg } from 'valgen'; import { DECODER, ENCODER } from '../../constants.js'; import { SimpleType } from '../simple-type.js'; let DateStringType = class DateStringType { constructor(attributes) { if (attributes) Object.assign(this, attributes); } [DECODER](properties) { const fn = vg.isDateString({ trim: 'date', 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) ], DateStringType.prototype, "minValue", void 0); __decorate([ SimpleType.Attribute({ description: 'Maximum value', }), __metadata("design:type", String) ], DateStringType.prototype, "maxValue", void 0); DateStringType = __decorate([ (SimpleType({ name: 'datestring', description: 'Date string value', nameMappings: { js: 'string', json: 'string', }, }) .Example('2021-04-18', 'Full date value') .Example('2021-04', 'Date value without day') .Example('2021', 'Year only value')), __metadata("design:paramtypes", [Object]) ], DateStringType); export { DateStringType };