HEX
Server: Microsoft-IIS/10.0
System: Windows NT ITPWINWEBSVR22 10.0 build 20348 (Windows Server 2022) AMD64
User: www.conferencesearch.co.uk (0)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: D:/web/matomo.vdk/plugins/CorePluginsAdmin/vue/src/FormField/utilities.ts
/*!
 * Matomo - free/libre analytics platform
 *
 * @link    https://matomo.org
 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

interface Option {
  key: string|number;
  value: unknown;
}

export function processCheckboxAndRadioAvailableValues(
  availableValues: Record<string, unknown>|null,
  type: string,
): Option[] {
  if (!availableValues) {
    return [];
  }

  const flatValues: Option[] = [];
  Object.entries(availableValues).forEach(([valueObjKey, value]) => {
    if (value && typeof value === 'object' && typeof (value as Option).key !== 'undefined') {
      flatValues.push(value as Option);
      return;
    }

    let key: number|string = valueObjKey;
    if (type === 'integer' && typeof valueObjKey === 'string') {
      key = parseInt(key, 10);
    }

    flatValues.push({ key, value });
  });

  return flatValues;
}