UNPKG

@sports-alliance/sports-lib

Version:

A Library to for importing / exporting and processing GPX, TCX, FIT and JSON files from services such as Strava, Movescount, Garmin, Polar etc

69 lines (68 loc) 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Data = void 0; var data_interface_1 = require("./data.interface"); var helpers_1 = require("../events/utilities/helpers"); var Data = /** @class */ (function () { function Data(value) { if (!this.getType()) { throw new Error('Type not set'); } if (!this.isValueTypeValid(value)) { throw new Error('Value is not boolean or number or string or Date or position'); } this.value = value; } Data.prototype.setValue = function (value) { if (!this.isValueTypeValid(value)) { throw new Error('Value is not boolean or number or string or Date or position'); } this.value = value; return this; }; Data.prototype.getValue = function (formatForDataType) { return this.value; }; Data.prototype.getDisplayValue = function () { var value = this.getValue(); switch (typeof value) { case 'string': case 'number': return value; default: return String(value); } }; Data.prototype.getType = function () { return this.constructor.type; }; Data.prototype.getUnit = function () { return this.constructor.unit; }; Data.prototype.getDisplayUnit = function () { return this.getUnit(); }; Data.prototype.getDisplayType = function () { return this.constructor.displayType || this.constructor.type; }; Data.prototype.getUnitSystem = function () { return this.constructor.unitSystem; }; Data.prototype.isValueTypeValid = function (value) { return !(typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean' && !Array.isArray(value) && !helpers_1.isNumber(value.latitudeDegrees) && !helpers_1.isNumber(value.longitudeDegrees)); }; Data.prototype.toJSON = function () { var _a; return _a = {}, _a[this.getType()] = this.getValue(), _a; }; Data.unitSystem = data_interface_1.UnitSystem.Metric; return Data; }()); exports.Data = Data;