[feat] add wppparser

This commit is contained in:
kwaroran
2023-06-27 22:18:09 +09:00
parent 4ec4719ba3
commit 67af81f3c9
2 changed files with 40 additions and 1 deletions

1
.gitignore vendored
View File

@@ -14,6 +14,7 @@ dist-web/
dist-ssr dist-ssr
*.local *.local
xplugin/ xplugin/
src-others/
# Editor directories and files # Editor directories and files
.vscode/* .vscode/*

View File

@@ -199,4 +199,42 @@ function isAPNG(pngData: Uint8Array): boolean {
} }
} }
return false; return false;
} }
function wppParser(data:string){
const lines = data.split('\n');
let characterDetails:{[key:string]:string[]} = {};
lines.forEach(line => {
// Check for "{" and "}" indicator of object start and end
if(line.includes('{')) return;
if(line.includes('}')) return;
// Extract key and value within brackets
let keyBracketStartIndex = line.indexOf('(');
let keyBracketEndIndex = line.indexOf(')');
if(keyBracketStartIndex === -1 || keyBracketEndIndex === -1)
throw new Error(`Invalid syntax ${line}`);
let key = line.substring(0, keyBracketStartIndex).trim();
// Validate Key
if(!key) throw new Error(`Missing Key in ${line}`);
const valueArray=line.substring(keyBracketStartIndex + 1, keyBracketEndIndex)
.split(',')
.map(str => str.trim());
// Validate Values
for(let i=0;i<valueArray.length ;i++){
if(!valueArray[i])
throw new Error(`Empty Value in ${line}`);
}
characterDetails[key] = valueArray;
});
return characterDetails;
}