Last active
October 15, 2022 18:05
-
-
Save zazaulola/d33768e20adbee51a27f80ceb99e87a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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