@cardog-icons/core
Version:
Core functionality for Cardog Icons - SVG optimization and processing
119 lines (115 loc) • 4.13 kB
TypeScript
/**
* Configuration for optimizing SVG files
*/
interface OptimizeOptions {
/** Precision for coordinate values */
precision?: number;
/** Whether to remove IDs from elements */
removeIds?: boolean;
/** Whether to optimize the SVG for smaller size */
optimize?: boolean;
/** Percentage values for width and height (e.g., "100%") */
dimensionValues?: string;
/** Whether to remove viewBox attribute */
removeViewBox?: boolean;
}
/**
* Icon metadata for processing
*/
interface IconMetadata {
/** Original name of the icon file */
originalName: string;
/** Processed component name in PascalCase */
componentName: string;
/** Path to the source file */
sourcePath: string;
/** Additional category or group */
category?: string;
/** Tags to help with searching */
tags?: string[];
/** Brand name if applicable */
brand?: string;
/** Type of logo (e.g., 'Logo', 'Icon', 'Wordmark') */
logoType?: string;
}
/**
* Known acronyms that should remain uppercase
*/
declare const KNOWN_ACRONYMS: string[];
/**
* Optimizes an SVG file and saves the result to the output directory
*
* @param inputPath - Path to the input SVG file
* @param outputPath - Path to save the optimized SVG
* @param options - Optimization options
* @returns The optimized SVG string
*/
declare function optimizeSvg(inputPath: string, outputPath: string, options?: OptimizeOptions): Promise<string>;
/**
* Optimizes all SVG files in a directory and saves the results to an output directory
*
* @param inputDir - Directory containing SVG files
* @param outputDir - Directory to save optimized SVGs
* @param options - Optimization options
* @returns A promise that resolves when all files are optimized
*/
declare function optimizeDirectory(inputDir: string, outputDir: string, options?: OptimizeOptions): Promise<void>;
/**
* Batch optimizes SVG files in parallel
*
* @param filePaths - Array of file paths to optimize
* @param outputDir - Directory to save optimized SVGs
* @param options - Optimization options
* @param batchSize - Number of files to process in parallel (default: 10)
* @returns A promise that resolves when all files are optimized
*/
declare function batchOptimizeSvgs(filePaths: string[], outputDir: string, options?: OptimizeOptions, batchSize?: number): Promise<void>;
/**
* Converts a filename or string to PascalCase while preserving specified acronyms
*
* @param input - The input string to convert
* @returns The converted PascalCase string
*/
declare function toPascalCase(input: string): string;
/**
* Capitalizes the first letter of a string
*
* @param input - The input string
* @returns The capitalized string
*/
declare function capitalize(input: string): string;
/**
* Ensures a directory exists, creating it recursively if needed
*
* @param dirPath - The directory path to ensure
*/
declare function ensureDirectoryExists(dirPath: string): void;
/**
* Finds all SVG files in a directory and its subdirectories
*
* @param directory - The directory to search in
* @returns An array of file paths
*/
declare function findSvgFiles(directory: string): Promise<string[]>;
/**
* Cleans a directory by removing all files with specified extensions
*
* @param directory - The directory to clean
* @param extensions - File extensions to remove (defaults to ['.svg'])
*/
declare function cleanDirectory(directory: string, extensions?: string[]): void;
/**
* Extracts the basename without extension from a file path
*
* @param filePath - The file path
* @returns The basename without extension
*/
declare function getBasename(filePath: string): string;
/**
* Processes a brand name while preserving specified acronyms
*
* @param brandName - The raw brand name
* @returns The processed brand name
*/
declare function processBrandName(brandName: string): string;
export { type IconMetadata, KNOWN_ACRONYMS, type OptimizeOptions, batchOptimizeSvgs, capitalize, cleanDirectory, ensureDirectoryExists, findSvgFiles, getBasename, optimizeDirectory, optimizeSvg, processBrandName, toPascalCase };