image-asset-manager
Version:
A comprehensive image asset management tool for frontend projects
125 lines • 4.18 kB
JavaScript
;
// Utility functions for the image asset manager
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSupportedImageFile = isSupportedImageFile;
exports.generateFileId = generateFileId;
exports.calculateFileHash = calculateFileHash;
exports.normalizePath = normalizePath;
exports.getRelativePath = getRelativePath;
exports.extractCategory = extractCategory;
exports.formatFileSize = formatFileSize;
exports.matchesPattern = matchesPattern;
exports.validatePort = validatePort;
exports.getAvailablePort = getAvailablePort;
const path = __importStar(require("path"));
const crypto = __importStar(require("crypto"));
const constants_1 = require("../constants");
/**
* Check if a file is a supported image format
*/
function isSupportedImageFile(filePath) {
const ext = path.extname(filePath).toLowerCase();
return constants_1.SUPPORTED_IMAGE_EXTENSIONS.includes(ext);
}
/**
* Generate a unique ID for a file based on its path
*/
function generateFileId(filePath) {
return crypto.createHash("md5").update(filePath).digest("hex");
}
/**
* Calculate file hash for duplicate detection
*/
function calculateFileHash(buffer) {
return crypto.createHash("sha256").update(buffer).digest("hex");
}
/**
* Normalize file path for cross-platform compatibility
*/
function normalizePath(filePath) {
return filePath.replace(/\\/g, "/");
}
/**
* Get relative path from project root
*/
function getRelativePath(filePath, projectRoot) {
return normalizePath(path.relative(projectRoot, filePath));
}
/**
* Extract category from file path
*/
function extractCategory(filePath) {
const parts = filePath.split("/");
if (parts.length > 1) {
// Use the parent directory name as category
return parts[parts.length - 2] || "uncategorized";
}
return "root";
}
/**
* Format file size in human readable format
*/
function formatFileSize(bytes) {
const sizes = ["Bytes", "KB", "MB", "GB"];
if (bytes === 0)
return "0 Bytes";
const i = Math.floor(Math.log(bytes) / Math.log(1024));
return Math.round((bytes / Math.pow(1024, i)) * 100) / 100 + " " + sizes[i];
}
/**
* Check if a pattern matches a file path
*/
function matchesPattern(filePath, patterns) {
return patterns.some((pattern) => {
// Simple glob pattern matching - can be enhanced later
const regex = new RegExp(pattern.replace(/\*/g, ".*").replace(/\?/g, "."));
return regex.test(filePath);
});
}
/**
* Validate CLI options
*/
function validatePort(port) {
return port >= 1000 && port <= 65535;
}
/**
* Get available port if the specified port is in use
*/
async function getAvailablePort(preferredPort) {
// This will be implemented when we add the web server
return preferredPort;
}
//# sourceMappingURL=index.js.map