UNPKG

battlemetrics-client

Version:

TypeScript client library for the BattleMetrics API

26 lines 941 B
export function flattenParams(obj, prefix = "") { const result = {}; if (obj && typeof obj === "object" && !Array.isArray(obj)) { for (const [key, value] of Object.entries(obj)) { let newKey; // Handle colon syntax (e.g., "filter:game" -> "filter[game]") if (key.includes(":") && !prefix) { const [baseKey, subKey] = key.split(":", 2); newKey = `${baseKey}[${subKey}]`; } else { newKey = prefix ? `${prefix}[${key}]` : key; } if (value !== null && typeof value === "object" && !Array.isArray(value)) { Object.assign(result, flattenParams(value, newKey)); } else if (value !== undefined) { result[newKey] = value; } } } return result; } //# sourceMappingURL=flattenParams.js.map