/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/

export const getCsrfToken = () => {
  return document.cookie
      .split("; ")
      .find((row) => row.startsWith("csrf-token"))
      ?.split("=")[1] || 'unknown';
}

export const getSlug = () => localStorage.getItem('slug') || 'default';

// From https://stackoverflow.com/a/1026087/3607039
export const capitalize = (val:string) => {
  return String(val).charAt(0).toUpperCase() + String(val).slice(1);
}

// From https://stackoverflow.com/a/62118163/3607039
export function asArray<T>(value: T | T[]): T[] {
  return ([] as T[]).concat(value)
}