UNPKG

@opra/common

Version:
51 lines (50 loc) 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NumberType = 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"); let NumberType = class NumberType { constructor(properties) { if (properties) Object.assign(this, properties); } [constants_js_1.DECODER](properties) { 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([valgen_1.toNumber, ...x], { returnIndex: 0 }) : valgen_1.toNumber; } [constants_js_1.ENCODER](properties) { return this[constants_js_1.DECODER](properties); } }; exports.NumberType = NumberType; tslib_1.__decorate([ simple_type_js_1.SimpleType.Attribute({ description: 'Determines the minimum value', }), tslib_1.__metadata("design:type", Number) ], NumberType.prototype, "minValue", void 0); tslib_1.__decorate([ simple_type_js_1.SimpleType.Attribute({ description: 'Determines the maximum value', }), tslib_1.__metadata("design:type", Number) ], NumberType.prototype, "maxValue", void 0); exports.NumberType = NumberType = tslib_1.__decorate([ (0, simple_type_js_1.SimpleType)({ name: 'number', description: 'Both Integer as well as Floating-Point numbers', nameMappings: { js: 'number', json: 'number', }, }), tslib_1.__metadata("design:paramtypes", [Object]) ], NumberType);