/** * Generic utility for parsing comma-separated specification strings * with optional range support. * * Handles: * - Empty string validation * - Comma-separated list parsing * - Optional range expansion (e.g., "1-5") * - Deduplication via Set * - Custom sorting/ordering * * @example * const parseIds = (spec: string) => parseSpec({ * spec, * label: 'ID', * formatExamples: ['"1,2,3"', '"1-5"'], * parseSingle: (value, context) => { * const id = parseInteger(value, context, 'ID') * if (id < 1 || id > 247) throw new Error(...) * return id * }, * parseRange: (start, end, context) => { * const startId = parseInteger(start, context, 'ID') * const endId = parseInteger(end, context, 'ID') * return Array.from({length: endId - startId + 1}, (_, i) => startId + i) * }, * sortItems: (items) => items.sort((a, b) => a - b) * }) */ export interface ParseSpecOptions { /** The specification string to parse (e.g., "1,2,3" or "none,even") */ spec: string; /** Label for the value type (e.g., "ID", "parity", "baud rate") */ label: string; /** Example formats to show in error messages (e.g., ['"1,2,3"', '"1-5"']) */ formatExamples: string[]; /** * Parse a single value from the spec * @param value - The trimmed value to parse * @param context - The original part for error context * @returns The parsed value */ parseSingle: (value: string, context: string) => T; /** * Optional: Parse a range (e.g., "1-5") * @param start - The start value string * @param end - The end value string * @param context - The original range string for error context * @returns Array of values in the range */ parseRange?: (start: string, end: string, context: string) => T[]; /** * Sort/order the final array of values * @param items - Deduplicated array of items * @returns Sorted array */ sortItems: (items: T[]) => T[]; /** * Optional: Skip empty parts in comma-separated list instead of throwing error * Default: false (throw error on empty parts) */ skipEmptyParts?: boolean; } /** * Generic parser for comma-separated specification strings * * @param options - Parsing options * @returns Sorted array of unique values * * @throws Error if spec is empty or contains invalid values */ export declare function parseSpec(options: ParseSpecOptions): T[]; //# sourceMappingURL=parse-spec.d.ts.map