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.

utils/text.ts
normalizeText(value: string): string

splitMatch()

Splits a text into matching and non-matching parts for highlighting.

utils/text.ts
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.

utils/text.ts
joinMeta(items: readonly (string | number | null | undefined | false)[]): string

formatNumber()

Formats a number for a locale.

utils/number.ts
formatNumber(value: number, options: FormatNumberOptions = {}): string

formatNumberCurrency()

Formats an amount in a currency.

utils/number.ts
formatNumberCurrency(value: number, options: FormatNumberOptions = {}): string

formatPercent()

Formats a percentage.

utils/number.ts
formatPercent(value: number, options: FormatNumberOptions = {}): string

formatDuration()

Formats seconds as 5m 32s or 1h 05m.

utils/number.ts
formatDuration(totalSeconds: number): string

formatBytes()

Formats a size in bytes as KB, MB or GB.

utils/number.ts
formatBytes(bytes: number, locale = 'en-US'): string

toIsoDate()

A local YYYY-MM-DD date without time zone surprises.

utils/date.ts
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.

utils/clone.ts
clonePlain(value: T): T

getInitials()

The initials of a name, for avatars.

utils/initials.ts
getInitials(name: string | undefined, max = 2): string

resolveChipColor()

Finds the colour of a value in a map or a function, ignoring case and separators.

utils/chip.ts
resolveChipColor(value: unknown, colors?: ChipColors): string | undefined

normalizeChipKey()

Normalises a value to compare chip keys.

utils/chip.ts
normalizeChipKey(value: unknown): string

toChipKey()

Turns any value into a chip key.

utils/chip.ts
toChipKey(value: unknown): string

resolveFileType()

The icon and colour of a file from its extension.

utils/file-types.ts
resolveFileType(filename?: string): { extension: string; icon: string; color: string; }
Returnsextensioniconcolor

filterNavigation()

Removes the menu items the user cannot see and empty groups and sections.

utils/navigation.ts
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.

utils/navigation.ts
scrollToSection(id: string = ''): void

scrollToTop()

Smooth-scrolls to the top.

utils/navigation.ts
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.

utils/frame.ts
frameThrottle(handler: () => void): FrameThrottled

resolvePalette()

Derives the missing secondary, tertiary and accent colours of a primary preset.

utils/palette.ts
resolvePalette(colors: PaletteColors, mode: 'light' | 'dark'): ResolvedPalette
Returnsprimarysecondarytertiaryaccent

resolveBrandPalette()

Builds the brand theme colours for a preset: a dark surface in its hue and its light primary.

utils/palette.ts
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…
Returnsbackgroundsurface'surface-muted'black'on-inverse'primary'on-primary'secondary'on-secondary'tertiary'on-tertiary'rating

hexToHsl()

Converts a hex colour to HSL.

utils/palette.ts
hexToHsl(hex: string): Hsl
Returnshsl

hslToHex()

Converts HSL to a hex colour.

utils/palette.ts
hslToHex({ h, s, l }: Hsl): string

cardBrand()

Detects the card brand from the first digits.

utils/form.ts
cardBrand(number: string): CardBrand | undefined

isEmptyFormValue()

Whether a form value counts as empty.

utils/form.ts
isEmptyFormValue(value: unknown): boolean

closestPage()

Suggests the menu page closest to a mistyped path, for the 404.

utils/status.ts
closestPage(path: string, pages: StatusPageLink[]): StatusPageLink | undefined

flattenNavigation()

Turns the menu into a flat list of links.

utils/status.ts
flattenNavigation(items: AppNavigationItem[]): StatusPageLink[]

editDistance()

The Levenshtein distance between two strings.

utils/status.ts
editDistance(source: string, target: string): number

highlightCode()

A tiny tokenizer for code snippets in the showcase.

utils/code-highlight.ts
highlightCode(code: string): CodeToken[][]

searchUiComponents()

Searches the showcase components by name and description.

utils/ui-showcase.ts
searchUiComponents(entries: UiComponentEntry[], term: string, describe: (entry: UiComponentEntry) => string = () => ''): UiComponentEntry[]

uiSectionId()

The anchor id of a showcase section.

utils/ui-showcase.ts
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.

utils/landing-channel.ts
applyLandingChannel(content: LandingPageContent, marketplaceUrl?: string): LandingPageContent
Returns...adaptedseo

landingChannel()

The sales channel of a deployment: marketplace when NUXT_PUBLIC_MARKETPLACE_URL is set, direct otherwise.

utils/landing-channel.ts
landingChannel(marketplaceUrl?: string): LandingChannel

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.

utils/landing-links.ts
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.

utils/landing-links.ts
resolveLandingPath(path: string, { demoUrl, docsUrl }: LandingLinkBases): string

isAbsoluteUrl()

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.

utils/landing-links.ts
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.

utils/landing-links.ts
landingActionTarget(action: Pick<LandingAction, 'to' | 'href'>): { to: string | undefined; href: string | undefined; section: boolean; newTab: boolean; }
© 2026 melsami UI.
Developer documentation for melsami UI.