Last active
October 18, 2020 13:15
-
-
Save blaise-io/b011f63a3f6624816fad to your computer and use it in GitHub Desktop.
Prepend all JavaScript files with "use strict"; that don't have it yet
This file contains 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
// To run: | |
// npm install globby | |
// node prepend-use-strict.js | |
var globby = require('globby'); | |
var fs = require('fs'); | |
globby('**/*.js', function(err, files) { | |
for (var i = 0, m = files.length; i < m; i++) { | |
var fileContent = fs.readFileSync(files[i]).toString(); | |
if (!fileContent.match("use strict")) { | |
fileContent = "\"use strict\";\n\n" + fileContent; | |
fs.writeFileSync(files[i], fileContent); | |
} | |
} | |
}); |
You're a lifesaver, thank you for this!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this to NPM!