UNPKG

@netdata/charts

Version:

Netdata frontend SDK and chart utilities

48 lines 1.97 kB
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); } var matchesPattern = function matchesPattern(value, pattern) { var hasStartWildcard = pattern.startsWith("*"); var hasEndWildcard = pattern.endsWith("*"); if (hasStartWildcard && hasEndWildcard) { var substring = pattern.slice(1, -1); return value.includes(substring); } if (hasStartWildcard) { var suffix = pattern.slice(1); return value.endsWith(suffix); } if (hasEndWildcard) { var prefix = pattern.slice(0, -1); return value.startsWith(prefix); } if (!pattern.includes("@")) { return value === pattern || value.startsWith("".concat(pattern, "@")); } return value === pattern; }; var normalizeSelectedInstances = function normalizeSelectedInstances(selectedInstances, instances) { if (!Array.isArray(selectedInstances) || !selectedInstances.length) { return selectedInstances; } if (!instances || _typeof(instances) !== "object") { return selectedInstances; } var instanceKeys = Object.keys(instances); var normalizedSet = new Set(); selectedInstances.forEach(function (selection) { if (!selection || typeof selection !== "string") return; if (instances[selection]) { normalizedSet.add(selection); return; } var matchedKeys = instanceKeys.filter(function (key) { var instance = instances[key]; if (!instance) return false; return matchesPattern(key, selection) || matchesPattern(instance.id, selection) || matchesPattern(instance.nm, selection); }); matchedKeys.forEach(function (key) { return normalizedSet.add(key); }); }); return Array.from(normalizedSet); }; export default normalizeSelectedInstances;