Skip to content

Utils & Constants ​

Utilities live in app/utils/ and constants in app/constants/. Both directories are auto-imported by Nuxt — no import statement is needed inside app/.

Utilities (app/utils/) ​

General-purpose (index.ts) ​

The main utility barrel. Key exports:

ExportPurpose
isSame(obj1, obj2)Deep equality via JSON.stringify
sortBy(field, reverse, primer?, ignoreCase?)Returns a comparator for array sorting by a field
shrinkString(str, maxChars, trailingCharCount)Truncates a string keeping a trailing suffix visible
deepSearch(object, key, predicate)Recursive tree walker — finds first node matching a predicate
getMarkedText(text, search, tag?)Wraps search term matches in an HTML tag (default <mark>)
toHumanlySize(size, divider?)Converts bytes to a human-readable string (KB, MB, GB…)
toHumanlyNumericSize(size, divider?)Like toHumanlySize but returns undefined when the label hasn't changed (rolling dedup)
getPermissionNames(names)Normalises a permission-names list, caps display at 10, returns { displayNames, remainingCount }
getRandomString(length)Generates a random alphanumeric string
computeFileName(fileName)Strips extension and truncates long names to 60 chars with an ellipsis
parseSizeToBytes(sizeStr)Parses a human size string (e.g. "10MB") to bytes
getFileExt(filename)Returns the lowercased file extension
normalizeFileExtension(filename)Normalises .tif → .tiff
fetchFirstCharClass(str)Returns a CSS class name based on the first character (e.g. char_a)
getValidationMessage({ message, response? })Extracts the first validation error from a Laravel error response
escapeHtml(str)Escapes &, <, >, ", ' for safe HTML insertion
deleteMetaKeys(array)Removes EXIF noise keys from a metadata object
camelCaseToNormalCase(key)Converts a camelCase identifier to space-separated words
formatSearchTerm(str)Strips punctuation and lowercases a search string
validateFullName(name)Returns an error string or '' — validates length, characters, spacing
validateEmailAddr(value)Returns an error string or '' — validates email format
validatePhone(phone)Returns an error string or '' — validates phone number
truncateString(text, num)Truncates to num characters with …
imageExtensions, videoExtensions, audioExtensions, pdfExtensions, docExtensions, htmlExtensions, txtExtensionsExtension arrays for file-type detection
isImage(ext), isVideo(ext), isAudio(ext), isPdf(ext), isDoc(ext), isHtml(ext), isTxt(ext)Boolean file-type checkers
log(...args)No-op logger (prod-safe replacement for console.log)
stringToRegex(input)Safely compiles a user input string to a RegExp, escaping special characters

Specialised Utils ​

FileKey exports / purpose
amplitudeSessionReplay.tsparseSessionReplaySampleRate(), initSessionReplay(), shutdownSessionReplay() — wraps @amplitude/session-replay-browser with sensible defaults, sensitive-input masking, and block selectors
branding.tsisResolvedBranding(value) — type guard that checks whether an unknown value is a BrandingDetails object (by the presence of any of the five core branding keys). isSameBrand(a, b) — compares two BrandingDetails values by id when both are set, falling back to brand_name / name equality; used to avoid redundant SSR branding re-resolves.
analyticsIds.tsID_KEYS, MULTI_KEYS, COUNT_KEYS, SINGLE_VALUED — lookup tables used by the Amplitude tracking layer to determine how entity IDs are counted and coerced when sending events
cacheHelpers.tsloadFolderCache(), saveFolderCache() — reads/writes a localStorage cache of folder asset/subcategory counts keyed by FOLDERSLISTING_CACHE
cancelTokenManager.tsaddCancelController(), addThrottleController(), removeCancelController(), removeThrottleController() (also aliased as addCancelToken / addThrottleToken) — manages pools of AbortController instances for in-flight request cancellation; enforces a cap of 50 controllers per pool
chartDataEnhancer.tsenhanceChartData(raw) — pure transform that applies color scheme and series metadata to raw dashboard weekly-insights data; extracted from useDashboard.ts to avoid double-registering mitt listeners
clipboard.tscopyTextToClipboard(text) — async clipboard write with navigator.clipboard + execCommand fallback; returns boolean
error.tsgetApiErrorMessage(error, fallback?) — extracts a user-facing message from an Axios, Nuxt $fetch, or standard Error shape; isNetworkError(error) — detects connectivity failures
file-hierarchy.tsFileHandler(files, items?), DataTransferHandler(dataTransferItems, items?) — build a HierarchyItem[] tree from FileList or DataTransferItemList for drag-and-drop and direct uploads
htmlSanitizer.tssanitizeHtml(html) — strips disallowed tags and attributes to prevent XSS; allow-list covers common rich-text elements
passkey.tsisPasskeyCancellation(err) — returns true for NotAllowedError/AbortError (including wrapped causes) so passkey ceremonies can distinguish user dismissal from genuine failure
portal-url.tsportalBaseUrl(base), joinPortalUrl(base, ...segments) — build clean portal URLs by trimming and joining path segments without double slashes
safeJsonParse.tssafeJsonParse<T>(jsonString, options?) — parses JSON with prototype-pollution guards (__proto__, constructor, prototype checks) and an optional type-guard validator; returns T | null
upload-helpers.tsgetFileIcon(ext), getImageFileIcon(ext), getMimeFromExtension(ext) and icon path constants (GENERAL_FILE_ICON, VIDEO_FILE_ICON, IMAGE_FILE_ICON, AUDIO_FILE_ICON, PDF_FILE_ICON, FOLDER_BLUE_ICON) — maps file extensions to /public/img/file/ icon paths
urlToBlob.tsurlToBlob(url) — fetches any URL (remote, blob:, or data:) and returns a Blob; client-only
uuid.tsgenerateUUID(), uuidv4 (alias) — RFC 4122 v4 UUID generator
visibility.tsisVisible(instanceVisibility) — returns true when an instance_visibility array contains at least one value > 0; drives lock/restricted UI across cards and list rows

