From 7767f9131f2b642bda9646ce9e3966a48aea2717 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Thu, 19 Mar 2026 15:51:02 -0700 Subject: [PATCH] Feat: Extract threads formatting helpers --- src/threads-utils.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/threads-utils.js diff --git a/src/threads-utils.js b/src/threads-utils.js new file mode 100644 index 0000000..e8fb5c5 --- /dev/null +++ b/src/threads-utils.js @@ -0,0 +1,18 @@ +import { partsToText } from './utils.js'; + +export const titleFrom = t => { + if (!t) return 'Untitled'; + const s = typeof t === 'string' ? t : (Array.isArray(t) ? partsToText({ content: t }) : 'Untitled'); + return s.replace(/\s+/g, ' ').trim().slice(0, 60) || 'Untitled'; +}; + +export const serializeThreadName = t => { + const s = (t.title || 'Untitled').replace(/[^a-zA-Z0-9]/g, '_').slice(0, 150); + return `${t.pinned ? '1' : '0'}-${t.updatedAt || Date.now()}-${t.id}-${s}.json`; +}; + +export const deserializeThreadName = n => { + const p = n.replace('.json', '').split('-'); + if (p.length < 4) return null; + return { pinned: p[0] === '1', updatedAt: parseInt(p[1]), id: p[2], title: p.slice(3).join('-').replace(/_/g, ' '), status: 'synced', type: 'thread' }; +};