const fs = require('fs'); const path = require('path'); function sanitize(name) { return name.replace(/[\/\\:*?"<>|]/g, '_').trim(); } function sanitizePathSegment(name, fallback) { const value = sanitize(String(name || '')).replace(/[. ]+$/g, ''); return value && value !== '.' && value !== '..' ? value : fallback; } function formatPersonNames(value) { return typeof value === 'string' ? value.replace(/\s*\/\s*/g, ' / ') : value; } function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } function getDirSize(dirPath) { let size = 0; try { for (const item of fs.readdirSync(dirPath)) { const itemPath = path.join(dirPath, item); const stat = fs.statSync(itemPath); size += stat.isDirectory() ? getDirSize(itemPath) : stat.size; } } catch {} return size; } module.exports = { sanitize, sanitizePathSegment, formatPersonNames, sleep, getDirSize };