Other helpers
Small helpers shipped with the module. Like everything in src/runtime/utils, they are auto-imported.
Colors
textColorOn(color, fallback = '#fff')
Returns the text color to use on top of color: '#000' on light colors, '#fff' on dark ones. When color cannot be parsed it returns fallback.
<template>
<v-chip :color="tag.color" :style="{ color: textColorOn(tag.color) }">
{{ tag.name }}
</v-chip>
</template>The light/dark threshold (relative luminance > 0.4) matches the on-* colors Vuetify picks for the Material palette, so a hand-written color and the same color declared in the theme get the same text color.
relativeLuminance(color)
WCAG relative luminance of color, from 0 (black) to 1 (white), or null when the color cannot be parsed.
Both accept #rgb, #rgba, #rrggbb, #rrggbbaa, rgb() and rgba(); alpha is ignored. CSS color names (red, rebeccapurple) are not supported.
relativeLuminance('#ffffff') // 1
relativeLuminance('rgb(0, 0, 0)') // 0
textColorOn('#ffeb3b') // '#000'
textColorOn('#3f51b5') // '#fff'
textColorOn('primary', 'inherit') // 'inherit'humanFileSize(bytes, si = false, dp = 1)
Formats a byte count. With si = false it uses powers of 1024 (KiB, MiB, ...), with si = true powers of 1000 (kB, MB, ...). dp is the number of decimals.
humanFileSize(512) // '512 B'
humanFileSize(1536) // '1.5 KiB'
humanFileSize(1536, true) // '1.5 kB'
humanFileSize(5_000_000, true, 0) // '5 MB'generateUUID()
Returns a random v4 UUID, using crypto.randomUUID() when available and a Math.random fallback otherwise (e.g. on insecure origins, where randomUUID is missing). Fine for client-side keys, not for anything security-sensitive.
const id = generateUUID() // '3b241101-e2bb-4255-8caf-4136c566a962'