UNPKG

@opra/common

Version:
75 lines (74 loc) 2.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DateType = 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 _isDateString = valgen_1.vg.isDateString({ precisionMin: 'day', trim: 'day', coerce: true, }); const _isDate = valgen_1.vg.isDate({ trim: 'day', coerce: true, }); let DateType = class DateType { constructor(attributes) { if (attributes) Object.assign(this, attributes); } [constants_js_1.DECODER](properties) { let fn; if (properties.convertToNative) { fn = _isDate; } else { fn = _isDateString; } const x = [fn]; if (properties.minValue != null) { x.push(valgen_1.vg.isGte(fn(properties.minValue))); } if (properties.maxValue != null) { x.push(valgen_1.vg.isLte(fn(properties.maxValue))); } return x.length > 0 ? valgen_1.vg.pipe(x, { returnIndex: 0 }) : fn; } [constants_js_1.ENCODER](properties) { const fn = _isDateString; const x = [fn]; if (properties.minValue != null) { x.push(valgen_1.vg.isGte(fn(properties.minValue))); } if (properties.maxValue != null) { x.push(valgen_1.vg.isLte(fn(properties.maxValue))); } return x.length > 0 ? valgen_1.vg.pipe(x, { returnIndex: 0 }) : fn; } }; exports.DateType = DateType; tslib_1.__decorate([ simple_type_js_1.SimpleType.Attribute({ description: 'Minimum value', }), tslib_1.__metadata("design:type", String) ], DateType.prototype, "minValue", void 0); tslib_1.__decorate([ simple_type_js_1.SimpleType.Attribute({ description: 'Maximum value', }), tslib_1.__metadata("design:type", String) ], DateType.prototype, "maxValue", void 0); exports.DateType = DateType = tslib_1.__decorate([ ((0, simple_type_js_1.SimpleType)({ name: 'date', description: 'A date without time', nameMappings: { js: 'string', json: 'string', }, }).Example('2021-04-18', 'Full date value')), tslib_1.__metadata("design:paramtypes", [Object]) ], DateType);