Skip to content

Instantly share code, notes, and snippets.

@itzarty
Created July 11, 2022 12:48
Show Gist options
  • Save itzarty/58eee1ae5f21d147dd2c4587db9ed666 to your computer and use it in GitHub Desktop.
Save itzarty/58eee1ae5f21d147dd2c4587db9ed666 to your computer and use it in GitHub Desktop.
A JavaScript function to parse an output of mostly windowses command line if formatted as a list
function parseList( input ) {
var result = { };
input = input.replaceAll("\r", "").replaceAll("\x00", "").split("\n");
input.forEach( ( line, index, object ) => {
line = line.replaceAll(" ", "");
line = line.split(/:|=/);
if( !line[1] ) return;
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;
result[line[0]] = line[1];
} );
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment