/** * Shared string utility functions. * Extracted from repeated patterns across api.js, docBlock.js, proAccept.js, proBlock.js, webSearch.js. */ /** * Normalize line endings to Unix-style (\n). * Handles \r\n (Windows), \r (old Mac), and \n (Unix). */ export function normalizeNewlines(value: string = ''): string { return String(value || '').replace(/\r\n?/g, '\n') } /** * Safely coerce any value to a non-null string. * Replaces the common `String(x || '')` pattern scattered across 20+ locations. */ export function safeString(value: unknown): string { return String(value ?? '') } /** * Remove trailing slashes from a URL/path string. */ export function stripTrailingSlashes(value: string = ''): string { return safeString(value).replace(/\/+$/, '') }