Skip to content

Instantly share code, notes, and snippets.

@blaise-io
Last active October 18, 2020 13:15
Show Gist options
  • Save blaise-io/b011f63a3f6624816fad to your computer and use it in GitHub Desktop.
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
// 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);
}
}
});
@KamuelaFranco
Copy link

Add this to NPM!

@davidharting
Copy link

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