Constants (app/constants/) ​

FileKey constants
auth.tsSESSION_EXPIRED_MESSAGE — the string shown to the user when a 401 triggers the session-expired redirect.
amplitudeEvents.tsAMPLITUDE_EVENTS — exhaustive map of every trackable Amplitude event string (asset, collage, folder, shared, user, search, settings, portal, announcement events)
events.tsNamed mitt event-bus string constants (EVENT_UPDATE_COLLAGE_ASSETS, EVENT_COLLAGE_RENAMED, EVENT_ASSET_RENAMED, EVENT_FOLDER_RENAMED, EVENT_OPEN_ADD_FOLDER_DIALOG, EVENT_RELOAD_FOLDERS, EVENT_DOWNLOAD_FILE, etc.) — single source of truth for inter-component communication
imageCropPresets.tsIMAGE_CROP_PRESET_GROUPS — crop preset catalog grouped by platform (Facebook, Instagram, Twitter/X, LinkedIn, etc.) for the image-editor action panel; imports types from ~/types/image-editor
media.tsGIF_AUTOPLAY_MAX_BYTES (30 MB) — threshold above which GIF auto-play is suppressed
notification.tsMODULE_IDS ({ DAM: 2, COLLAGE: 1 }), NOTIFICATION_TYPES ({ SYSTEM: 0, ANNOUNCEMENT: 1 }), NOTIFICATION_ERROR_MESSAGES, NOTIFICATION_API_ENDPOINTS
queryKeys.tsqueryKeys — central TanStack Query key registry; factories for trash, dashboard, folders, assets, search, collections, sharing, members, announcements, notifications, profile, portal, settings, and customFields namespaces
routes.tsNamed route constants (ROUTE_DAM_DASHBOARD, ROUTE_DAM_FOLDERS, ROUTE_DAM_SEARCH, ROUTE_WORKSPACE_SETTINGS, ROUTE_PROFILE, etc.) and EXTERNAL_ROUTE_NAMES — avoids hardcoded route name strings throughout the app
search.tsSEARCH_COLLECTIONS map, PER_PAGE per-tab defaults (50), SEARCH_DEBOUNCE_MS (500 ms), POOL_REORDER_CUTOFF (49), VIRTUAL_THRESHOLD (500), LIST_ROW_HEIGHT, GRID_ROW_HEIGHT, BUFFER_ROWS_LIST, BUFFER_ROWS_GRID, DEFAULT_SORT_STRING, QUERY_BY (query field per tab), SEARCH_VIEW_MODES (["list", "grid"]), SearchViewMode type
selection.tsDEFAULT_BULK_SELECTION_LIMIT (5000) — maximum assets that can be bulk-selected at once
sharing.tsFLAG_SHARE_LINK, FLAG_TRASH_LISTING — flag strings used to distinguish sharing context