'use strict'; // Pure helpers for Ora's main process (no Electron here, so test/core.test.cjs can run them with plain Node). function slug(text, max = 40) { return (text || 'picture').toLowerCase().normalize('NFKD').replace(/[^\w\s-]/g, '').trim() .replace(/[\s_-]+/g, '-').slice(0, max).replace(/-+$/, '') || 'picture'; } // Folder-safe name: letters, digits, spaces and dashes only, on every system. function folderName(text, max = 60) { const clean = String(text || '').normalize('NFKD').replace(/[^\w\s-]/g, ' ').replace(/_/g, ' ').replace(/\s+/g, ' ').trim(); return clean.slice(0, max).trim() || 'Plan'; } // A batch of pictures ("Make the month's posts" is up to 30): folder, position and title of one picture in it. const MAX_JOBS = 30; function validateProject(p) { if (p === undefined) return []; const errors = []; if (!p || typeof p !== 'object') return ['bad project']; if (typeof p.folder !== 'string' || !/^[\w -]{1,80}$/.test(p.folder)) errors.push('bad project folder'); if (!Number.isInteger(p.total) || p.total < 1 || p.total > MAX_JOBS) errors.push('bad picture count'); if (!Number.isInteger(p.index) || p.index < 1 || p.index > p.total) errors.push('bad picture number'); if (typeof p.title !== 'string' || p.title.length > 300) errors.push('bad picture title'); return errors; } module.exports = { slug, folderName, validateProject, MAX_JOBS };