Extract two pure helpers so they're testable without zustand/expo: - settings-merge.ts: clampPageSize + forward-compatible mergeStoredSettings (the upgrade path where stored data predates a new notification category must yield the default, not undefined). stores/settings.ts now delegates. - notify-format.ts: sanitizeBody (strip C0/DEL control chars, trim, cap at 200) used for server-supplied notification text. stores/events.ts now imports it. Behavior unchanged; typecheck clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
15 lines
693 B
TypeScript
15 lines
693 B
TypeScript
// Pure formatting for notification bodies, extracted from stores/events.ts so the
|
|
// sanitization rules are unit-testable without the event store's RN dependencies.
|
|
|
|
export const MAX_NOTIF_BODY = 200
|
|
|
|
/**
|
|
* Make a server-supplied string safe to show in a notification:
|
|
* strip C0 control characters and DEL (which can corrupt the notification shade
|
|
* or hide content), collapse surrounding whitespace, and cap the length. Falls
|
|
* back to `fallback` when the input is empty/whitespace-only or undefined.
|
|
*/
|
|
export function sanitizeBody(s: string | undefined, fallback: string): string {
|
|
return (s ? s.replace(/[\x00-\x1f\x7f]/g, " ").trim().slice(0, MAX_NOTIF_BODY) : "") || fallback
|
|
}
|