Skip to content

Instantly share code, notes, and snippets.

@zazaulola
Last active October 15, 2022 18:05
Show Gist options
  • Save zazaulola/d33768e20adbee51a27f80ceb99e87a9 to your computer and use it in GitHub Desktop.
Save zazaulola/d33768e20adbee51a27f80ceb99e87a9 to your computer and use it in GitHub Desktop.
function detab(str) {
return str.replaceAll(/^\s*|\s*$|(?<=(?:\n(\s*).*?)+)\1/g, "");
}
// Test
let query = `
SELECT
'table'.*
FROM
'database'.'table'
WHERE
'table'.'id' = NULL
`;
console.log(JSON.stringify(detab(query)));
// => "SELECT\n table.*\nFROM\n database.table\nWHERE\n table.id = NULL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment