The main purpose of the utils/ directory is to allow a semantic distinction between your Vue composables and other auto-imported utility functions.
Method 1: Using named export
export const { format: formatNumber } = Intl.NumberFormat('en-GB', {
notation: 'compact',
maximumFractionDigits: 1,
})
Method 2: Using default export
// It will be available as randomEntry() (camelCase of file name without extension)
export default function (arr: Array<any>) {
return arr[Math.floor(Math.random() * arr.length)]
}
You can now use auto imported utility functions in .js, .ts and .vue files
<template>
<p>{{ formatNumber(1234) }}</p>
</template>
utils/ auto-imports work and are scanned is identical to the composables/ directory.server/utils are auto-imported in the server/ directory.