loccon
Version:
A simple local context storage and management tool with CLI and web interfaces. Store, search, and organize code snippets, notes, and development contexts with sharded JSON storage.
54 lines • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatTimestamp = formatTimestamp;
exports.formatFileSize = formatFileSize;
exports.sleep = sleep;
exports.isValidJSON = isValidJSON;
exports.truncateString = truncateString;
exports.parseCategories = parseCategories;
exports.categoriesToString = categoriesToString;
function formatTimestamp(isoString) {
const date = new Date(isoString);
return date.toLocaleString();
}
function formatFileSize(bytes) {
const units = ['B', 'KB', 'MB', 'GB'];
let size = bytes;
let unitIndex = 0;
while (size >= 1024 && unitIndex < units.length - 1) {
size /= 1024;
unitIndex++;
}
return `${size.toFixed(1)} ${units[unitIndex]}`;
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function isValidJSON(str) {
try {
JSON.parse(str);
return true;
}
catch {
return false;
}
}
function truncateString(str, maxLength) {
if (str.length <= maxLength) {
return str;
}
return str.substring(0, maxLength - 3) + '...';
}
function parseCategories(input) {
if (!input || input.trim() === '') {
return [];
}
return input
.split(',')
.map(cat => cat.trim())
.filter(cat => cat.length > 0);
}
function categoriesToString(categories) {
return categories.join(', ');
}
//# sourceMappingURL=common.js.map