Utilities

API reference for form validation, URL, text, math, time, email, docs, route, scheduling, and SEO utility functions across Nuxtify modules.

Overview

Nuxtify auto-imports utility functions from each installed module. Shared utilities from @nuxtify/core are available in both app code and Nitro server routes, while module-specific helpers are auto-imported in app code (and server-only helpers in server/).

Core App Utilities (@nuxtify/core)

formRules

Vuetify-compatible field validation rules ((value) => true | string) ready to pass directly to :rules="[formRules.required, formRules.validEmail]".

RuleValidates
requiredNon-empty string value (!!v).
requiredArrayNon-empty array (!!v.length).
validEmailBasic email pattern (/.+@.+/).
minLength8, minLength12Minimum string length (passes when empty; pair with required).
maxLength30, maxLength60, maxLength120, maxLength150, maxLength200, maxLength300, maxLength600, maxLength1200, maxLength5000, maxLength10000Maximum string length bounds.
isIntegerValue parses as an integer (Number.isInteger(+v)).
gt0, gte6, lte12, lte365Numeric range checks (> 0, >= 6, <= 12, <= 365).

URL & Route Matching

FunctionSignatureDescription
getBaseUrl(url: string) => stringStrips query parameters and hash fragments from a URL.
getUtmParams(url: string) => { utmSource, utmMedium, utmCampaign, utmTerm, utmContent }Extracts standard utm_* query parameters (string | null).
isExternalUrl(url: string, hostname: string) => booleanReturns true for absolute URLs whose hostname differs from hostname; returns false for empty or /-prefixed relative paths.
matchRoute(pattern: string, path: string) => booleanMatches a route path against exact patterns, single-segment *, or recursive /** wildcards (used by AppAnnouncement).

Core Shared Utilities (@nuxtify/core)

Available in both client/app code and Nitro server/ handlers.

Text Formatting

FunctionSignatureDescription
titleCase(text: string, skipShortWords?: boolean) => stringCapitalizes words, optionally keeping short conjunctions/prepositions lowercase except as the first word (skipShortWords = true).
capitalizeFirstLetter(text: string) => stringUppercases the first character of a string.
fullName(firstName: string, lastName: string) => stringJoins non-empty first and last names cleanly.
parseFullName(fullName?: string | null) => { firstName: string, lastName: string }Splits a full name string into firstName and remaining lastName.
honoraryName(name: string, honorificSuffix?: string) => stringFormats "Name, Suffix" when a suffix is present.
getPronouns(gender: string) => { single, plural, possessive, possessivePlural }Returns pronoun forms for 'male', 'female', or gender-neutral default ('they').
formatPhone(input: string, separator?: string) => stringStrips a leading +1 and formats 10-digit US phone numbers with separator (default '-').
formatDate(date: number | string | Date, config?) => stringFormats dates using Intl.DateTimeFormat (type: 'date' | 'datetime', locale, options, defaultString).
booleanToText(bool: boolean) => 'Yes' | 'No'Converts a boolean into 'Yes' or 'No'.
truncate(text: string, maxLength?: number, ellipses?: boolean) => stringTruncates text at the nearest word boundary (maxLength = 80, ellipses = true).
slugify(text: string) => stringNormalizes Unicode (NFKD) and converts text into a lowercase hyphenated URL slug.
unslugify(text: string) => stringReplaces hyphens with spaces.
pluralize(value: number, units: string, showValue?: boolean) => stringPluralizes unit nouns (handling trailing 'y' -> 'ies'), optionally prefixing the numeric value.
getLanguageName(languageCode: string, displayLanguage?: string) => string | undefinedResolves BCP 47 language codes via Intl.DisplayNames with root-language fallback.
addArticle(text: string | undefined, includeText?: boolean) => stringPrepends (or returns) 'a' or 'an' based on the leading letter.

Math, Time, Navigation & Misc

FunctionSourceSignatureDescription
toPercentagemath.ts(val: number, decimals?: number) => stringFormats a decimal ratio (e.g., 0.42) as a percentage string ('42%').
roundToFixedmath.ts(val: number | string, positions?: number) => numberRounds a numeric value to positions decimal places (default 2).
isTitledLinksnavigation.ts(item: NavigationItem) => item is TitledLinksType guard distinguishing dropdown groups from flat Link items.
delaytime.ts(ms: number) => Promise<void>Async sleep helper.
daysSincetime.ts(targetDate: Date) => numberReturns whole days elapsed since targetDate.
addOrReplaceArrayItemutil.ts(array, element) => voidMutates an array of { id } objects, replacing a matching id or pushing if absent.
getRandomIntutil.ts(min: number, max: number) => numberReturns a uniform random integer between min and max (inclusive).
youTubeUrlyoutube.ts(url: string) => string | nullExtracts an 11-character YouTube video ID from common share/watch URLs and returns https://www.youtube.com/embed/<id>.

Core Server Utilities (@nuxtify/core)

Auto-imported inside Nitro server/ routes only.

submitToAPI

Sends a JSON POST request with Authorization: Bearer <apiKey> and returns { res, isSubmitted, isError, errorMessage }.

const { res, isSubmitted, isError, errorMessage } = await submitToAPI(
  apiKey,
  'https://api.example.com/v1/subscribers',
  JSON.stringify({ email }),
)

Email Utilities (@nuxtify/pages)

submitFormData

Posts a FormData payload to submitUrl and returns { isSubmitted: boolean, isError: boolean, errorMessage: string }. Used internally by EmailSubscribeForm and available for custom form components.

const { isSubmitted, isError, errorMessage } = await submitFormData(submitUrl, formData)

CMS Utilities (@nuxtify/cms)

Docs Utilities

FunctionSignatureDescription
normalizeDocRoutePath(path?: string) => stringGuarantees a leading slash and strips query strings, hashes, and trailing slashes.
toDocsPublicPath(contentPath: string, docsPrefix?: string) => stringRewrites a /docs/... collection path to your configured docsPrefix.
toDocsContentPath(publicPath: string, docsPrefix?: string) => stringMaps an incoming public docs URL back to a /docs/... collection lookup path.
unwrapDocsNavigationRoot(tree, docsPrefix?) => ContentNavigationItem[]Strips .navigation meta nodes, unwraps the root /docs folder, and normalizes paths.
findFirstDocLeaf(items) => ContentNavigationItem | nullDepth-first search returning the first navigable page in a docs tree (used for root and folder auto-redirects).
resolveDocNavNode(items, targetPath) => ContentNavigationItem | nullFinds a navigation node by normalized path anywhere in the tree.
splitDocsNavigation(items, currentPath) => DocsNavigationStateSplits top-level grouped directories into { categories, activeCategory, sidebarItems } for DocsTabs and DocsSidebar.
buildDocsBreadcrumbs(items, currentPath) => BreadcrumbItem[]Builds the breadcrumb trail from the root category down to the active doc page.
rewriteDocsSurroundings(surroundings, docsPrefix?) => [prev, next]Rewrites usePublicCollectionSurroundings results to honor custom docsPrefix.

Route & Sitemap Utilities

FunctionSignatureDescription
normalizePrefix(prefix?: string, fallback?: string) => stringNormalizes a route prefix to start with / and omit any trailing /.
extractSlug(item?: { stem?, path? } | string) => stringExtracts the trailing slug segment from a content item or path string.
getContentItemLink(prefix: string, item?) => stringBuilds a flat collection permalink (${normalizedPrefix}/${slug}).
getDocsItemLink(prefix: string, item?) => stringBuilds a nested docs permalink, preserving hierarchy and stripping numeric ordering prefixes.
isNavigationMetaItem(item?: { stem?, path? }) => booleanReturns true for Nuxt Content .navigation metadata entries.
applyContentSitemapMeta(ctx: ContentAfterParseContext) => voidBuild-time hook helper normalizing publishedAt to UTC ISO-8601, excluding .navigation/draft/disabled items from sitemap and robots, and mapping sitemap.loc to custom routePrefix values. (Future-dated publishedAt sitemap exclusion is handled dynamically at runtime via createSeoSchema from @nuxtify/cms/content.)

Scheduling Utilities

ExportType / SignatureDescription
DEFAULT_SCHEDULED_COLLECTIONSreadonly ['articles', 'notes', 'pages', 'docs']Default collection names filtered by future publishedAt.
parsePublishedAt(value: unknown) => Date | nullSafely parses string | Date timestamps into a valid Date or null.
normalizePublishedAtUtc(value: unknown) => string | undefinedConverts valid dates to 24-character UTC ISO-8601 strings (YYYY-MM-DDTHH:mm:ss.sssZ) so SQLite comparisons match UTC epoch order.
isScheduledFuture(value: unknown, now?: Date | number) => booleanReturns true when value is strictly after now.
shouldFilterScheduledCollection(collection, scheduledCollections?, override?) => booleanResolves whether scheduled-content filtering applies for a collection.

SEO & Schema Builders

Low-level pure builders backing useContentPageSchema, useArticleSchema, useDocSchema, PageFaq, and useSeoMeta:

FunctionDescription
getBreadcrumbsSchema(breadcrumbs, currentItem?)Normalizes BreadcrumbItem[] into Schema.org ListItem entries (returns [] if fewer than 2 valid items).
stripMarkdown(text?)Strips Markdown syntax (links, images, emphasis, code, headings, lists) for plain-text Schema.org fields.
normalizeSchemaImage(src?)Ensures relative image paths start with / while preserving absolute URLs.
buildBrandSiteConfigFallback(brand?)Converts nuxtify.brand into a low-priority (_priority: -10) site-config-stack entry with Organization identity.
mergeSchemaOrgNodes(override, defaultNodes, breadcrumbNode?)Honors frontmatter schemaOrg overrides while appending a BreadcrumbList node when none is present.
countDocumentWords(body)Counts words across a Nuxt Content AST body for reading time and Schema.org wordCount.
buildContentPageSchemaNodes(docRef, options?, resolvers?)Builds WebPage + optional BreadcrumbList JSON-LD nodes.
buildArticleSchemaNodes(options, resolvers?)Builds Article/BlogPosting + Person author + optional BreadcrumbList nodes.
buildDocSchemaNodes(options, resolvers?)Builds TechArticle + optional BreadcrumbList nodes for documentation pages.
buildFaqSchemaNodes(questions?, resolvers?)Builds FAQPage + Question JSON-LD nodes (used by PageFaq).
buildArticleSeoMeta(doc, options?)Produces useSeoMeta-compatible Open Graph article tags (ogType: 'article', articlePublishedTime, articleModifiedTime, articleTag, ogImage fallback) while preserving frontmatter seo overrides.