Skip to content
Snippets Groups Projects
utilities.js 1.36 KiB
Newer Older
import { useStore } from 'vuex'
import { computed } from 'vue'

Konrad Mohrfeldt's avatar
Konrad Mohrfeldt committed
export function uppercaseFirst(string = '') {
  return string.charAt(0).toUpperCase() + string.slice(1)
Konrad Mohrfeldt's avatar
Konrad Mohrfeldt committed
export function lowercaseFirst(string = '') {
  return string.charAt(0).toLowerCase() + string.slice(1)

export function has(obj, prop) {
Konrad Mohrfeldt's avatar
Konrad Mohrfeldt committed
  try {
    return Object.prototype.hasOwnProperty.call(obj, prop)
  } catch (e) {
    return false
  }

export function getISODateString(date) {
  date = date ? date : new Date()
  const year = date.getFullYear()
  const month = (date.getMonth() + 1).toString().padStart(2, '0')
  const day = date.getDate().toString().padStart(2, '0')
  return `${year}-${month}-${day}`
}

export function getTimeString(date, withSeconds = false) {
  date = date ? date : new Date()
  const hours = date.getHours().toString().padStart(2, '0')
  const minutes = date.getMinutes().toString().padStart(2, '0')
  const seconds = date.getSeconds().toString().padStart(2, '0')
  return `${hours}:${minutes}${withSeconds ? `:${seconds}` : ''}`
}

export function useIsSuperUser() {
  const store = useStore()
  return computed(() => {
    const user = store.state.auth.user.steeringUser
    return user && user.is_superuser
  })
}

export function useSelectedShow() {
  const store = useStore()
  return computed(() => {
    return store.state.shows.shows[store.state.shows.selected.index]
  })
}