interface ParsedIni { [section: string]: { [key: string]: string }; } const regexPatterns = { section: /^\s*\[\s*([^\]]*)\s*\]\s*$/, param: /^\s*([\w.\-_]+)\s*=\s*(.*?)\s*$/, comment: /^\s*;.*$/, }; const lineFilter = (value: string): boolean => { const isEmpty: boolean = value.length === 0; const isComment: boolean = regexPatterns.comment.test(value); if (isComment || isEmpty) { return false; } return true; }; const iniParse = (data: string): ParsedIni => { const parsedIni: ParsedIni = {}; const lines: string[] = data.split(/\r\n|\r|\n/); const filteredLines: string[] = lines.filter(lineFilter); let currentSection: string | undefined; filteredLines.forEach((line) => { const paramMatch: RegExpMatchArray | null = line.match(regexPatterns.param); const sectionMatch: RegExpMatchArray | null = line.match(regexPatterns.section); if (paramMatch && currentSection) { const matchKey: string = paramMatch[1].toLowerCase(); const matchValue: string = paramMatch[2]; parsedIni[currentSection][matchKey] = matchValue; } else if (sectionMatch) { const matchKey: string = sectionMatch[1].toLowerCase(); parsedIni[matchKey] = {}; currentSection = matchKey; } }); return parsedIni; }; export default iniParse;