export function safeJsonParse(str, fallback) {
  if (!str || typeof str !== "string") return fallback;
  try { return JSON.parse(str); } catch { return fallback; }
}

export function ensureArraySet(obj, key) {
  if (!obj[key]) obj[key] = [];
  if (!Array.isArray(obj[key])) obj[key] = [];
  return obj[key];
}

export function addUnique(arr, value) {
  if (!arr.includes(value)) arr.push(value);
}