Skip to content

Instantly share code, notes, and snippets.

@itzarty
Created July 17, 2022 23:39
Show Gist options
  • Select an option

  • Save itzarty/c9276c74ee944e78ce6cf7a481a1a4df to your computer and use it in GitHub Desktop.

Select an option

Save itzarty/c9276c74ee944e78ce6cf7a481a1a4df to your computer and use it in GitHub Desktop.
function parseList( input ) {
if( !input ) return;
let parsed = [ ];
let divCounter = 0;
let spaceCounter = 0;
input = input.replaceAll("\r", "").split("\n");
input.forEach(( line, index, object ) => {
if( divCounter == 0 ) {
parsed.push({ });
divCounter++;
}
if( line == "" ) {
spaceCounter++;
if( spaceCounter <= 1 ) {
parsed.push({ });
divCounter++;
}
return;
} else {
spaceCounter = 0;
}
line = line.replaceAll(" ", "");
line = line.split(/:|=/);
if( !line[1] ) line[1] = { };
if( line == "" ) return;
if( line[0].slice( -1 ) == " " ) line[0] = line[0].slice( 0, -1 );
if( line[1][0] == " " ) line[1] = line[1].substring( 1 );
if( !isNaN(line[1]) ) line[1] = Number( line[1] );
if( line[1] == "true" || line[1] == "enabled" || line[1] == "True" || line[1] == "Enabled" ) line[1] = true;
if( line[1] == "false" || line[1] == "disabled" || line[1] == "False" || line[1] == "Disabled" ) line[1] = false;
parsed[ parsed.length - 1 ][ line[0] ] = line[1];
});
if( parsed.length == 1 ) return parsed;
return parsed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment