UNPKG

@opra/common

Version:
48 lines (47 loc) 1.45 kB
import { __decorate, __metadata } from "tslib"; import { toNumber, vg } from 'valgen'; import { DECODER, ENCODER } from '../../constants.js'; import { SimpleType } from '../simple-type.js'; let NumberType = class NumberType { constructor(properties) { if (properties) Object.assign(this, properties); } [DECODER](properties) { 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([toNumber, ...x], { returnIndex: 0 }) : toNumber; } [ENCODER](properties) { return this[DECODER](properties); } }; __decorate([ SimpleType.Attribute({ description: 'Determines the minimum value', }), __metadata("design:type", Number) ], NumberType.prototype, "minValue", void 0); __decorate([ SimpleType.Attribute({ description: 'Determines the maximum value', }), __metadata("design:type", Number) ], NumberType.prototype, "maxValue", void 0); NumberType = __decorate([ SimpleType({ name: 'number', description: 'Both Integer as well as Floating-Point numbers', nameMappings: { js: 'number', json: 'number', }, }), __metadata("design:paramtypes", [Object]) ], NumberType); export { NumberType };