/** * Search-box.ai * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * File: packages/shared/src/text.ts * Description: Text sanitation for untrusted web content (JSON- and Postgres-safe). */ /** * Makes arbitrary scraped text safe for JSON serialization and Postgres storage: * removes lone UTF-16 surrogates (invalid JSON) and NUL bytes (rejected by PG). * Call again after slicing — a cut can split a surrogate pair. */ export function sanitizeText(s: string): string { return s .replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])/g, "") .replace(/(?