Last active
May 6, 2020 15:42
-
-
Save vicradon/077709c3a2990c70fa6e9a7b222ac942 to your computer and use it in GitHub Desktop.
remove python comments from js file
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
// 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