/**
* Utility functions
*/
/**
* HTML-escape a string for safe insertion into innerHTML.
*/
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text == null ? '' : String(text);
return div.innerHTML;
}
/**
* Debounce function calls
* @param {Function} func - Function to debounce
* @param {number} wait - Wait time in milliseconds
* @returns {Function} Debounced function
*/
function debounce(func, wait) {
let timeout;
return function () {
const context = this;
const args = arguments;
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(context, args), wait);
};
}
/**
* Get file type icon based on file extension
* @param {string} fileName - Name of the file
* @returns {string} Emoji icon for the file type
*/
function getFileTypeIcon(fileName) {
const extension = zddc.splitExtension(fileName).extension;
const iconMap = {
// Documents
'md': '๐',
'markdown': '๐',
'txt': '๐',
'rtf': '๐',
'doc': '๐',
'docx': '๐',
'odt': '๐',
// Web files
'html': '๐',
'htm': '๐',
'css': '๐จ',
'js': 'โก',
'json': '๐',
'xml': '๐',
'yaml': 'โ๏ธ',
'yml': 'โ๏ธ',
// PDFs and presentations
'pdf': '๐',
'ppt': '๐',
'pptx': '๐',
'odp': '๐',
// Spreadsheets
'xls': '๐',
'xlsx': '๐',
'csv': '๐',
'ods': '๐',
// Images
'png': '๐ผ๏ธ',
'jpg': '๐ผ๏ธ',
'jpeg': '๐ผ๏ธ',
'gif': '๐ผ๏ธ',
'svg': '๐ผ๏ธ',
'webp': '๐ผ๏ธ',
'bmp': '๐ผ๏ธ',
// Archives
'zip': '๐ฆ',
'rar': '๐ฆ',
'tar': '๐ฆ',
'gz': '๐ฆ',
'7z': '๐ฆ',
// Code files
'py': '๐',
'java': 'โ',
'cpp': 'โ๏ธ',
'c': 'โ๏ธ',
'h': 'โ๏ธ',
'php': '๐ง',
'rb': '๐',
'go': '๐ต',
'rs': '๐ฆ',
'swift': '๐งก',
'kt': '๐',
// Configuration
'ini': 'โ๏ธ',
'conf': 'โ๏ธ',
'cfg': 'โ๏ธ',
'env': 'โ๏ธ',
// Other
'log': '๐',
'sql': '๐๏ธ',
'db': '๐๏ธ',
'sqlite': '๐๏ธ',
};
return iconMap[extension] || '๐';
}