API reference
General
Text, numbers, dates, initials, chips, files, navigation and palettes.
Everything in utils/ is a pure function: it takes data and returns data, with no Vue and no global state. Pass the current date as now so results are deterministic. Each file has its unit tests in tests/unit/.
normalizeText()
Lowercases and removes accents, for search.
normalizeText(value: string): string
splitMatch()
Splits a text into matching and non-matching parts for highlighting.
splitMatch(text: string, term: string): TextPart[]
joinMeta()
Joins short facts into one line with META_SEPARATOR (a middle dot), skipping empty values. In markup, use BaseMeta instead.
joinMeta(items: readonly (string | number | null | undefined | false)[]): string
formatNumber()
Formats a number for a locale.
formatNumber(value: number, options: FormatNumberOptions = {}): stringformatNumberCurrency()
Formats an amount in a currency.
formatNumberCurrency(value: number, options: FormatNumberOptions = {}): stringformatPercent()
Formats a percentage.
formatPercent(value: number, options: FormatNumberOptions = {}): stringformatDuration()
Formats seconds as 5m 32s or 1h 05m.
formatDuration(totalSeconds: number): string
formatBytes()
Formats a size in bytes as KB, MB or GB.
formatBytes(bytes: number, locale = 'en-US'): string
toIsoDate()
A local YYYY-MM-DD date without time zone surprises.
toIsoDate(date: Date): string
clonePlain()
Deep copy of a record that may hold reactive objects at any depth, for a form draft or a duplicate. Use it instead of structuredClone(toRaw(value)), which only unwraps the top level and throws on a nested proxy.
clonePlain(value: T): T
getInitials()
The initials of a name, for avatars.
getInitials(name: string | undefined, max = 2): string
resolveChipColor()
Finds the colour of a value in a map or a function, ignoring case and separators.
resolveChipColor(value: unknown, colors?: ChipColors): string | undefined
normalizeChipKey()
Normalises a value to compare chip keys.
normalizeChipKey(value: unknown): string
toChipKey()
Turns any value into a chip key.
toChipKey(value: unknown): string
resolveFileType()
The icon and colour of a file from its extension.
resolveFileType(filename?: string): { extension: string; icon: string; color: string; }extensioniconcolorfilterNavigation()
Removes the menu items the user cannot see and empty groups and sections.
filterNavigation(items: AppNavigationItem[], can: (permission?: Permission) => boolean): AppNavigationItem[]
scrollToSection()
Smooth-scrolls to a section by id and leaves it just below the sticky header (the landing header, demo bar included, or the app bar), measured at click time. When the scroll ends it checks the position again, because lazy blocks above the section can change height while it moves.
scrollToSection(id: string = ''): void
scrollToTop()
Smooth-scrolls to the top.
scrollToTop(): void
frameThrottle()
Wraps a scroll or resize listener so it runs at most once per animation frame, and returns it with cancel() for the pending frame. BaseTableOfContents, the bulk bar of BaseDataTable and useSectionScrollSpy() use it, so a fast scroll measures the layout once per frame instead of once per event.
frameThrottle(handler: () => void): FrameThrottled
resolvePalette()
Derives the missing secondary, tertiary and accent colours of a primary preset.
resolvePalette(colors: PaletteColors, mode: 'light' | 'dark'): ResolvedPalette
primarysecondarytertiaryaccentresolveBrandPalette()
Builds the brand theme colours for a preset: a dark surface in its hue and its light primary.
resolveBrandPalette(light: ResolvedPalette, dark: ResolvedPalette): { background: string; surface: string; 'surface-muted': string; black: string; 'on-inverse': string; primary: string; 'on-primary': string; secondary: string; 'on-secondary': stri…backgroundsurface'surface-muted'black'on-inverse'primary'on-primary'secondary'on-secondary'tertiary'on-tertiary'ratinghexToHsl()
Converts a hex colour to HSL.
hexToHsl(hex: string): Hsl
hslhslToHex()
Converts HSL to a hex colour.
hslToHex({ h, s, l }: Hsl): stringcardBrand()
Detects the card brand from the first digits.
cardBrand(number: string): CardBrand | undefined
isEmptyFormValue()
Whether a form value counts as empty.
isEmptyFormValue(value: unknown): boolean
closestPage()
Suggests the menu page closest to a mistyped path, for the 404.
closestPage(path: string, pages: StatusPageLink[]): StatusPageLink | undefined
flattenNavigation()
Turns the menu into a flat list of links.
flattenNavigation(items: AppNavigationItem[]): StatusPageLink[]
editDistance()
The Levenshtein distance between two strings.
editDistance(source: string, target: string): number
highlightCode()
A tiny tokenizer for code snippets in the showcase.
highlightCode(code: string): CodeToken[][]
searchUiComponents()
Searches the showcase components by name and description.
searchUiComponents(entries: UiComponentEntry[], term: string, describe: (entry: UiComponentEntry) => string = () => ''): UiComponentEntry[]
uiSectionId()
The anchor id of a showcase section.
uiSectionId(name: string): string
applyLandingChannel()
Keeps the landing items of the current sales channel and, on a marketplace, points links to dropped sections at its product page. useLandingContent() calls it with marketplaceUrl from the runtime config. See Sell on a marketplace.
applyLandingChannel(content: LandingPageContent, marketplaceUrl?: string): LandingPageContent
...adaptedseolandingChannel()
The sales channel of a deployment: marketplace when NUXT_PUBLIC_MARKETPLACE_URL is set, direct otherwise.
landingChannel(marketplaceUrl?: string): LandingChannel
resolveLandingLinks()
Points landing links at the demo and the documentation for a split deployment. useLandingContent() calls it with demoUrl and docsUrl from the runtime config; with both empty it returns the content untouched.
resolveLandingLinks(value: T, bases: LandingLinkBases): T
resolveLandingPath()
Resolves a single path: /docs… goes to the documentation, any other /path to the demo, and sections, mailto: and absolute URLs stay as they are.
resolveLandingPath(path: string, { demoUrl, docsUrl }: LandingLinkBases): stringisAbsoluteUrl()
Whether a link is an http(s) URL. LandingActionButton opens an absolute to in the same tab and an absolute href in a new one.
isAbsoluteUrl(url?: string): boolean
landingActionTarget()
Where a LandingAction leads: to for a route of the site, href for a section (section), an absolute URL or a mailto:/tel: link, and newTab for an absolute href. LandingActionButton and the image of LandingPortfolioGrid read it, so a link opens the same way from both.
landingActionTarget(action: Pick<LandingAction, 'to' | 'href'>): { to: string | undefined; href: string | undefined; section: boolean; newTab: boolean; }