Skip to content

Instantly share code, notes, and snippets.

@GuilhermeSantos001
Last active April 19, 2021 17:18
Show Gist options
  • Select an option

  • Save GuilhermeSantos001/ba827b8d93715284f354e87ecbd67c01 to your computer and use it in GitHub Desktop.

Select an option

Save GuilhermeSantos001/ba827b8d93715284f354e87ecbd67c01 to your computer and use it in GitHub Desktop.
Conversão complexa de uma lista de comandos passados por string, por exemplo: debug on color tasks welcome. O script irá executar this.enableDebug("color", "tasks", "welcome");
let command = answers['command'].toLowerCase(),
args = command.split(' ').slice(1),
params = args.slice(1);
if (command.search(/[debug]/g) == 0) {
if (args[0] === 'on') {
let join = params.join(','),
i = 0, l = join.length, quote = false,
newJoin = '\"';
if (join.indexOf(',') != -1) {
for (; i < l; i++) {
let letter = join[i];
if (letter != ',') {
if (quote) {
newJoin += `\"`;
quote = false;
}
newJoin += `${join[i]}`;
} else {
quote = true;
newJoin += `\",`;
}
if (i + 1 >= l)
newJoin += `\"`;
}
} else {
newJoin += `${join}\"`;
}
let func = `this.enableDebug(${newJoin});`;
try {
eval(func);
} catch (error) {
console.error(error);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment