UNPKG

@elrondnetwork/erdjs-data-api-client

Version:
61 lines 1.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataApiResponseFormatter = void 0; const tslib_1 = require("tslib"); const moment_1 = tslib_1.__importDefault(require("moment")); class DataApiResponseFormatter { static formatResponse(responsePath, response) { for (const path of responsePath) { if (response) { response = response[path]; } } return response; } static buildLastResponse(response) { if (response === undefined) { return undefined; } if (response.length === 0) { return undefined; } return { value: response[0].last.toString(), timestamp: (0, moment_1.default)(response[0].time).unix(), }; } static buildAggregateResponse(response) { if (response === undefined) { return undefined; } if (response.length === 0) { return undefined; } return { first: response[0].first, last: response[0].last, min: response[0].min, max: response[0].max, count: response[0].count, sum: response[0].sum, avg: response[0].avg, }; } static buildHistoricalResponse(response) { if (response === undefined) { return []; } return response.map((res) => ({ first: res.first, last: res.last, min: res.min, max: res.max, count: res.count, sum: res.sum, avg: res.avg, timestamp: (0, moment_1.default)(res.time).unix(), })); } } exports.DataApiResponseFormatter = DataApiResponseFormatter; //# sourceMappingURL=response.formatter.js.map