diff options
| author | stonedDiscord <Tukz@gmx.de> | 2023-09-20 13:10:36 +0200 |
|---|---|---|
| committer | stonedDiscord <Tukz@gmx.de> | 2023-09-20 13:10:36 +0200 |
| commit | dda92bd41f4bee11e2cc5de265ce4fbf5221f1ff (patch) | |
| tree | bcb0f8121955ff815758b30ec4e24a1e6bde4fba /webAO/iniParse.js | |
| parent | 59028dd4046ad0715d80be8d1ed0031f20f05b7a (diff) | |
autoformat with eslint
Diffstat (limited to 'webAO/iniParse.js')
| -rw-r--r-- | webAO/iniParse.js | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/webAO/iniParse.js b/webAO/iniParse.js index fb04e67..d3a9a90 100644 --- a/webAO/iniParse.js +++ b/webAO/iniParse.js @@ -1,42 +1,42 @@ const regexPatterns = { - section: /^\s*\[\s*([^\]]*)\s*\]\s*$/, - param: /^\s*([\w.\-_]+)\s*=\s*(.*?)\s*$/, - comment: /^\s*;.*$/, + section: /^\s*\[\s*([^\]]*)\s*\]\s*$/, + param: /^\s*([\w.\-_]+)\s*=\s*(.*?)\s*$/, + comment: /^\s*;.*$/, }; const valueHandler = (matchKey, matchValue) => (matchKey === 'showname' ? matchValue : matchValue.toLowerCase()); const lineFilter = (value) => { - const isEmpty = value.length === 0; - const isComment = regexPatterns.comment.test(value); - if (isComment || isEmpty) { - return false; - } - return true; + const isEmpty = value.length === 0; + const isComment = regexPatterns.comment.test(value); + if (isComment || isEmpty) { + return false; + } + return true; }; const iniParse = (data) => { - const parsedIni = {}; - const lines = data.split(/\r\n|\r|\n/); - const filteredLines = lines.filter(lineFilter); + const parsedIni = {}; + const lines = data.split(/\r\n|\r|\n/); + const filteredLines = lines.filter(lineFilter); - let currentSection; - filteredLines.forEach((line) => { - const isParameter = regexPatterns.param.test(line); - const isSection = regexPatterns.section.test(line); - if (isParameter && currentSection) { - const match = line.match(regexPatterns.param); - const matchKey = match[1].toLowerCase(); - const matchValue = match[2]; - parsedIni[currentSection][matchKey] = valueHandler(matchKey, matchValue); - } else if (isSection) { - const match = line.match(regexPatterns.section); - const matchKey = match[1].toLowerCase(); - parsedIni[matchKey] = {}; - currentSection = matchKey; - } - }); - return parsedIni; + let currentSection; + filteredLines.forEach((line) => { + const isParameter = regexPatterns.param.test(line); + const isSection = regexPatterns.section.test(line); + if (isParameter && currentSection) { + const match = line.match(regexPatterns.param); + const matchKey = match[1].toLowerCase(); + const matchValue = match[2]; + parsedIni[currentSection][matchKey] = valueHandler(matchKey, matchValue); + } else if (isSection) { + const match = line.match(regexPatterns.section); + const matchKey = match[1].toLowerCase(); + parsedIni[matchKey] = {}; + currentSection = matchKey; + } + }); + return parsedIni; }; export default iniParse; |
