UNPKG

@trap_stevo/metrictide

Version:

Unlock powerful analytics through this modular, event-driven solution built for real-time metric tracking, aggregation, and forecasting. Capture actionable trends, segment data with flexible tag structures, and generate predictive insights using built-in

53 lines (52 loc) 1.96 kB
"use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function matchesFilter(fieldValue, condition) { if (Array.isArray(condition)) { return condition.some(function (c) { return matchesFilter(fieldValue, c); }); } if (_typeof(condition) === "object" && condition !== null) { var min = condition.min, max = condition.max; if (min !== undefined && fieldValue < min) { return false; } if (max !== undefined && fieldValue > max) { return false; } return true; } return fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.toString().includes(condition === null || condition === void 0 ? void 0 : condition.toString()); } ; function applyMetricFilter(metric) { var filter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; for (var key in filter) { var value = filter[key]; if (key === "tags") { for (var tagKey in value) { var _metric$tags; var tagVal = (_metric$tags = metric.tags) === null || _metric$tags === void 0 ? void 0 : _metric$tags[tagKey]; if (!matchesFilter(tagVal, value[tagKey])) { return false; } } } else if (key === "metadata") { for (var metaKey in value) { var _metric$metadata; var metaVal = (_metric$metadata = metric.metadata) === null || _metric$metadata === void 0 ? void 0 : _metric$metadata[metaKey]; if (!matchesFilter(metaVal, value[metaKey])) { return false; } } } else { if (!matchesFilter(metric[key], value)) return false; } } return true; } ; module.exports = { applyMetricFilter: applyMetricFilter };