Skip to content

Instantly share code, notes, and snippets.

@vicradon
Last active May 6, 2020 15:42
Show Gist options
  • Save vicradon/077709c3a2990c70fa6e9a7b222ac942 to your computer and use it in GitHub Desktop.
Save vicradon/077709c3a2990c70fa6e9a7b222ac942 to your computer and use it in GitHub Desktop.
remove python comments from js file
// relative_path is the relative path of the file you want to clean up
// For some reason, you may have python comments in a js file
// and your too lazy to clean it up manually, but are eager enough to
// write code to clean it up
const fs = require('fs')
fs.readFile(relative_path, "utf8", (err, data) => {
if (err) throw err;
let processedData = ""
data.split('\n').forEach(x => {
let line = x.split(' ');
const hashIndex = line.indexOf('#')
if (line.includes('#')){
line = line.slice(0, hashIndex)
}
line = line.join(' ')
processedData += `${line}\n`
})
fs.writeFile(relative_path, processedData, (err, data) => {
if (err) throw err;
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment